|
11 | 11 |
|
12 | 12 | declare(strict_types=1); |
13 | 13 |
|
14 | | -namespace spec\Sylius\Resource\StateMachine; |
| 14 | +namespace Sylius\Resource\Tests\StateMachine; |
15 | 15 |
|
16 | | -use PhpSpec\ObjectBehavior; |
| 16 | +use PHPUnit\Framework\TestCase; |
17 | 17 | use Psr\Container\ContainerInterface; |
18 | 18 | use Sylius\Resource\Context\Context; |
19 | 19 | use Sylius\Resource\Metadata\Create; |
|
22 | 22 | use Sylius\Resource\StateMachine\OperationStateMachine; |
23 | 23 | use Sylius\Resource\StateMachine\OperationStateMachineInterface; |
24 | 24 |
|
25 | | -final class OperationStateMachineSpec extends ObjectBehavior |
| 25 | +final class OperationStateMachineTest extends TestCase |
26 | 26 | { |
27 | | - function let(ContainerInterface $locator): void |
| 27 | + private ContainerInterface $locator; |
| 28 | + |
| 29 | + private OperationStateMachine $operationStateMachine; |
| 30 | + |
| 31 | + protected function setUp(): void |
28 | 32 | { |
29 | | - $this->beConstructedWith($locator); |
| 33 | + $this->locator = $this->createMock(ContainerInterface::class); |
| 34 | + $this->operationStateMachine = new OperationStateMachine($this->locator); |
30 | 35 | } |
31 | 36 |
|
32 | | - function it_is_initializable(): void |
| 37 | + public function testItIsInitializable(): void |
33 | 38 | { |
34 | | - $this->shouldHaveType(OperationStateMachine::class); |
| 39 | + $this->assertInstanceOf(OperationStateMachine::class, $this->operationStateMachine); |
35 | 40 | } |
36 | 41 |
|
37 | | - function it_calls_can_method_from_operation_state_machine_as_string( |
38 | | - ContainerInterface $locator, |
39 | | - OperationStateMachineInterface $stateMachine, |
40 | | - \stdClass $data, |
41 | | - ): void { |
| 42 | + public function testItCallsCanMethodFromOperationStateMachineAsString(): void |
| 43 | + { |
| 44 | + $stateMachine = $this->createMock(OperationStateMachineInterface::class); |
| 45 | + $data = new \stdClass(); |
42 | 46 | $operation = (new Create())->withStateMachineComponent('symfony'); |
43 | 47 | $context = new Context(); |
44 | 48 |
|
45 | | - $locator->has('symfony')->willReturn(true); |
46 | | - $locator->get('symfony')->willReturn($stateMachine); |
| 49 | + $this->locator->expects($this->once()) |
| 50 | + ->method('has') |
| 51 | + ->with('symfony') |
| 52 | + ->willReturn(true); |
47 | 53 |
|
48 | | - $stateMachine->can($data, $operation, $context)->willReturn(true)->shouldBeCalled(); |
| 54 | + $this->locator->expects($this->once()) |
| 55 | + ->method('get') |
| 56 | + ->with('symfony') |
| 57 | + ->willReturn($stateMachine); |
49 | 58 |
|
50 | | - $this->can($data, $operation, $context)->shouldReturn(true); |
| 59 | + $stateMachine->expects($this->once()) |
| 60 | + ->method('can') |
| 61 | + ->with($data, $operation, $context) |
| 62 | + ->willReturn(true); |
| 63 | + |
| 64 | + $this->assertTrue($this->operationStateMachine->can($data, $operation, $context)); |
51 | 65 | } |
52 | 66 |
|
53 | | - function it_returns_false_if_no_operation_state_machine_has_been_configured_on_operation( |
54 | | - ContainerInterface $locator, |
55 | | - OperationStateMachineInterface $stateMachine, |
56 | | - \stdClass $data, |
57 | | - ): void { |
| 67 | + public function testItReturnsFalseIfNoOperationStateMachineHasBeenConfiguredOnOperation(): void |
| 68 | + { |
| 69 | + $data = new \stdClass(); |
58 | 70 | $operation = new Create(); |
59 | 71 | $context = new Context(); |
60 | 72 |
|
61 | | - $locator->has('\App\StateMachine')->willReturn(false); |
62 | | - |
63 | | - $this->can($data, $operation, $context)->shouldReturn(false); |
| 73 | + $this->assertFalse($this->operationStateMachine->can($data, $operation, $context)); |
64 | 74 | } |
65 | 75 |
|
66 | | - function it_calls_apply_method_from_operation_state_machine_as_string( |
67 | | - ContainerInterface $locator, |
68 | | - OperationStateMachineInterface $stateMachine, |
69 | | - \stdClass $data, |
70 | | - ): void { |
| 76 | + public function testItCallsApplyMethodFromOperationStateMachineAsString(): void |
| 77 | + { |
| 78 | + $stateMachine = $this->createMock(OperationStateMachineInterface::class); |
| 79 | + $data = new \stdClass(); |
71 | 80 | $operation = (new Create())->withStateMachineComponent('symfony'); |
72 | 81 | $context = new Context(); |
73 | 82 |
|
74 | | - $locator->has('symfony')->willReturn(true); |
75 | | - $locator->get('symfony')->willReturn($stateMachine); |
| 83 | + $this->locator->expects($this->once()) |
| 84 | + ->method('has') |
| 85 | + ->with('symfony') |
| 86 | + ->willReturn(true); |
| 87 | + |
| 88 | + $this->locator->expects($this->once()) |
| 89 | + ->method('get') |
| 90 | + ->with('symfony') |
| 91 | + ->willReturn($stateMachine); |
76 | 92 |
|
77 | | - $stateMachine->apply($data, $operation, $context)->shouldBeCalled(); |
| 93 | + $stateMachine->expects($this->once()) |
| 94 | + ->method('apply') |
| 95 | + ->with($data, $operation, $context); |
78 | 96 |
|
79 | | - $this->apply($data, $operation, $context); |
| 97 | + $this->operationStateMachine->apply($data, $operation, $context); |
80 | 98 | } |
81 | 99 |
|
82 | | - function it_does_nothing_if_no_operation_state_machine_has_been_configured_on_operation( |
83 | | - ContainerInterface $locator, |
84 | | - \stdClass $data, |
85 | | - ): void { |
| 100 | + public function testItDoesNothingIfNoOperationStateMachineHasBeenConfiguredOnOperation(): void |
| 101 | + { |
| 102 | + $data = new \stdClass(); |
86 | 103 | $operation = new Create(); |
87 | 104 | $context = new Context(); |
88 | 105 |
|
89 | | - $this->apply($data, $operation, $context); |
| 106 | + $this->operationStateMachine->apply($data, $operation, $context); |
| 107 | + $this->expectNotToPerformAssertions(); |
90 | 108 | } |
91 | 109 |
|
92 | | - function it_throws_an_exception_when_operation_does_not_implement_a_state_machine( |
93 | | - \stdClass $data, |
94 | | - ): void { |
| 110 | + public function testItThrowsAnExceptionWhenOperationDoesNotImplementAStateMachine(): void |
| 111 | + { |
| 112 | + $data = new \stdClass(); |
95 | 113 | $operation = new Index(); |
96 | 114 |
|
97 | | - $this->shouldThrow( |
98 | | - new \LogicException(sprintf('Expected an instance of %s. Got: %s', StateMachineAwareOperationInterface::class, Index::class)), |
99 | | - )->during('can', [$data, $operation, new Context()]); |
| 115 | + $this->expectException(\LogicException::class); |
| 116 | + $this->expectExceptionMessage(sprintf('Expected an instance of %s. Got: %s', StateMachineAwareOperationInterface::class, Index::class)); |
| 117 | + |
| 118 | + $this->operationStateMachine->can($data, $operation, new Context()); |
100 | 119 | } |
101 | 120 | } |
0 commit comments