|
1
|
|
|
<?php |
|
2
|
|
|
namespace FwlibTest\Html\Generator\Helper; |
|
3
|
|
|
|
|
4
|
|
|
use Fwlib\Html\Generator\Helper\GetTitleClassAndIdTrait; |
|
5
|
|
|
use Fwolf\Wrapper\PHPUnit\PHPUnitTestCase; |
|
6
|
|
|
use PHPUnit_Framework_MockObject_MockObject as MockObject; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @copyright Copyright 2015 Fwolf |
|
10
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html LGPL-3.0+ |
|
11
|
|
|
*/ |
|
12
|
|
|
class GetTitleClassAndIdTraitTest extends PHPUnitTestCase |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @param string[] $methods |
|
16
|
|
|
* @return MockObject|GetTitleClassAndIdTrait |
|
17
|
|
|
*/ |
|
18
|
|
|
protected function buildMock(array $methods = null) |
|
19
|
|
|
{ |
|
20
|
|
|
$mock = $this->getMockBuilder(GetTitleClassAndIdTrait::class) |
|
21
|
|
|
->setMethods($methods) |
|
22
|
|
|
->getMockForTrait(); |
|
23
|
|
|
|
|
24
|
|
|
return $mock; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
public function testGetTitleClassAndId() |
|
29
|
|
|
{ |
|
30
|
|
|
$trait = $this->buildMock(['getClass', 'getId']); |
|
31
|
|
|
$trait->expects($this->any()) |
|
|
|
|
|
|
32
|
|
|
->method('getClass') |
|
33
|
|
|
->willReturnOnConsecutiveCalls('', 'foo'); |
|
34
|
|
|
|
|
35
|
|
|
$this->assertEquals('', $this->reflectionCall($trait, 'getTitleClass')); |
|
36
|
|
|
$this->assertEquals( |
|
37
|
|
|
'foo__title', |
|
38
|
|
|
$this->reflectionCall($trait, 'getTitleClass') |
|
39
|
|
|
); |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
$trait->expects($this->any()) |
|
43
|
|
|
->method('getId') |
|
44
|
|
|
->willReturnOnConsecutiveCalls('', 'bar', 'bar'); |
|
45
|
|
|
|
|
46
|
|
|
$this->assertEquals('', $this->reflectionCall($trait, 'getTitleId')); |
|
47
|
|
|
$this->assertEquals( |
|
48
|
|
|
'bar__title', |
|
49
|
|
|
$this->reflectionCall($trait, 'getTitleId') |
|
50
|
|
|
); |
|
51
|
|
|
$this->assertEquals( |
|
52
|
|
|
'bar__title--42', |
|
53
|
|
|
$this->reflectionCall($trait, 'getTitleId', [42]) |
|
54
|
|
|
); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: