1111
1212namespace test \Totem ;
1313
14+ use \stdClass ;
15+
1416use \PHPUnit_Framework_TestCase ;
1517
16- use Totem \Set ;
18+ use Totem \Set ,
19+ Totem \Snapshot \ObjectSnapshot ;
1720
1821class ChangeSetTest extends \PHPUnit_Framework_TestCase
1922{
@@ -44,7 +47,9 @@ public function testHasChanged()
4447 $ set = new Set ($ old , $ new );
4548
4649 $ this ->assertTrue ($ set ->hasChanged ('foo ' ));
50+ $ this ->assertTrue (isset ($ set ['foo ' ]));
4751 $ this ->assertFalse ($ set ->hasChanged ('baz ' ));
52+ $ this ->assertFalse (isset ($ set ['baz ' ]));
4853 }
4954
5055 /**
@@ -59,18 +64,59 @@ public function testGetChangeWithInvalidProperty()
5964 $ set ->getChange ('foo ' );
6065 }
6166
67+ // @todo to break up
6268 public function testGetChange ()
6369 {
64- $ old = $ new = ['foo ' => 'foo ' ,
65- 'bar ' => ['foo ' , 'bar ' ]];
66-
67- $ new ['foo ' ] = 'bar ' ;
68- $ new ['bar ' ] = ['foo ' , 'baz ' ];
70+ $ old = $ new = ['foo ' => 'foo ' ,
71+ 'bar ' => ['foo ' , 'bar ' ],
72+ 'baz ' => new stdClass ,
73+ 'qux ' => 'foo ' ,
74+ 'fubar ' => (object ) ['foo ' => 'bar ' ],
75+ 'fubaz ' => ['foo ' , 'bar ' ]];
76+
77+ $ new ['foo ' ] = 'bar ' ;
78+ $ new ['bar ' ] = ['foo ' , 'baz ' ];
79+ $ new ['baz ' ] = clone $ old ['fubar ' ];
80+ $ new ['qux ' ] = 42 ;
81+ $ new ['fubaz ' ][] = 'baz ' ;
6982
7083 $ set = new Set ($ old , $ new );
7184
7285 $ this ->assertInstanceOf ('Totem \\Change ' , $ set ->getChange ('foo ' ));
7386 $ this ->assertInstanceOf ('Totem \\Set ' , $ set ->getChange ('bar ' ));
87+ $ this ->assertInstanceOf ('Totem \\Change ' , $ set ['foo ' ]);
88+ }
89+
90+ public function testGetters ()
91+ {
92+ $ old = ['foo ' , 'bar ' ];
93+ $ set = new Set ($ old , $ old );
94+
95+ $ this ->assertSame ($ old , $ set ->getOld ());
96+ $ this ->assertSame ($ old , $ set ->getNew ());
97+ }
98+
99+ /**
100+ * @expectedException BadMethodCallException
101+ */
102+ public function testForbidenSetter ()
103+ {
104+ $ old = ['foo ' ];
105+ $ set = new Set ($ old , $ old );
106+
107+ $ set [] = 'baz ' ;
74108 }
109+
110+ /**
111+ * @expectedException BadMethodCallException
112+ */
113+ public function testForbidenUnsetter ()
114+ {
115+ $ old = ['foo ' ];
116+ $ set = new Set ($ old , $ old );
117+
118+ unset($ set [0 ]);
119+ }
120+
75121}
76122
0 commit comments