@@ -11,10 +11,49 @@ public function setUp()
1111 $ this ->reader = new StreamReader ();
1212 }
1313
14- public function testA ()
14+ public function testReadByteAssertCorrect ()
1515 {
16- $ that = $ this ;
16+ $ this -> reader -> readByteAssert ( 0x01 )-> then ( $ this -> expectCallableOnce ( 0x01 )) ;
1717
18+ $ this ->reader ->write ("\x01" );
19+ }
20+
21+ public function testReadByteAssertInvalid ()
22+ {
23+ $ this ->reader ->readByteAssert (0x02 )->then (null , $ this ->expectCallableOnce ());
24+
25+ $ this ->reader ->write ("\x03" );
26+ }
27+
28+ public function testReadStringNull ()
29+ {
30+ $ this ->reader ->readStringNull ()->then ($ this ->expectCallableOnce ('hello ' ));
31+
32+ $ this ->reader ->write ("hello \x00" );
33+ }
34+
35+ public function testReadStringLength ()
36+ {
37+ $ this ->reader ->readLength (5 )->then ($ this ->expectCallableOnce ('hello ' ));
38+
39+ $ this ->reader ->write ('he ' );
40+ $ this ->reader ->write ('ll ' );
41+ $ this ->reader ->write ('o ' );
42+
43+ $ this ->assertEquals (' ' , $ this ->reader ->getBuffer ());
44+ }
45+
46+ public function testReadBuffered ()
47+ {
48+ $ this ->reader ->write ('hello ' );
49+
50+ $ this ->reader ->readLength (5 )->then ($ this ->expectCallableOnce ('hello ' ));
51+
52+ $ this ->assertEquals ('' , $ this ->reader ->getBuffer ());
53+ }
54+
55+ public function testSequence ()
56+ {
1857 $ this ->reader ->readByte ()->then ($ this ->expectCallableOnce (ord ('h ' )));
1958 $ this ->reader ->readByteAssert (ord ('e ' ))->then ($ this ->expectCallableOnce (ord ('e ' )));
2059 $ this ->reader ->readLength (4 )->then ($ this ->expectCallableOnce ('llo ' ));
@@ -24,4 +63,20 @@ public function testA()
2463
2564 $ this ->assertEquals ('rld ' , $ this ->reader ->getBuffer ());
2665 }
66+
67+ /**
68+ * @expectedException InvalidArgumentException
69+ */
70+ public function testInvalidStructure ()
71+ {
72+ $ this ->reader ->readBinary (array ('invalid ' => 'y ' ));
73+ }
74+
75+ /**
76+ * @expectedException InvalidArgumentException
77+ */
78+ public function testInvalidCallback ()
79+ {
80+ $ this ->reader ->readBufferCallback (array ());
81+ }
2782}
0 commit comments