@@ -12,7 +12,10 @@ class AbstractConnectionDecoratorTest extends TestCase {
1212 protected $ l1 ;
1313 protected $ l2 ;
1414
15- public function setUp () {
15+ /**
16+ * @before
17+ */
18+ public function setUpConnection () {
1619 $ this ->mock = $ this ->getMockBuilder ('Ratchet\ConnectionInterface ' )->getMock ();
1720 $ this ->l1 = new ConnectionDecorator ($ this ->mock );
1821 $ this ->l2 = new ConnectionDecorator ($ this ->l1 );
@@ -132,41 +135,44 @@ public function testDecoratorRecursionLevel2() {
132135 }
133136
134137 public function testWarningGettingNothing () {
135- if (!(error_reporting () & E_NOTICE )) {
136- $ this ->markTestSkipped ('Requires error_reporting to include E_NOTICE ' );
137- }
138-
139- if (method_exists ($ this , 'expectException ' )) {
140- $ this ->expectException (class_exists ('PHPUnit\Framework\Error\Error ' ) ? 'PHPUnit\Framework\Error\Error ' : 'PHPUnit_Framework_Error ' );
141- } else {
142- $ this ->setExpectedException ('PHPUnit_Framework_Error ' );
143- }
138+ $ error = false ;
139+ set_error_handler (function () use (&$ error ) {
140+ $ error = true ;
141+ }, E_NOTICE );
142+
144143 $ var = $ this ->mock ->nonExistant ;
144+
145+ restore_error_handler ();
146+
147+ $ this ->assertTrue ($ error );
148+ $ this ->assertNull ($ var );
145149 }
146150
147151 public function testWarningGettingNothingLevel1 () {
148- if (!(error_reporting () & E_NOTICE )) {
149- $ this ->markTestSkipped ('Requires error_reporting to include E_NOTICE ' );
150- }
151-
152- if (method_exists ($ this , 'expectException ' )) {
153- $ this ->expectException (class_exists ('PHPUnit\Framework\Error\Error ' ) ? 'PHPUnit\Framework\Error\Error ' : 'PHPUnit_Framework_Error ' );
154- } else {
155- $ this ->setExpectedException ('PHPUnit_Framework_Error ' );
156- }
152+ $ error = false ;
153+ set_error_handler (function () use (&$ error ) {
154+ $ error = true ;
155+ }, E_NOTICE );
156+
157157 $ var = $ this ->l1 ->nonExistant ;
158+
159+ restore_error_handler ();
160+
161+ $ this ->assertTrue ($ error );
162+ $ this ->assertNull ($ var );
158163 }
159164
160165 public function testWarningGettingNothingLevel2 () {
161- if (!(error_reporting () & E_NOTICE )) {
162- $ this ->markTestSkipped ('Requires error_reporting to include E_NOTICE ' );
163- }
164-
165- if (method_exists ($ this , 'expectException ' )) {
166- $ this ->expectException (class_exists ('PHPUnit\Framework\Error\Error ' ) ? 'PHPUnit\Framework\Error\Error ' : 'PHPUnit_Framework_Error ' );
167- } else {
168- $ this ->setExpectedException ('PHPUnit_Framework_Error ' );
169- }
166+ $ error = false ;
167+ set_error_handler (function () use (&$ error ) {
168+ $ error = true ;
169+ }, E_NOTICE );
170+
170171 $ var = $ this ->l2 ->nonExistant ;
172+
173+ restore_error_handler ();
174+
175+ $ this ->assertTrue ($ error );
176+ $ this ->assertNull ($ var );
171177 }
172178}
0 commit comments