1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Totem package |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE file |
6
|
|
|
* that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @copyright Baptiste Clavié <[email protected]> |
9
|
|
|
* @license http://www.opensource.org/licenses/MIT-License MIT License |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Totem\Snapshot; |
13
|
|
|
|
14
|
|
|
use stdClass; |
15
|
|
|
use ReflectionMethod; |
16
|
|
|
|
17
|
|
|
use PHPUnit_Framework_TestCase; |
18
|
|
|
|
19
|
|
|
class ObjectSnapshotTest extends PHPUnit_Framework_TestCase |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @dataProvider providerCompare |
23
|
|
|
*/ |
24
|
|
|
public function testCompare($object, $compare, $expect) |
25
|
|
|
{ |
26
|
|
|
$snapshot = new ObjectSnapshot($object); |
27
|
|
|
$this->assertSame($expect, $snapshot->isComparable($compare)); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function providerCompare() |
31
|
|
|
{ |
32
|
|
|
$object = new stdClass; |
33
|
|
|
|
34
|
|
|
$snapshot = $this->getMockBuilder('Totem\\AbstractSnapshot') |
35
|
|
|
->disableOriginalConstructor() |
36
|
|
|
->getMock(); |
37
|
|
|
|
38
|
|
|
return [[$object, new ObjectSnapshot($object), true], |
39
|
|
|
[$object, new ObjectSnapshot(clone $object), false], |
40
|
|
|
[$object, $snapshot, false]]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @expectedException InvalidArgumentException |
45
|
|
|
*/ |
46
|
|
|
public function testConstructWithoutObject() |
47
|
|
|
{ |
48
|
|
|
new ObjectSnapshot([]); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @dataProvider deepProvider |
53
|
|
|
*/ |
54
|
|
|
public function testDeepConstructor($value) |
55
|
|
|
{ |
56
|
|
|
new ObjectSnapshot((object) ['foo' => $value]); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function deepProvider() |
60
|
|
|
{ |
61
|
|
|
return [[(object) ['bar' => 'baz']], |
62
|
|
|
[['bar' => 'baz']], |
63
|
|
|
['fubar']]; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|