Completed
Push — master ( 07e238...0f15f1 )
by Pavel
09:14
created

DeleteControllerTest::testDeleting()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 18
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 12
nc 1
nop 0
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\DeleteController;
9
use ScayTrase\Api\Cruds\Event\CollectionCrudEvent;
10
use ScayTrase\Api\Cruds\Event\CrudEvents;
11
use ScayTrase\Api\Cruds\Tests\Fixtures\AbcClass;
12
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
13
14
class DeleteControllerTest extends \PHPUnit_Framework_TestCase
15
{
16
    public function testDeleting()
17
    {
18
        $id = 241;
19
        $f1 = new AbcClass();
20
21
        $evm = $this->prophesize(EventDispatcherInterface::class);
22
        $evm->dispatch(CrudEvents::DELETE, Argument::type(CollectionCrudEvent::class))->shouldBeCalled();
23
24
        $repository = $this->prophesize(ObjectRepository::class);
25
        $repository->find(Argument::exact($id))->willReturn($f1)->shouldBeCalled();
26
27
        $manager = $this->prophesize(ObjectManager::class);
28
        $manager->remove(Argument::exact($f1))->shouldBeCalled();
29
        $manager->flush()->shouldBeCalled();
30
31
        $controller = new DeleteController($repository->reveal(), $manager->reveal(), $evm->reveal());
32
        $controller->deleteAction($id);
33
    }
34
}
35