Exemple #1
0
 public function testDeepConstructor()
 {
     $object = new Foo((object) ['foo' => 'bar'], ['baz' => 'fubar'], 'fubaz');
     $snapshot = new ObjectSnapshot($object);
     $data = $snapshot->getComparableData();
     $this->assertInstanceOf('Totem\\Snapshot\\ObjectSnapshot', $data['foo']);
     $this->assertInstanceOf('Totem\\Snapshot\\ArraySnapshot', $data['bar']);
     $this->assertNotInstanceOf('Totem\\AbstractSnapshot', $data['baz']);
 }
class ObjectSnapshotTest extends PHPUnit_Framework_TestCase
{
    /**
     * @dataProvider providerCompare
     */
    public function testCompare($object, $compare, $expect)
    {
        $snapshot = new ObjectSnapshot($object);
        $this->assertSame($expect, $snapshot->isComparable($compare));
    }
    public function providerCompare()
    {
        $object = new stdClass();
        $snapshot = $this->getMockBuilder('Totem\\AbstractSnapshot')->disableOriginalConstructor()->getMock();
        return [[$object, new ObjectSnapshot($object), true], [$object, new ObjectSnapshot(clone $object), false], [$object, $snapshot, false]];
    }
    /**
     * @expectedException InvalidArgumentException
     */
    public function testConstructWithoutObject()
    {
        new ObjectSnapshot([]);
    }
    public function testExportAllProperties()
    {
        $object = new class
        {
            public $foo = 'foo';
            protected $bar = 'bar';
            private $baz = 'baz';
        };
        $snapshot = new ObjectSnapshot($object);
        $data = $snapshot->getComparableData();
        $this->assertCount(3, $data);
        $this->assertArrayHasKey('foo', $data);
        $this->assertArrayHasKey('bar', $data);
        $this->assertArrayHasKey('baz', $data);
        $this->assertSame('foo', $data['foo']);
        $this->assertSame('bar', $data['bar']);
        $this->assertSame('baz', $data['baz']);
    }
    public function testDeepConstructor()
    {
        $object = new class
        {
            public $array;
            public $object;
            public $scalar = 'foo';
            public function __construct()
            {
                $this->object = new class
                {
                    public $foo = 'bar';
                };
                $this->array = ['foo' => 'bar'];
            }
        };
        $snapshot = new ObjectSnapshot($object);
        $data = $snapshot->getComparableData();
        $this->assertInstanceOf('Totem\\Snapshot\\ObjectSnapshot', $data['object']);
        $this->assertInstanceOf('Totem\\Snapshot\\ArraySnapshot', $data['array']);
        $this->assertNotInstanceOf('Totem\\AbstractSnapshot', $data['scalar']);
    }
}