|
1
|
|
|
<?php |
|
2
|
|
|
namespace FwlibTest\Web; |
|
3
|
|
|
|
|
4
|
|
|
use Fwlib\Web\ViewTrait; |
|
5
|
|
|
use FwlibTest\Aide\ObjectMockBuilder\FwlibWebRequestTrait; |
|
6
|
|
|
use Fwolf\Wrapper\PHPUnit\PHPUnitTestCase; |
|
7
|
|
|
use PHPUnit_Framework_MockObject_MockObject as MockObject; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @copyright Copyright 2013-2015 Fwolf |
|
11
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html LGPL-3.0+ |
|
12
|
|
|
*/ |
|
13
|
|
|
class ViewTraitTest extends PHPUnitTestCase |
|
14
|
|
|
{ |
|
15
|
|
|
use FwlibWebRequestTrait; |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @return MockObject | ViewTrait |
|
20
|
|
|
*/ |
|
21
|
|
|
protected function buildMock() |
|
22
|
|
|
{ |
|
23
|
|
|
$mock = $this->getMockBuilder(ViewTrait::class) |
|
24
|
|
|
->setMethods(['getOutputBody']) |
|
25
|
|
|
->getMockForTrait(); |
|
26
|
|
|
|
|
27
|
|
|
$mock->expects($this->any()) |
|
28
|
|
|
->method('getOutputBody') |
|
29
|
|
|
->will($this->returnValue('body for test action')); |
|
30
|
|
|
|
|
31
|
|
|
// Simulate property |
|
32
|
|
|
/** @noinspection PhpUndefinedFieldInspection */ |
|
33
|
|
|
$mock->outputParts = []; |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
return $mock; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
public function testAccessors() |
|
40
|
|
|
{ |
|
41
|
|
|
$view = $this->buildMock(); |
|
42
|
|
|
|
|
43
|
|
|
$this->reflectionCall($view, 'setTitle', ['Title']); |
|
44
|
|
|
$this->assertEquals('Title', $this->reflectionGet($view, 'title')); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
public function testGetOutput() |
|
49
|
|
|
{ |
|
50
|
|
|
$view = $this->buildMock(); |
|
51
|
|
|
|
|
52
|
|
|
$view->outputParts = []; |
|
|
|
|
|
|
53
|
|
|
$this->assertEquals( |
|
54
|
|
|
'', |
|
55
|
|
|
$view->getOutput() |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
|
$view->outputParts = [0 => 'body',]; |
|
|
|
|
|
|
59
|
|
|
$this->assertEquals( |
|
60
|
|
|
'body for test action', |
|
61
|
|
|
$view->getOutput() |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @expectedException \Fwlib\Web\Exception\InvalidOutputPartException |
|
68
|
|
|
* @expectedExceptionMessage View method for part |
|
69
|
|
|
*/ |
|
70
|
|
|
public function testGetOutputWithInvalidPart() |
|
71
|
|
|
{ |
|
72
|
|
|
$view = $this->buildMock(); |
|
73
|
|
|
|
|
74
|
|
|
$view->outputParts = ['NotExist']; |
|
|
|
|
|
|
75
|
|
|
$view->getOutput(); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: