1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Novactive Collection. |
4
|
|
|
* |
5
|
|
|
* @author Luke Visinoni <[email protected], [email protected]> |
6
|
|
|
* @author Sébastien Morel <[email protected], [email protected]> |
7
|
|
|
* @copyright 2017 Novactive |
8
|
|
|
* @license MIT |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Novactive\Tests; |
12
|
|
|
|
13
|
|
|
use Novactive\Collection\Factory; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class ReplaceCollectionTest. |
17
|
|
|
*/ |
18
|
|
|
class ReplaceCollectionTest extends UnitTestCase |
19
|
|
|
{ |
20
|
|
|
public function testReplaceCombinesInPlace() |
21
|
|
|
{ |
22
|
|
|
$coll = Factory::create($this->fixtures['names']); |
23
|
|
|
$return = $coll->replace($this->fixtures['emails']); |
24
|
|
|
$this->assertSame($coll, $return); |
25
|
|
|
$this->assertEquals( |
26
|
|
|
[ |
27
|
|
|
'Chelsea' => '[email protected]', |
28
|
|
|
'Adella' => '[email protected]', |
29
|
|
|
'Monte' => '[email protected]', |
30
|
|
|
'Maye' => '[email protected]', |
31
|
|
|
'Lottie' => '[email protected]', |
32
|
|
|
'Don' => '[email protected]', |
33
|
|
|
'Dayton' => '[email protected]', |
34
|
|
|
'Kirk' => '[email protected]', |
35
|
|
|
'Troy' => '[email protected]', |
36
|
|
|
'Nakia' => '[email protected]', |
37
|
|
|
], |
38
|
|
|
$coll->toArray() |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @expectedException \InvalidArgumentException |
44
|
|
|
* @expectedExceptionMessage Invalid input type for replace. |
45
|
|
|
*/ |
46
|
|
|
public function testReplaceThrowsExceptionIfInvalidInput() |
47
|
|
|
{ |
48
|
|
|
$coll = Factory::create($this->fixtures['names']); |
49
|
|
|
$coll->replace('not an array'); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @expectedException \InvalidArgumentException |
54
|
|
|
* @expectedExceptionMessage Invalid input for replace, number of items does not match. |
55
|
|
|
*/ |
56
|
|
|
public function testReplaceThrowsExceptionIfIncomingTraversableCountIsNotSameAsCollection() |
57
|
|
|
{ |
58
|
|
|
$coll = Factory::create($this->fixtures['names']); |
59
|
|
|
$coll->replace([1, 2, 3]); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
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: