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