ObjectSnapshotTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
c 2
b 0
f 1
lcom 0
cbo 1
dl 0
loc 47
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testCompare() 0 5 1
A providerCompare() 0 12 1
A testConstructWithoutObject() 0 4 1
A testDeepConstructor() 0 4 1
A deepProvider() 0 6 1
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