|
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\CopyTraitStub; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Axstrad\Component\Content\Tests\Unit\Traits\CopyTest |
|
21
|
|
|
* |
|
22
|
|
|
* @author Dan Kempster <[email protected]> |
|
23
|
|
|
* @license MIT |
|
24
|
|
|
* @package Axstrad/Content |
|
25
|
|
|
* @subpackage Tests |
|
26
|
|
|
* @group unit |
|
27
|
|
|
*/ |
|
28
|
|
|
class CopyTest extends \PHPUnit_Framework_TestCase |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @var CopyTraitStub |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $fixture; |
|
34
|
|
|
|
|
35
|
|
|
public function setUp() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->fixture = new CopyTraitStub; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @covers Axstrad\Component\Content\Traits\Copy::getCopy |
|
42
|
|
|
*/ |
|
43
|
|
|
public function testGetCopyMethod1() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->assertNull( |
|
46
|
|
|
$this->fixture->getCopy() |
|
47
|
|
|
); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @covers Axstrad\Component\Content\Traits\Copy::setCopy |
|
52
|
|
|
*/ |
|
53
|
|
|
public function testCanSetCopy() |
|
54
|
|
|
{ |
|
55
|
|
|
$this->fixture->setCopy('Some more copy.'); |
|
56
|
|
|
$this->assertAttributeEquals( |
|
57
|
|
|
'Some more copy.', |
|
58
|
|
|
'copy', |
|
59
|
|
|
$this->fixture |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @covers Axstrad\Component\Content\Traits\Copy::getCopy |
|
65
|
|
|
* @depends testCanSetCopy |
|
66
|
|
|
* @uses Axstrad\Component\Content\Traits\Copy::setCopy |
|
67
|
|
|
*/ |
|
68
|
|
|
public function testGetCopyMethod2() |
|
69
|
|
|
{ |
|
70
|
|
|
$this->fixture->setCopy('My copy'); |
|
71
|
|
|
$this->assertEquals( |
|
72
|
|
|
'My copy', |
|
73
|
|
|
$this->fixture->getCopy() |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @covers Axstrad\Component\Content\Traits\Copy::setCopy |
|
79
|
|
|
*/ |
|
80
|
|
|
public function testSetCopyReturnsSelf() |
|
81
|
|
|
{ |
|
82
|
|
|
$this->assertSame( |
|
83
|
|
|
$this->fixture, |
|
84
|
|
|
$this->fixture->setCopy('foo') |
|
85
|
|
|
); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @covers Axstrad\Component\Content\Traits\Copy::setCopy |
|
90
|
|
|
* @depends testCanSetCopy |
|
91
|
|
|
*/ |
|
92
|
|
|
public function testCopyIsTypeCastToString() |
|
93
|
|
|
{ |
|
94
|
|
|
$this->fixture->setCopy(1.1); |
|
95
|
|
|
$this->assertAttributeEquals( |
|
96
|
|
|
'1.1', |
|
97
|
|
|
'copy', |
|
98
|
|
|
$this->fixture |
|
99
|
|
|
); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @covers Axstrad\Component\Content\Traits\Copy::setCopy |
|
104
|
|
|
* @depends testCanSetCopy |
|
105
|
|
|
*/ |
|
106
|
|
|
public function testCopyCanBeSetToNull() |
|
107
|
|
|
{ |
|
108
|
|
|
$this->fixture->setCopy('My Copy'); |
|
109
|
|
|
$this->fixture->setCopy(null); |
|
110
|
|
|
$this->assertAttributeEquals( |
|
111
|
|
|
null, |
|
112
|
|
|
'copy', |
|
113
|
|
|
$this->fixture |
|
114
|
|
|
); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @expectedException InvalidArgumentException |
|
119
|
|
|
* @covers Axstrad\Component\Content\Traits\Copy::setCopy |
|
120
|
|
|
*/ |
|
121
|
|
|
public function testSetCopyThrowsExceptionIfArgumentIsNotScalar() |
|
122
|
|
|
{ |
|
123
|
|
|
$this->fixture->setCopy($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: