Code Duplication    Length = 63-67 lines in 2 locations

test/Controller/DeleteControllerTest.php 1 location

@@ 8-74 (lines=67) @@
5
use Sebaks\Crud\Controller\DeleteController;
6
use Sebaks\Crud\View\Model\DeleteViewModel;
7
8
class DeleteControllerTest extends \PHPUnit_Framework_TestCase
9
{
10
    private $controller;
11
    private $id;
12
    private $deleterMock;
13
    private $view;
14
    private $eventMock;
15
16
    public function setUp()
17
    {
18
        $this->id = 22;
19
20
        $this->deleterMock = $this->getMockBuilder('T4webDomainInterface\Service\DeleterInterface')
21
            ->disableOriginalConstructor()
22
            ->getMock();
23
24
        $this->eventMock = $this->getMock('Zend\Mvc\MvcEvent');
25
26
        $this->view = new DeleteViewModel();
27
28
        $this->controller = new DeleteController(
29
            $this->id,
30
            $this->deleterMock,
31
            $this->view
32
        );
33
    }
34
35
    public function testOnDispatchSuccess()
36
    {
37
        $entityMock = $this->getMock('T4webDomainInterface\EntityInterface');
38
39
        $this->deleterMock->method('delete')
40
            ->with($this->id)
41
            ->willReturn($entityMock);
42
43
        $this->eventMock->method('setResult')
44
            ->with($this->view);
45
46
        $actualViewModel = $this->controller->onDispatch($this->eventMock);
47
48
        $this->assertSame($this->view, $actualViewModel);
49
        $this->assertSame($entityMock, $actualViewModel->getEntity());
50
    }
51
52
    public function testOnDispatchFail()
53
    {
54
        $this->deleterMock->method('delete')
55
            ->with($this->id)
56
            ->willReturn(null);
57
58
        $this->eventMock->expects($this->never())
59
            ->method('setResult');
60
61
        $this->eventMock->method('getRouteMatch')
62
            ->willReturn($this->getMockBuilder('Zend\Mvc\Router\RouteMatch')
63
                ->setMethods(['setParam'])
64
                ->disableOriginalConstructor()
65
                ->getMock());
66
67
        $this->controller->setEvent($this->eventMock);
68
69
        $actualViewModel = $this->controller->onDispatch($this->eventMock);
70
71
        $this->assertInstanceOf('Zend\View\Model\ViewModel', $actualViewModel);
72
    }
73
74
}

test/Controller/ReadControllerTest.php 1 location

@@ 8-70 (lines=63) @@
5
use Sebaks\Crud\Controller\ReadController;
6
use Sebaks\Crud\View\Model\ReadViewModel;
7
8
class ReadControllerTest extends \PHPUnit_Framework_TestCase
9
{
10
    private $controller;
11
    private $criteriaMock;
12
    private $repositoryMock;
13
    private $view;
14
    private $eventMock;
15
16
    public function setUp()
17
    {
18
        $this->criteriaMock = $this->getMock('T4webDomainInterface\Infrastructure\CriteriaInterface');
19
        $this->repositoryMock = $this->getMock('T4webDomainInterface\Infrastructure\RepositoryInterface');
20
21
        $this->eventMock = $this->getMock('Zend\Mvc\MvcEvent');
22
23
        $this->view = new ReadViewModel();
24
25
        $this->controller = new ReadController(
26
            $this->criteriaMock,
27
            $this->repositoryMock,
28
            $this->view
29
        );
30
    }
31
32
    public function testOnDispatchSuccess()
33
    {
34
        $entityMock = $this->getMock('T4webDomainInterface\EntityInterface');
35
36
        $this->repositoryMock->method('find')
37
            ->with($this->criteriaMock)
38
            ->willReturn($entityMock);
39
40
        $this->eventMock->method('setResult')
41
            ->with($this->view);
42
43
        $actualViewModel = $this->controller->onDispatch($this->eventMock);
44
45
        $this->assertSame($this->view, $actualViewModel);
46
        $this->assertSame($entityMock, $actualViewModel->getEntity());
47
    }
48
49
    public function testOnDispatchFail()
50
    {
51
        $this->repositoryMock->method('find')
52
            ->with($this->criteriaMock)
53
            ->willReturn(null);
54
55
        $this->eventMock->expects($this->never())
56
            ->method('setResult');
57
58
        $this->eventMock->method('getRouteMatch')
59
            ->willReturn($this->getMockBuilder('Zend\Mvc\Router\RouteMatch')
60
                ->setMethods(['setParam'])
61
                ->disableOriginalConstructor()
62
                ->getMock());
63
64
        $this->controller->setEvent($this->eventMock);
65
        $actualViewModel = $this->controller->onDispatch($this->eventMock);
66
67
        $this->assertInstanceOf('Zend\View\Model\ViewModel', $actualViewModel);
68
    }
69
70
}