@@ -6,8 +6,8 @@ class ReadlineTest extends TestCase
6
6
{
7
7
public function setUp ()
8
8
{
9
- $ output = $ this ->getMockBuilder ('Clue\React\Stdio\Stdout ' )->disableOriginalConstructor ()->getMock ();
10
- $ this ->readline = new Readline ($ output );
9
+ $ this -> output = $ this ->getMockBuilder ('Clue\React\Stdio\Stdout ' )->disableOriginalConstructor ()->getMock ();
10
+ $ this ->readline = new Readline ($ this -> output );
11
11
}
12
12
13
13
public function testSettersReturnSelf ()
@@ -45,4 +45,83 @@ public function testMultiByteInput()
45
45
$ this ->assertEquals ('täst ' , $ this ->readline ->getInput ());
46
46
$ this ->assertEquals (4 , $ this ->readline ->getCursorPosition ());
47
47
}
48
+
49
+ public function testRedrawingReadlineWritesToOutputOnce ()
50
+ {
51
+ $ this ->readline ->setPrompt ('> ' );
52
+ $ this ->readline ->setInput ('test ' );
53
+ $ this ->readline ->moveCursorBy (-2 );
54
+
55
+ $ this ->output ->expects ($ this ->once ())->method ('write ' )->with ($ this ->equalTo ("\r\033[K " . "> " . "test " . "\x08\x08" ));
56
+ $ this ->assertSame ($ this ->readline , $ this ->readline ->redraw ());
57
+ }
58
+
59
+ public function testSettingSameSettingsDoesNotNeedToRedraw ()
60
+ {
61
+ $ this ->readline ->setPrompt ('> ' );
62
+ $ this ->readline ->setInput ('test ' );
63
+ $ this ->readline ->moveCursorBy (-2 );
64
+
65
+ $ this ->output ->expects ($ this ->never ())->method ('write ' );
66
+
67
+ $ this ->assertSame ($ this ->readline , $ this ->readline ->setPrompt ('> ' ));
68
+ $ this ->assertSame ($ this ->readline , $ this ->readline ->setInput ('test ' ));
69
+ $ this ->assertSame ($ this ->readline , $ this ->readline ->moveCursorTo (2 ));
70
+ }
71
+
72
+ public function testSettingEchoOnWithInputDoesRedraw ()
73
+ {
74
+ $ this ->readline ->setEcho (false );
75
+ $ this ->readline ->setPrompt ('> ' );
76
+ $ this ->readline ->setInput ('test ' );
77
+
78
+ $ this ->output ->expects ($ this ->once ())->method ('write ' )->with ($ this ->equalTo ("\r\033[K " . "> " . "test " ));
79
+
80
+ $ this ->assertSame ($ this ->readline , $ this ->readline ->setEcho (true ));
81
+ }
82
+
83
+ public function testSettingEchoOffWithInputDoesRedraw ()
84
+ {
85
+ $ this ->readline ->setEcho (true );
86
+ $ this ->readline ->setPrompt ('> ' );
87
+ $ this ->readline ->setInput ('test ' );
88
+
89
+ $ this ->output ->expects ($ this ->once ())->method ('write ' )->with ($ this ->equalTo ("\r\033[K " . "> " ));
90
+
91
+ $ this ->assertSame ($ this ->readline , $ this ->readline ->setEcho (false ));
92
+ }
93
+
94
+ public function testSettingEchoWithoutInputDoesNotNeedToRedraw ()
95
+ {
96
+ $ this ->output ->expects ($ this ->never ())->method ('write ' );
97
+
98
+ $ this ->assertSame ($ this ->readline , $ this ->readline ->setEcho (false ));
99
+ $ this ->assertSame ($ this ->readline , $ this ->readline ->setEcho (true ));
100
+ }
101
+
102
+ public function testSettingInputDoesRedraw ()
103
+ {
104
+ $ this ->output ->expects ($ this ->once ())->method ('write ' );
105
+ $ this ->assertSame ($ this ->readline , $ this ->readline ->setInput ('test ' ));
106
+ }
107
+
108
+ public function testSettingInputWithoutEchoDoesNotNeedToRedraw ()
109
+ {
110
+ $ this ->readline ->setEcho (false );
111
+
112
+ $ this ->output ->expects ($ this ->never ())->method ('write ' );
113
+
114
+ $ this ->assertSame ($ this ->readline , $ this ->readline ->setInput ('test ' ));
115
+ }
116
+
117
+ public function testMovingCursorWithoutEchoDoesNotNeedToRedraw ()
118
+ {
119
+ $ this ->readline ->setEcho (false );
120
+ $ this ->readline ->setInput ('test ' );
121
+
122
+ $ this ->output ->expects ($ this ->never ())->method ('write ' );
123
+
124
+ $ this ->assertSame ($ this ->readline , $ this ->readline ->moveCursorTo (0 ));
125
+ $ this ->assertSame ($ this ->readline , $ this ->readline ->moveCursorBy (2 ));
126
+ }
48
127
}
0 commit comments