|
1
|
|
|
<?php |
|
2
|
|
|
namespace FwlibTest\Html\Generator\Helper; |
|
3
|
|
|
|
|
4
|
|
|
use Fwlib\Html\Generator\Helper\ElementPropertyTrait; |
|
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 ElementPropertyTraitTest extends PHPUnitTestCase |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @param string[] $methods |
|
16
|
|
|
* @return MockObject|ElementPropertyTrait |
|
17
|
|
|
*/ |
|
18
|
|
|
protected function buildMock(array $methods = null) |
|
19
|
|
|
{ |
|
20
|
|
|
$mock = $this->getMockBuilder(ElementPropertyTrait::class) |
|
21
|
|
|
->setMethods($methods) |
|
22
|
|
|
->getMockForTrait(); |
|
23
|
|
|
|
|
24
|
|
|
return $mock; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
public function testAccessors() |
|
29
|
|
|
{ |
|
30
|
|
|
$trait = $this->buildMock(); |
|
31
|
|
|
|
|
32
|
|
|
$trait->setComment('foo'); |
|
|
|
|
|
|
33
|
|
|
$this->assertEquals('foo', $trait->getComment()); |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
$trait->setName('bar'); |
|
|
|
|
|
|
36
|
|
|
$this->assertEquals('bar', $trait->getName()); |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
$trait->setTip('foo'); |
|
|
|
|
|
|
39
|
|
|
$this->assertEquals('foo', $trait->getTip()); |
|
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
$trait->setTitle('bar'); |
|
|
|
|
|
|
42
|
|
|
$this->assertEquals('bar', $trait->getTitle()); |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
$trait->setValidateRules(['foo', 'bar']); |
|
|
|
|
|
|
45
|
|
|
$this->assertEquals(['foo', 'bar'], $trait->getValidateRules()); |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
public function testSetGetValue() |
|
50
|
|
|
{ |
|
51
|
|
|
$trait = $this->buildMock(['getConfig']); |
|
52
|
|
|
$trait->expects($this->any()) |
|
|
|
|
|
|
53
|
|
|
->method('getConfig') |
|
54
|
|
|
->willReturnOnConsecutiveCalls(null, null, 'foo'); |
|
55
|
|
|
|
|
56
|
|
|
// Both value and default value are null |
|
57
|
|
|
$trait->setValue(null); |
|
|
|
|
|
|
58
|
|
|
$this->assertNull($trait->getValue()); |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
// Only default is null |
|
61
|
|
|
$trait->setValue('bar'); |
|
62
|
|
|
$this->assertEquals('bar', $trait->getValue()); |
|
63
|
|
|
|
|
64
|
|
|
// Only value is null, should use default value |
|
65
|
|
|
$trait->setValue(null); |
|
66
|
|
|
$this->assertEquals('foo', $trait->getValue()); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
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: