@@ -95,6 +95,30 @@ public function itShouldReturnFalseForAnyDataWrittenToItWhenPaused()
9595 $ this ->assertFalse ($ ret );
9696 }
9797
98+ /** @test */
99+ public function itShouldReturnFalseForAnyDataWrittenToItWhenDataEventEndsStream ()
100+ {
101+ $ through = new ThroughStream ();
102+ $ through ->on ('data ' , function () use ($ through ) {
103+ $ through ->end ();
104+ });
105+ $ ret = $ through ->write ('foo ' );
106+
107+ $ this ->assertFalse ($ ret );
108+ }
109+
110+ /** @test */
111+ public function itShouldReturnFalseForAnyDataWrittenToItWhenDataEventClosesStream ()
112+ {
113+ $ through = new ThroughStream ();
114+ $ through ->on ('data ' , function () use ($ through ) {
115+ $ through ->close ();
116+ });
117+ $ ret = $ through ->write ('foo ' );
118+
119+ $ this ->assertFalse ($ ret );
120+ }
121+
98122 /** @test */
99123 public function itShouldEmitDrainOnResumeAfterReturnFalseForAnyDataWrittenToItWhenPaused ()
100124 {
@@ -106,6 +130,40 @@ public function itShouldEmitDrainOnResumeAfterReturnFalseForAnyDataWrittenToItWh
106130 $ through ->resume ();
107131 }
108132
133+ /** @test */
134+ public function itShouldNotEmitDrainOnResumeAfterClose ()
135+ {
136+ $ through = new ThroughStream ();
137+ $ through ->close ();
138+
139+ $ through ->on ('drain ' , $ this ->expectCallableNever ());
140+ $ through ->resume ();
141+ }
142+
143+ /** @test */
144+ public function itShouldNotEmitDrainOnResumeAfterReturnFalseForAnyDataWrittenThatCausesStreamToClose ()
145+ {
146+ $ through = new ThroughStream ();
147+ $ through ->on ('data ' , function () use ($ through ) { $ through ->close (); });
148+ $ through ->write ('foo ' );
149+
150+ $ through ->on ('drain ' , $ this ->expectCallableNever ());
151+ $ through ->resume ();
152+ }
153+
154+ /** @test */
155+ public function itShouldReturnFalseForAnyDataWrittenToItAfterPausingFromDrainEvent ()
156+ {
157+ $ through = new ThroughStream ();
158+ $ through ->pause ();
159+ $ through ->write ('foo ' );
160+
161+ $ through ->on ('drain ' , function () use ($ through ) { $ through ->pause (); });
162+ $ through ->resume ();
163+
164+ $ this ->assertFalse ($ through ->write ('bar ' ));
165+ }
166+
109167 /** @test */
110168 public function itShouldReturnTrueForAnyDataWrittenToItWhenResumedAfterPause ()
111169 {
0 commit comments