File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1919 },
2020 "require-dev" : {
2121 "clue/block-react" : " ^1.2" ,
22- "phpunit/phpunit" : " ^7.0 || ^6.0 || ^5.0 || ^4.8.35"
22+ "phpunit/phpunit" : " ^9.3 || ^5.7 || ^4.8.35"
2323 },
2424 "autoload" : {
2525 "psr-4" : { "Clue\\ React\\ Ami\\ " : " src/" }
Original file line number Diff line number Diff line change @@ -53,7 +53,13 @@ private function createClientMock()
5353 {
5454 $ stream = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->getMock ();
5555
56- $ client = $ this ->getMockBuilder ('Clue\React\Ami\Client ' )->setMethods (array ('createAction ' ))->setConstructorArgs (array ($ stream ))->getMock ();
56+ if (method_exists ('PHPUnit\Framework\MockObject\MockBuilder ' , 'onlyMethods ' )) {
57+ // PHPUnit 9+
58+ $ client = $ this ->getMockBuilder ('Clue\React\Ami\Client ' )->onlyMethods (array ('createAction ' ))->setConstructorArgs (array ($ stream ))->getMock ();
59+ } else {
60+ // legacy PHPUnit 4 - PHPUnit 8
61+ $ client = $ this ->getMockBuilder ('Clue\React\Ami\Client ' )->setMethods (array ('createAction ' ))->setConstructorArgs (array ($ stream ))->getMock ();
62+ }
5763
5864 return $ client ;
5965 }
Original file line number Diff line number Diff line change @@ -45,6 +45,12 @@ public function testUnexpectedResponseEmitsErrorAndClosesClient()
4545
4646 private function createStreamMock ()
4747 {
48- return $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('write ' , 'close ' ))->getMock ();
48+ if (method_exists ('PHPUnit\Framework\MockObject\MockBuilder ' , 'onlyMethods ' )) {
49+ // PHPUnit 9+
50+ return $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->onlyMethods (array ('write ' , 'close ' ))->getMock ();
51+ } else {
52+ // legacy PHPUnit 4 - PHPUnit 8
53+ return $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('write ' , 'close ' ))->getMock ();
54+ }
4955 }
5056}
Original file line number Diff line number Diff line change @@ -11,7 +11,10 @@ class FactoryTest extends TestCase
1111 private $ tcp ;
1212 private $ factory ;
1313
14- public function setUp ()
14+ /**
15+ * @before
16+ */
17+ public function setUpFactory ()
1518 {
1619 $ this ->loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
1720 $ this ->tcp = $ this ->getMockBuilder ('React\Socket\ConnectorInterface ' )->getMock ();
Original file line number Diff line number Diff line change @@ -13,13 +13,19 @@ class FunctionalTest extends TestCase
1313 private static $ address = false ;
1414 private static $ loop ;
1515
16- public static function setUpBeforeClass ()
16+ /**
17+ * @beforeClass
18+ */
19+ public static function setUpLoopBeforeClass ()
1720 {
1821 self ::$ address = getenv ('LOGIN ' );
1922 self ::$ loop = \React \EventLoop \Factory::create ();
2023 }
2124
22- public function setUp ()
25+ /**
26+ * @before
27+ */
28+ public function setUpSkipTest ()
2329 {
2430 if (self ::$ address === false ) {
2531 $ this ->markTestSkipped ('No ENV named LOGIN found. Please use "export LOGIN= \'user:pass@host \'. ' );
@@ -54,10 +60,10 @@ public function testPing(Client $client)
5460 /**
5561 * @depends testConnection
5662 * @param Client $client
57- * @expectedException Exception
5863 */
5964 public function testInvalidCommandGetsRejected (Client $ client )
6065 {
66+ $ this ->setExpectedException ('Exception ' );
6167 $ this ->waitFor ($ client ->request ($ client ->createAction ('Invalid ' )));
6268 }
6369
@@ -85,10 +91,10 @@ public function testActionSenderLogoffDisconnects(Client $client)
8591 /**
8692 * @depends testActionSenderLogoffDisconnects
8793 * @param Client $client
88- * @expectedException Exception
8994 */
9095 public function testSendRejectedAfterClose (Client $ client )
9196 {
97+ $ this ->setExpectedException ('Exception ' );
9298 $ this ->waitFor ($ client ->request ($ client ->createAction ('Ping ' )));
9399 }
94100
Original file line number Diff line number Diff line change @@ -132,14 +132,12 @@ public function testParsingResponseIsNotCommandResponse()
132132 $ this ->assertEquals ('Some message--END COMMAND-- ' , $ first ->getFieldValue ('Message ' ));
133133 }
134134
135- /**
136- * @expectedException UnexpectedValueException
137- */
138135 public function testParsingInvalidResponseFails ()
139136 {
140137 $ parser = new Parser ();
141138 $ this ->assertEquals (array (), $ parser ->push ("Asterisk Call Manager/1.3 \r\n" ));
142139
140+ $ this ->setExpectedException ('UnexpectedValueException ' );
143141 $ parser ->push ("invalid response \r\n\r\n" );
144142 }
145143
Original file line number Diff line number Diff line change @@ -18,6 +18,29 @@ protected function expectCallableOnce()
1818
1919 protected function createCallableMock ()
2020 {
21- return $ this ->getMockBuilder ('stdClass ' )->setMethods (array ('__invoke ' ))->getMock ();
21+ if (method_exists ('PHPUnit\Framework\MockObject\MockBuilder ' , 'addMethods ' )) {
22+ // PHPUnit 9+
23+ return $ this ->getMockBuilder ('stdClass ' )->addMethods (array ('__invoke ' ))->getMock ();
24+ } else {
25+ // legacy PHPUnit 4 - PHPUnit 8
26+ return $ this ->getMockBuilder ('stdClass ' )->setMethods (array ('__invoke ' ))->getMock ();
27+ }
28+ }
29+
30+ public function setExpectedException ($ exception , $ exceptionMessage = '' , $ exceptionCode = null )
31+ {
32+ if (method_exists ($ this , 'expectException ' )) {
33+ // PHPUnit 5+
34+ $ this ->expectException ($ exception );
35+ if ($ exceptionMessage !== '' ) {
36+ $ this ->expectExceptionMessage ($ exceptionMessage );
37+ }
38+ if ($ exceptionCode !== null ) {
39+ $ this ->expectExceptionCode ($ exceptionCode );
40+ }
41+ } else {
42+ // legacy PHPUnit 4
43+ parent ::setExpectedException ($ exception , $ exceptionMessage , $ exceptionCode );
44+ }
2245 }
2346}
You can’t perform that action at this time.
0 commit comments