|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sebaks\CrudTest\Controller\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use Sebaks\Crud\Controller\CreateController; |
|
6
|
|
|
use Sebaks\Crud\View\Model\CreateViewModel; |
|
7
|
|
|
|
|
8
|
|
|
class CreateControllerTest extends \PHPUnit_Framework_TestCase |
|
9
|
|
|
{ |
|
10
|
|
|
private $controller; |
|
11
|
|
|
private $data; |
|
|
|
|
|
|
12
|
|
|
private $creatorMock; |
|
13
|
|
|
private $view; |
|
14
|
|
|
private $eventMock; |
|
15
|
|
|
|
|
16
|
|
|
public function setUp() |
|
17
|
|
|
{ |
|
18
|
|
|
$this->data = [ |
|
19
|
|
|
'foo' => 'bar' |
|
20
|
|
|
]; |
|
21
|
|
|
|
|
22
|
|
|
$this->creatorMock = $this->getMockBuilder('T4webDomainInterface\Service\CreatorInterface') |
|
23
|
|
|
->disableOriginalConstructor() |
|
24
|
|
|
->getMock(); |
|
25
|
|
|
|
|
26
|
|
|
$this->eventMock = $this->getMock('Zend\Mvc\MvcEvent'); |
|
27
|
|
|
|
|
28
|
|
|
$this->view = new CreateViewModel(); |
|
29
|
|
|
|
|
30
|
|
|
$this->controller = new CreateController( |
|
31
|
|
|
$this->data, |
|
32
|
|
|
$this->creatorMock, |
|
33
|
|
|
$this->view |
|
34
|
|
|
); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testOnDispatchSuccess() |
|
38
|
|
|
{ |
|
39
|
|
|
$entityMock = $this->getMock('T4webDomainInterface\EntityInterface'); |
|
40
|
|
|
|
|
41
|
|
|
$this->creatorMock->method('create') |
|
42
|
|
|
->with($this->data) |
|
43
|
|
|
->willReturn($entityMock); |
|
44
|
|
|
|
|
45
|
|
|
$this->eventMock->method('setResult') |
|
46
|
|
|
->with($this->view); |
|
47
|
|
|
|
|
48
|
|
|
$actualViewModel = $this->controller->onDispatch($this->eventMock); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertSame($this->view, $actualViewModel); |
|
51
|
|
|
$this->assertSame($entityMock, $actualViewModel->getEntity()); |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testOnDispatchFail() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->creatorMock->method('create') |
|
57
|
|
|
->with($this->data) |
|
58
|
|
|
->willReturn(null); |
|
59
|
|
|
|
|
60
|
|
|
$this->creatorMock->method('getErrors') |
|
61
|
|
|
->willReturn(['errorField' => 'error message']); |
|
62
|
|
|
|
|
63
|
|
|
$this->eventMock->method('setResult') |
|
64
|
|
|
->with($this->view); |
|
65
|
|
|
|
|
66
|
|
|
$actualViewModel = $this->controller->onDispatch($this->eventMock); |
|
67
|
|
|
|
|
68
|
|
|
$this->assertSame($this->view, $actualViewModel); |
|
69
|
|
|
$this->assertNull($actualViewModel->getEntity()); |
|
|
|
|
|
|
70
|
|
|
$this->assertEquals(['errorField' => 'error message'], $actualViewModel->getErrors()); |
|
|
|
|
|
|
71
|
|
|
$this->assertSame($this->data, $actualViewModel->getInputData()); |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
} |