| @@ 19-50 (lines=32) @@ | ||
| 16 | use stdClass; |
|
| 17 | use Doctrine\Common\Persistence\ObjectManager; |
|
| 18 | ||
| 19 | final class EntityArgumentTest extends TestCase |
|
| 20 | { |
|
| 21 | ||
| 22 | /** |
|
| 23 | * @test |
|
| 24 | */ |
|
| 25 | public function shouldResolveEntityArgument() |
|
| 26 | { |
|
| 27 | /** @var ObjectManager $objectManager */ |
|
| 28 | $objectManager = $this->createMock(ObjectManager::class); |
|
| 29 | ||
| 30 | /** @var Argument $id */ |
|
| 31 | $id = $this->createMock(Argument::class); |
|
| 32 | $id->method("resolve")->willReturn("some-id"); |
|
| 33 | ||
| 34 | /** @var object $expectedEntity */ |
|
| 35 | $expectedEntity = new stdClass(); |
|
| 36 | ||
| 37 | $objectManager->expects($this->once())->method('find')->with( |
|
| 38 | $this->identicalTo("some-entity-class"), |
|
| 39 | $this->identicalTo("some-id") |
|
| 40 | )->willReturn($expectedEntity); |
|
| 41 | ||
| 42 | $argument = new EntityArgument($objectManager, "some-entity-class", $id); |
|
| 43 | ||
| 44 | /** @var object $actualEntity */ |
|
| 45 | $actualEntity = $argument->resolve(); |
|
| 46 | ||
| 47 | $this->assertSame($actualEntity, $expectedEntity); |
|
| 48 | } |
|
| 49 | ||
| 50 | } |
|
| 51 | ||
| @@ 19-48 (lines=30) @@ | ||
| 16 | use stdClass; |
|
| 17 | use Addiks\SymfonyGenerics\Arguments\Argument; |
|
| 18 | ||
| 19 | final class ServiceArgumentTest extends TestCase |
|
| 20 | { |
|
| 21 | ||
| 22 | /** |
|
| 23 | * @test |
|
| 24 | */ |
|
| 25 | public function loremIpsum() |
|
| 26 | { |
|
| 27 | /** @var stdClass $sampleService */ |
|
| 28 | $sampleService = $this->createMock(stdClass::class); |
|
| 29 | ||
| 30 | /** @var ContainerInterface $container */ |
|
| 31 | $container = $this->createMock(ContainerInterface::class); |
|
| 32 | $container->expects($this->once())->method('get')->with( |
|
| 33 | $this->equalTo('some-service-id') |
|
| 34 | )->willReturn($sampleService); |
|
| 35 | ||
| 36 | /** @var Argument $serviceId */ |
|
| 37 | $serviceId = $this->createMock(Argument::class); |
|
| 38 | $serviceId->method('resolve')->willReturn("some-service-id"); |
|
| 39 | ||
| 40 | $argument = new ServiceArgument($container, $serviceId); |
|
| 41 | ||
| 42 | /** @var mixed $actualResult */ |
|
| 43 | $actualResult = $argument->resolve(); |
|
| 44 | ||
| 45 | $this->assertSame($actualResult, $sampleService); |
|
| 46 | } |
|
| 47 | ||
| 48 | } |
|
| 49 | ||