1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Axstrad library. |
5
|
|
|
* |
6
|
|
|
* (c) Dan Kempster <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @copyright 2014-2015 Dan Kempster <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Axstrad\Component\Content\Tests\Unit\Traits; |
15
|
|
|
|
16
|
|
|
use Axstrad\Component\Content\Exception\InvalidArgumentException; |
17
|
|
|
use Axstrad\Component\Content\Tests\Stubs\Traits\IntroductionTraitStub; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Axstrad\Component\Content\Tests\Unit\Traits\IntroductionTest |
21
|
|
|
* |
22
|
|
|
* @author Dan Kempster <[email protected]> |
23
|
|
|
* @license MIT |
24
|
|
|
* @package Axstrad/Content |
25
|
|
|
* @subpackage Tests |
26
|
|
|
* @group unit |
27
|
|
|
*/ |
28
|
|
|
class IntroductionTest extends \PHPUnit_Framework_TestCase |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var IntroductionTraitStub |
32
|
|
|
*/ |
33
|
|
|
protected $fixture; |
34
|
|
|
|
35
|
|
|
public function setUp() |
36
|
|
|
{ |
37
|
|
|
$this->fixture = new IntroductionTraitStub; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @covers Axstrad\Component\Content\Traits\Introduction::getIntroduction |
42
|
|
|
*/ |
43
|
|
|
public function testGetIntroductionMethod1() |
44
|
|
|
{ |
45
|
|
|
$this->assertNull( |
46
|
|
|
$this->fixture->getIntroduction() |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @covers Axstrad\Component\Content\Traits\Introduction::setIntroduction |
52
|
|
|
*/ |
53
|
|
|
public function testCanSetIntroduction() |
54
|
|
|
{ |
55
|
|
|
$this->fixture->setIntroduction('An introduction.'); |
56
|
|
|
$this->assertAttributeEquals( |
57
|
|
|
'An introduction.', |
58
|
|
|
'introduction', |
59
|
|
|
$this->fixture |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @covers Axstrad\Component\Content\Traits\Introduction::getIntroduction |
65
|
|
|
* @depends testCanSetIntroduction |
66
|
|
|
* @uses Axstrad\Component\Content\Traits\Introduction::setIntroduction |
67
|
|
|
*/ |
68
|
|
|
public function testGetIntroductionMethod2() |
69
|
|
|
{ |
70
|
|
|
$this->fixture->setIntroduction('My Introduction'); |
71
|
|
|
$this->assertEquals( |
72
|
|
|
'My Introduction', |
73
|
|
|
$this->fixture->getIntroduction() |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @covers Axstrad\Component\Content\Traits\Introduction::setIntroduction |
79
|
|
|
*/ |
80
|
|
|
public function testSetIntroductionReturnsSelf() |
81
|
|
|
{ |
82
|
|
|
$this->assertSame( |
83
|
|
|
$this->fixture, |
84
|
|
|
$this->fixture->setIntroduction('foo') |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @covers Axstrad\Component\Content\Traits\Introduction::setIntroduction |
90
|
|
|
* @depends testCanSetIntroduction |
91
|
|
|
*/ |
92
|
|
|
public function testCopyIsTypeCastToString() |
93
|
|
|
{ |
94
|
|
|
$this->fixture->setIntroduction(1.1); |
95
|
|
|
$this->assertAttributeEquals( |
96
|
|
|
'1.1', |
97
|
|
|
'introduction', |
98
|
|
|
$this->fixture |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @covers Axstrad\Component\Content\Traits\Introduction::setIntroduction |
104
|
|
|
* @depends testCanSetIntroduction |
105
|
|
|
*/ |
106
|
|
|
public function testCopyCanBeSetToNull() |
107
|
|
|
{ |
108
|
|
|
$this->fixture->setIntroduction('My Introduction'); |
109
|
|
|
$this->fixture->setIntroduction(null); |
110
|
|
|
$this->assertAttributeEquals( |
111
|
|
|
null, |
112
|
|
|
'introduction', |
113
|
|
|
$this->fixture |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @expectedException InvalidArgumentException |
119
|
|
|
* @covers Axstrad\Component\Content\Traits\Introduction::setIntroduction |
120
|
|
|
*/ |
121
|
|
|
public function testSetIntroductionThrowsExceptionIfArgumentIsNotScalar() |
122
|
|
|
{ |
123
|
|
|
$this->fixture->setIntroduction($this); |
|
|
|
|
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: