Valinor/tests/Fake/Definition/FakeFunctionDefinition.php
Eduardo Dobay c009ab98cc
fix: properly handle static anonymous functions
The `MethodObjectBuilder` was incorrectly used when a registered
constructor is a static anonymous functions — it was handled like a
static method closure `Class::method(...)` and would yield errors like
this:

```
Error: Call to undefined method 
stdClass::CuyZ\Valinor\Tests\Integration\Mapping\{closure}()
```

PHP Reflection does not provide any way of telling static functions and
closures of static methods apart, other than checking for the name
`{closure}`. We check that `{closure}` is actually the last part of the
fully-qualified name, instead of just checking that the string ends with
`{closure}`.
2022-09-24 20:01:53 +02:00

41 lines
1.0 KiB
PHP

<?php
declare(strict_types=1);
namespace CuyZ\Valinor\Tests\Fake\Definition;
use CuyZ\Valinor\Definition\EmptyAttributes;
use CuyZ\Valinor\Definition\FunctionDefinition;
use CuyZ\Valinor\Definition\ParameterDefinition;
use CuyZ\Valinor\Definition\Parameters;
use CuyZ\Valinor\Type\Types\NativeStringType;
use stdClass;
final class FakeFunctionDefinition
{
public static function new(string $fileName = null): FunctionDefinition
{
return new FunctionDefinition(
'foo',
'foo:42-1337',
new FakeAttributes(),
$fileName ?? 'foo/bar',
stdClass::class,
true,
true,
new Parameters(
new ParameterDefinition(
'bar',
'foo::bar',
NativeStringType::get(),
false,
false,
'foo',
EmptyAttributes::get()
)
),
NativeStringType::get()
);
}
}