|
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\Collection; |
|
14
|
|
|
use Novactive\Collection\Factory; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class CollectionTest. |
|
18
|
|
|
*/ |
|
19
|
|
|
class CollectionTest extends UnitTestCase |
|
20
|
|
|
{ |
|
21
|
|
|
public function testInstantiateCollectionWithNoParams() |
|
22
|
|
|
{ |
|
23
|
|
|
$coll = Factory::create(); |
|
24
|
|
|
$this->assertInstanceOf(Collection::class, $coll); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testJsonSerialize() |
|
28
|
|
|
{ |
|
29
|
|
|
$coll = Factory::create($this->fixtures['assoc']); |
|
30
|
|
|
$json = json_encode($coll); |
|
31
|
|
|
$this->assertEquals('{"1st":"first","2nd":"second","3rd":"third"}', $json); |
|
32
|
|
|
|
|
33
|
|
|
$jsonDecoded = json_decode($json, true); |
|
34
|
|
|
$coll2 = Factory::create($jsonDecoded); |
|
35
|
|
|
$this->assertEquals($coll2, $coll); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testJsonSerialize2() |
|
39
|
|
|
{ |
|
40
|
|
|
$coll = Factory::create($this->fixtures['assoc']); |
|
41
|
|
|
$coll2 = Factory::create('{"1st":"first","2nd":"second","3rd":"third"}'); |
|
42
|
|
|
$this->assertEquals($coll2, $coll); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testDump() |
|
46
|
|
|
{ |
|
47
|
|
|
$coll = Factory::create($this->fixtures['assoc']); |
|
48
|
|
|
$coll2 = $coll->dump(); |
|
49
|
|
|
$this->assertEquals($coll2, $coll); |
|
50
|
|
|
$this->assertSame($coll2, $coll); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function factoryProvider() |
|
54
|
|
|
{ |
|
55
|
|
|
$assoc = ['1st' => 'first', '2nd' => 'second', '3rd' => 'third']; |
|
56
|
|
|
|
|
57
|
|
|
return [ |
|
58
|
|
|
[$assoc], |
|
59
|
|
|
['{"1st":"first","2nd":"second","3rd":"third"}'], |
|
60
|
|
|
[Factory::create($assoc)], |
|
61
|
|
|
]; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @dataProvider factoryProvider |
|
66
|
|
|
*/ |
|
67
|
|
|
public function testFactory($arg) |
|
68
|
|
|
{ |
|
69
|
|
|
$coll = Factory::create($arg); |
|
70
|
|
|
$this->assertInstanceOf(Collection::class, $coll); |
|
71
|
|
|
|
|
72
|
|
|
$coll2 = Collection($arg); |
|
73
|
|
|
$this->assertInstanceOf(Collection::class, $coll2); |
|
74
|
|
|
$this->assertEquals($coll, $coll2); |
|
75
|
|
|
|
|
76
|
|
|
$coll3 = NovaCollection($arg); |
|
77
|
|
|
$this->assertInstanceOf(Collection::class, $coll3); |
|
78
|
|
|
$this->assertEquals($coll3, $coll2); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|