|
3 | 3 | namespace ApiClients\Tests\Foundation; |
4 | 4 |
|
5 | 5 | use ApiClients\Foundation\Client; |
| 6 | +use ApiClients\Foundation\Hydrator\CommandBus\Command\ExtractFQCNCommand; |
| 7 | +use ApiClients\Foundation\Hydrator\CommandBus\Command\HydrateFQCNCommand; |
| 8 | +use ApiClients\Foundation\Resource\ResourceInterface; |
6 | 9 | use ApiClients\Tools\CommandBus\CommandBus; |
7 | 10 | use ApiClients\Tools\CommandBus\CommandBusInterface; |
8 | 11 | use ApiClients\Tools\TestUtilities\TestCase; |
@@ -57,4 +60,44 @@ public function testCommandBusMissing() |
57 | 60 | { |
58 | 61 | new Client(ContainerBuilder::buildDevContainer()); |
59 | 62 | } |
| 63 | + |
| 64 | + public function testHydrate() |
| 65 | + { |
| 66 | + $resource = $this->prophesize(ResourceInterface::class)->reveal(); |
| 67 | + |
| 68 | + $commandBus = $this->prophesize(CommandBusInterface::class); |
| 69 | + $commandBus->handle(new HydrateFQCNCommand('stdClass', []))->shouldBeCalled()->willReturn(resolve($resource)); |
| 70 | + |
| 71 | + $container = ContainerBuilder::buildDevContainer(); |
| 72 | + $container->set(CommandBusInterface::class, $commandBus->reveal()); |
| 73 | + $client = new Client($container); |
| 74 | + |
| 75 | + $json = json_encode([ |
| 76 | + 'class' => 'stdClass', |
| 77 | + 'properties' => [], |
| 78 | + ]); |
| 79 | + |
| 80 | + self::assertSame($resource, await($client->hydrate($json), Factory::create())); |
| 81 | + } |
| 82 | + |
| 83 | + public function testExtract() |
| 84 | + { |
| 85 | + $resource = $this->prophesize(ResourceInterface::class)->reveal(); |
| 86 | + |
| 87 | + $json = json_encode([ |
| 88 | + 'class' => get_class($resource), |
| 89 | + 'properties' => [], |
| 90 | + ]); |
| 91 | + |
| 92 | + $commandBus = $this->prophesize(CommandBusInterface::class); |
| 93 | + $commandBus->handle( |
| 94 | + new ExtractFQCNCommand(get_class($resource), $resource) |
| 95 | + )->shouldBeCalled()->willReturn(resolve([])); |
| 96 | + |
| 97 | + $container = ContainerBuilder::buildDevContainer(); |
| 98 | + $container->set(CommandBusInterface::class, $commandBus->reveal()); |
| 99 | + $client = new Client($container); |
| 100 | + |
| 101 | + self::assertSame($json, await($client->extract($resource), Factory::create())); |
| 102 | + } |
60 | 103 | } |
0 commit comments