1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2014 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2021 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\Client\Html\Common\Decorator; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class ExampleTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
private $client; |
16
|
|
|
private $object; |
17
|
|
|
private $context; |
18
|
|
|
private $view; |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
protected function setUp() : void |
22
|
|
|
{ |
23
|
|
|
$this->view = \TestHelperHtml::view(); |
24
|
|
|
$this->context = \TestHelperHtml::getContext(); |
25
|
|
|
|
26
|
|
|
$this->client = $this->getMockBuilder( '\\Aimeos\\Client\\Html\\Catalog\\Filter\\Standard' ) |
27
|
|
|
->setMethods( array( 'header', 'body', 'testMethod' ) ) |
28
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
29
|
|
|
->getMock(); |
30
|
|
|
|
31
|
|
|
$this->object = new \Aimeos\Client\Html\Common\Decorator\Example( $this->client, $this->context, [] ); |
|
|
|
|
32
|
|
|
$this->object->setView( $this->view ); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
protected function tearDown() : void |
37
|
|
|
{ |
38
|
|
|
unset( $this->object, $this->context, $this->view ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
public function testCall() |
43
|
|
|
{ |
44
|
|
|
$this->client->expects( $this->once() )->method( 'testMethod' ) ->will( $this->returnValue( true ) ); |
45
|
|
|
$this->assertTrue( $this->object->testMethod() ); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
public function testGetSubClient() |
50
|
|
|
{ |
51
|
|
|
$this->assertInstanceOf( '\\Aimeos\\Client\\Html\\Iface', $this->object->getSubClient( 'tree' ) ); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
public function testHeader() |
56
|
|
|
{ |
57
|
|
|
$this->client->expects( $this->once() )->method( 'header' )->will( $this->returnValue( 'header' ) ); |
58
|
|
|
$this->assertEquals( 'header', $this->object->header() ); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
public function testBody() |
63
|
|
|
{ |
64
|
|
|
$this->client->expects( $this->once() )->method( 'body' )->will( $this->returnValue( 'body' ) ); |
65
|
|
|
$this->assertEquals( 'body', $this->object->body() ); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
public function testGetView() |
70
|
|
|
{ |
71
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\View\\Iface', $this->view ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
public function testSetView() |
76
|
|
|
{ |
77
|
|
|
$this->view = new \Aimeos\MW\View\Standard(); |
78
|
|
|
$this->object->setView( $this->view ); |
79
|
|
|
|
80
|
|
|
$this->assertSame( $this->view, $this->view ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
public function testModifyBody() |
85
|
|
|
{ |
86
|
|
|
$this->assertEquals( 'test', $this->object->modifyBody( 'test', 1 ) ); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
public function testModifyHeader() |
91
|
|
|
{ |
92
|
|
|
$this->assertEquals( 'test', $this->object->modifyHeader( 'test', 1 ) ); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
public function testInit() |
97
|
|
|
{ |
98
|
|
|
$this->object->init(); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
public function testResponse() |
103
|
|
|
{ |
104
|
|
|
$this->assertInstanceOf( '\Psr\Http\Message\ResponseInterface', $this->object->response() ); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
public function testSetObject() |
109
|
|
|
{ |
110
|
|
|
$this->assertInstanceOf( \Aimeos\Client\Html\Iface::class, $this->object->setObject( $this->object ) ); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
} |
114
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.