Skip to content

Commit dfaa96c

Browse files
committed
PHPSpec to PHPUnit DependencyInjection
1 parent 307b7c0 commit dfaa96c

File tree

3 files changed

+78
-64
lines changed

3 files changed

+78
-64
lines changed

src/Bundle/spec/DependencyInjection/Compiler/Helper/TargetEntitiesResolverSpec.php

Lines changed: 57 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111

1212
declare(strict_types=1);
1313

14-
namespace spec\Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\Helper;
14+
namespace Sylius\Bundle\ResourceBundle\spec\DependencyInjection\Compiler\Helper;
1515

16-
use PhpSpec\ObjectBehavior;
16+
use PHPUnit\Framework\TestCase;
17+
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\Helper\TargetEntitiesResolver;
1718
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\Helper\TargetEntitiesResolverInterface;
1819
use Sylius\Bundle\ResourceBundle\Tests\Fixtures\AnimalInterface;
1920
use Sylius\Bundle\ResourceBundle\Tests\Fixtures\Bear;
@@ -23,97 +24,111 @@
2324
use Sylius\Bundle\ResourceBundle\Tests\Fixtures\MammalInterface;
2425
use Sylius\Bundle\ResourceBundle\Tests\Fixtures\Resource;
2526

26-
class TargetEntitiesResolverSpec extends ObjectBehavior
27+
final class TargetEntitiesResolverTest extends TestCase
2728
{
28-
function it_is_a_target_entities_resolver(): void
29+
private TargetEntitiesResolverInterface $resolver;
30+
31+
protected function setUp(): void
32+
{
33+
$this->resolver = new TargetEntitiesResolver();
34+
}
35+
36+
public function testItIsATargetEntitiesResolver(): void
2937
{
30-
$this->shouldImplement(TargetEntitiesResolverInterface::class);
38+
$this->assertInstanceOf(TargetEntitiesResolverInterface::class, $this->resolver);
3139
}
3240

33-
function it_skips_resource_interface(): void
41+
public function testItSkipsResourceInterface(): void
3442
{
3543
$emptyConfig = ['app.resource' => ['classes' => ['model' => Resource::class]]];
3644

37-
$this->resolve($emptyConfig)->shouldReturn([]);
45+
$this->assertSame([], $this->resolver->resolve($emptyConfig));
3846
}
3947

40-
function it_autodiscovers_interfaces_based_on_the_model_class(): void
48+
public function testItAutodiscoversInterfacesBasedOnTheModelClass(): void
4149
{
4250
$flyConfig = ['app.fly' => ['classes' => ['model' => Fly::class]]];
4351

44-
$this->resolve($flyConfig)->shouldHaveCount(2);
45-
$this->resolve($flyConfig)->shouldHaveKeyWithValue(FlyInterface::class, Fly::class);
46-
$this->resolve($flyConfig)->shouldHaveKeyWithValue(AnimalInterface::class, Fly::class);
52+
$resolved = $this->resolver->resolve($flyConfig);
53+
54+
$this->assertCount(2, $resolved);
55+
$this->assertSame(Fly::class, $resolved[FlyInterface::class]);
56+
$this->assertSame(Fly::class, $resolved[AnimalInterface::class]);
4757

4858
$bearConfig = ['app.bear' => ['classes' => ['model' => Bear::class]]];
4959

50-
$this->resolve($bearConfig)->shouldHaveCount(3);
51-
$this->resolve($bearConfig)->shouldHaveKeyWithValue(BearInterface::class, Bear::class);
52-
$this->resolve($bearConfig)->shouldHaveKeyWithValue(MammalInterface::class, Bear::class);
53-
$this->resolve($bearConfig)->shouldHaveKeyWithValue(AnimalInterface::class, Bear::class);
60+
$resolved = $this->resolver->resolve($bearConfig);
61+
62+
$this->assertCount(3, $resolved);
63+
$this->assertSame(Bear::class, $resolved[BearInterface::class]);
64+
$this->assertSame(Bear::class, $resolved[MammalInterface::class]);
65+
$this->assertSame(Bear::class, $resolved[AnimalInterface::class]);
5466
}
5567

56-
function it_autodiscovers_only_unique_interfaces_based_on_model_classes(): void
68+
public function testItAutodiscoversOnlyUniqueInterfacesBasedOnModelClasses(): void
5769
{
5870
$config = [
5971
'app.fly' => ['classes' => ['model' => Fly::class]],
6072
'app.bear' => ['classes' => ['model' => Bear::class]],
6173
];
6274

63-
$this->resolve($config)->shouldHaveCount(3);
64-
$this->resolve($config)->shouldHaveKeyWithValue(BearInterface::class, Bear::class);
65-
$this->resolve($config)->shouldHaveKeyWithValue(MammalInterface::class, Bear::class);
66-
$this->resolve($config)->shouldHaveKeyWithValue(FlyInterface::class, Fly::class);
75+
$resolved = $this->resolver->resolve($config);
6776

68-
$this->resolve($config)->shouldNotHaveKeyWithValue(AnimalInterface::class, Fly::class);
69-
$this->resolve($config)->shouldNotHaveKeyWithValue(AnimalInterface::class, Bear::class);
77+
$this->assertCount(3, $resolved);
78+
$this->assertSame(Bear::class, $resolved[BearInterface::class]);
79+
$this->assertSame(Bear::class, $resolved[MammalInterface::class]);
80+
$this->assertSame(Fly::class, $resolved[FlyInterface::class]);
81+
82+
$this->assertArrayNotHasKey(AnimalInterface::class, $resolved);
7083
}
7184

72-
function it_autodiscovers_interfaces_on_models_when_passed_multiple_times(): void
85+
public function testItAutodiscoversInterfacesOnModelsWhenPassedMultipleTimes(): void
7386
{
7487
$config = [
7588
'app.fly' => ['classes' => ['model' => Fly::class]],
7689
'app.another_resource_with_fly_model' => ['classes' => ['model' => Fly::class]],
7790
];
7891

79-
$this->resolve($config)->shouldHaveCount(2);
80-
$this->resolve($config)->shouldHaveKeyWithValue(FlyInterface::class, Fly::class);
81-
$this->resolve($config)->shouldHaveKeyWithValue(AnimalInterface::class, Fly::class);
92+
$resolved = $this->resolver->resolve($config);
93+
94+
$this->assertCount(2, $resolved);
95+
$this->assertSame(Fly::class, $resolved[FlyInterface::class]);
96+
$this->assertSame(Fly::class, $resolved[AnimalInterface::class]);
8297
}
8398

84-
function it_uses_the_interface_defined_in_the_config(): void
99+
public function testItUsesTheInterfaceDefinedInTheConfig(): void
85100
{
86101
$config = [
87102
'app.deprecated' => ['classes' => ['model' => Resource::class, 'interface' => \Countable::class]],
88103
];
89104

90-
error_reporting(0);
91-
$this->resolve($config)->shouldHaveCount(1);
92-
$this->resolve($config)->shouldHaveKeyWithValue(\Countable::class, Resource::class);
93-
error_reporting(\E_ALL);
94-
$this->shouldTrigger(\E_USER_DEPRECATED)->during('resolve', [$config]);
105+
$resolved = @$this->resolver->resolve($config);
106+
107+
$this->assertCount(1, $resolved);
108+
$this->assertSame(Resource::class, $resolved[\Countable::class]);
95109
}
96110

97-
function it_uses_the_interface_defined_explicitly_over_the_autodiscovered_one(): void
111+
public function testItUsesTheInterfaceDefinedExplicitlyOverTheAutodiscoveredOne(): void
98112
{
99113
$config = [
100114
'app.deprecated' => ['classes' => ['model' => Resource::class, 'interface' => MammalInterface::class]],
101115
'app.bear' => ['classes' => ['model' => Bear::class]],
102116
];
103117

104-
error_reporting(0);
105-
$this->resolve($config)->shouldHaveCount(3);
106-
$this->resolve($config)->shouldHaveKeyWithValue(MammalInterface::class, Resource::class);
107-
$this->resolve($config)->shouldHaveKeyWithValue(AnimalInterface::class, Bear::class);
108-
$this->resolve($config)->shouldHaveKeyWithValue(BearInterface::class, Bear::class);
109-
error_reporting(\E_ALL);
110-
$this->shouldTrigger(\E_USER_DEPRECATED)->during('resolve', [$config]);
118+
$resolved = @$this->resolver->resolve($config);
119+
120+
$this->assertCount(3, $resolved);
121+
$this->assertSame(Resource::class, $resolved[MammalInterface::class]);
122+
$this->assertSame(Bear::class, $resolved[AnimalInterface::class]);
123+
$this->assertSame(Bear::class, $resolved[BearInterface::class]);
111124
}
112125

113-
function it_throws_an_exception_if_model_class_can_not_be_resolved(): void
126+
public function testItThrowsAnExceptionIfModelClassCannotBeResolved(): void
114127
{
115128
$config = ['app.error' => ['classes' => ['interface' => \Countable::class]]];
116129

117-
$this->shouldThrow(\InvalidArgumentException::class)->during('resolve', [$config]);
130+
$this->expectException(\InvalidArgumentException::class);
131+
132+
$this->resolver->resolve($config);
118133
}
119134
}

src/Bundle/spec/DependencyInjection/Driver/Exception/InvalidDriverExceptionSpec.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,25 @@
1111

1212
declare(strict_types=1);
1313

14-
namespace spec\Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\Exception;
14+
namespace Sylius\Bundle\ResourceBundle\spec\DependencyInjection\Driver\Exception;
1515

16-
use PhpSpec\ObjectBehavior;
16+
use PHPUnit\Framework\TestCase;
17+
use Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\Exception\InvalidDriverException;
1718

18-
final class InvalidDriverExceptionSpec extends ObjectBehavior
19+
final class InvalidDriverExceptionTest extends TestCase
1920
{
20-
function let(): void
21-
{
22-
$this->beConstructedWith('driver', 'className');
23-
}
21+
private InvalidDriverException $invalidDriverException;
2422

25-
function it_extends_exception(): void
23+
protected function setUp(): void
2624
{
27-
$this->shouldHaveType(\Exception::class);
25+
$this->invalidDriverException = new InvalidDriverException('driver', 'className');
2826
}
2927

30-
function it_has_a_message(): void
28+
public function testHasAMessage(): void
3129
{
32-
$this->getMessage()->shouldReturn('Driver "driver" is not supported by className.');
30+
$this->assertSame(
31+
'Driver "driver" is not supported by className.',
32+
$this->invalidDriverException->getMessage(),
33+
);
3334
}
3435
}

src/Bundle/spec/DependencyInjection/Driver/Exception/UnknownDriverExceptionSpec.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,22 @@
1111

1212
declare(strict_types=1);
1313

14-
namespace spec\Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\Exception;
14+
namespace Sylius\Bundle\ResourceBundle\spec\DependencyInjection\Driver\Exception;
1515

16-
use PhpSpec\ObjectBehavior;
16+
use PHPUnit\Framework\TestCase;
17+
use Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\Exception\UnknownDriverException;
1718

18-
final class UnknownDriverExceptionSpec extends ObjectBehavior
19+
final class UnknownDriverExceptionTest extends TestCase
1920
{
20-
function let(): void
21-
{
22-
$this->beConstructedWith('driver');
23-
}
21+
private UnknownDriverException $unknownDriverException;
2422

25-
function it_extends_exception(): void
23+
protected function setUp(): void
2624
{
27-
$this->shouldHaveType(\Exception::class);
25+
$this->unknownDriverException = new UnknownDriverException('driver');
2826
}
2927

30-
function it_has_a_message(): void
28+
public function testHasAMessage(): void
3129
{
32-
$this->getMessage()->shouldReturn('Unknown driver "driver".');
30+
$this->assertSame('Unknown driver "driver".', $this->unknownDriverException->getMessage());
3331
}
3432
}

0 commit comments

Comments
 (0)