1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ScayTrase\Api\Cruds\Tests\Unit\Controller; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
6
|
|
|
use Prophecy\Argument; |
7
|
|
|
use ScayTrase\Api\Cruds\Controller\CreateController; |
8
|
|
|
use ScayTrase\Api\Cruds\Event\CollectionCrudEvent; |
9
|
|
|
use ScayTrase\Api\Cruds\Event\CrudEvents; |
10
|
|
|
use ScayTrase\Api\Cruds\PropertyAccessProcessor; |
11
|
|
|
use ScayTrase\Api\Cruds\ReflectionConstructorFactory; |
12
|
|
|
use ScayTrase\Api\Cruds\Tests\Fixtures\AbcClass; |
13
|
|
|
use Symfony\Component\EventDispatcher\Event; |
14
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
15
|
|
|
|
16
|
|
|
class CreateControllerTest extends \PHPUnit_Framework_TestCase |
17
|
|
|
{ |
18
|
|
|
public function testEntityCreation() |
19
|
|
|
{ |
20
|
|
|
$evmProphecy = $this->prophesize(EventDispatcherInterface::class); |
21
|
|
|
$evmProphecy->dispatch(CrudEvents::READ, Argument::type(CollectionCrudEvent::class))->shouldBeCalled(); |
22
|
|
|
$evmProphecy->dispatch(CrudEvents::CREATE, Argument::type(Event::class))->shouldBeCalled(); |
23
|
|
|
/** @var EventDispatcherInterface $evm */ |
24
|
|
|
$evm = $evmProphecy->reveal(); |
25
|
|
|
|
26
|
|
|
$factory = new ReflectionConstructorFactory(AbcClass::class); |
27
|
|
|
$processor = new PropertyAccessProcessor(); |
28
|
|
|
|
29
|
|
|
$manager = $this->prophesize(ObjectManager::class); |
30
|
|
|
$manager->persist(Argument::type(AbcClass::class))->shouldBeCalled(); |
31
|
|
|
$manager->flush()->shouldBeCalled(); |
32
|
|
|
|
33
|
|
|
$controller = new CreateController($processor, $manager->reveal(), $factory, $evm); |
34
|
|
|
|
35
|
|
|
/** @var AbcClass $entity */ |
36
|
|
|
$entity = $controller->createAction(['a' => 1, 'b' => 'b', 'c' => [1, 2, 3], 'd' => null]); |
37
|
|
|
self::assertInstanceOf(AbcClass::class, $entity); |
38
|
|
|
self::assertSame(1, $entity->a); |
39
|
|
|
self::assertSame('b', $entity->b); |
40
|
|
|
self::assertSame([1, 2, 3], $entity->c); |
41
|
|
|
self::assertNull(null, $entity->d); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|