Skip to content

Commit

Permalink
[phpspec-2-phpunit] migration of tests (Reflection)
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 committed Oct 17, 2024
1 parent 44d53e9 commit f8e1996
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
32 changes: 19 additions & 13 deletions src/Component/spec/Reflection/CallableReflectionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,42 @@

declare(strict_types=1);

namespace spec\Sylius\Resource\Reflection;
namespace Sylius\Resource\Tests\Reflection;

use PhpSpec\ObjectBehavior;
use PHPUnit\Framework\TestCase;
use ReflectionFunctionAbstract;
use Sylius\Component\Resource\Tests\Dummy\RepositoryWithCallables;
use Sylius\Resource\Reflection\CallableReflection;

class CallableReflectionSpec extends ObjectBehavior
final class CallableReflectionTest extends TestCase
{
function it_is_initializable(): void
public function testItIsInitializable(): void
{
$this->shouldHaveType(CallableReflection::class);
$callableReflection = new CallableReflection();
$this->assertInstanceOf(CallableReflection::class, $callableReflection);
}

function it_reflects_an_array_callable(): void
public function testItReflectsAnArrayCallable(): void
{
$this::from([RepositoryWithCallables::class, 'find'])->shouldHaveType(\ReflectionFunctionAbstract::class);
$reflection = CallableReflection::from([RepositoryWithCallables::class, 'find']);
$this->assertInstanceOf(ReflectionFunctionAbstract::class, $reflection);
}

function it_reflects_a_closure_callable(): void
public function testItReflectsAClosureCallable(): void
{
$this::from(fn (): array => [])->shouldHaveType(\ReflectionFunctionAbstract::class);
$reflection = CallableReflection::from(fn (): array => []);
$this->assertInstanceOf(ReflectionFunctionAbstract::class, $reflection);
}

function it_reflects_a_string_callable(): void
public function testItReflectsAStringCallable(): void
{
$this::from('Sylius\Component\Resource\Tests\Dummy\RepositoryWithCallables::find')->shouldHaveType(\ReflectionFunctionAbstract::class);
$reflection = CallableReflection::from('Sylius\Component\Resource\Tests\Dummy\RepositoryWithCallables::find');
$this->assertInstanceOf(ReflectionFunctionAbstract::class, $reflection);
}

function it_reflects_an_invokable_callable(): void
public function testItReflectsAnInvokableCallable(): void
{
$this::from(new RepositoryWithCallables())->shouldHaveType(\ReflectionFunctionAbstract::class);
$reflection = CallableReflection::from(new RepositoryWithCallables());
$this->assertInstanceOf(ReflectionFunctionAbstract::class, $reflection);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,40 @@

declare(strict_types=1);

namespace spec\Sylius\Resource\Reflection\Filter;
namespace Sylius\Resource\Tests\Reflection\Filter;

use PhpSpec\ObjectBehavior;
use PHPUnit\Framework\TestCase;
use Sylius\Component\Resource\Tests\Dummy\RepositoryWithCallables;
use Sylius\Resource\Reflection\CallableReflection;
use Sylius\Resource\Reflection\Filter\FunctionArgumentsFilter;

final class FunctionArgumentsFilterSpec extends ObjectBehavior
final class FunctionArgumentsFilterTest extends TestCase
{
function it_is_initializable(): void
private FunctionArgumentsFilter $functionArgumentsFilter;

protected function setUp(): void
{
$this->shouldHaveType(FunctionArgumentsFilter::class);
$this->functionArgumentsFilter = new FunctionArgumentsFilter();
}

function it_filters_matching_arguments(): void
public function testItIsInitializable(): void
{
$this->assertInstanceOf(FunctionArgumentsFilter::class, $this->functionArgumentsFilter);
}

public function testItFiltersMatchingArguments(): void
{
$callable = [RepositoryWithCallables::class, 'find'];
$reflector = CallableReflection::from($callable);

$this->filter(
$result = $this->functionArgumentsFilter->filter(
$reflector,
[
'id' => 'my_id',
'foo' => 'fighters',
],
)->shouldReturn([
'id' => 'my_id',
]);
);

$this->assertSame(['id' => 'my_id'], $result);
}
}

0 comments on commit f8e1996

Please sign in to comment.