55namespace AntidotTest \React ;
66
77use Antidot \React \SocketFactory ;
8+ use Assert \AssertionFailedException ;
89use PHPUnit \Framework \TestCase ;
910use Psr \Container \ContainerInterface ;
1011use React \EventLoop \LoopInterface ;
@@ -20,11 +21,52 @@ public function testItShouldcreateReactSocketInstances(): void
2021 ->withConsecutive ([LoopInterface::class], ['config ' ])
2122 ->willReturnOnConsecutiveCalls (
2223 $ this ->createMock (LoopInterface::class),
23- ['server ' => []]
24+ ['server ' => [' workers ' => 1 , ' host ' => ' 0.0.0.0 ' , ' port ' => 8080 ]]
2425 );
2526
2627 $ factory = new SocketFactory ();
2728 $ socket = $ factory ($ container );
2829 $ this ->assertInstanceOf (Socket::class, $ socket );
2930 }
31+
32+ /** @dataProvider getInvalidConfig */
33+ public function testItShouldThrowExceptionWithInvalidConfig (array $ config ): void
34+ {
35+ $ this ->expectException (AssertionFailedException::class);
36+ $ container = $ this ->createMock (ContainerInterface::class);
37+ $ container ->expects ($ this ->exactly (2 ))
38+ ->method ('get ' )
39+ ->withConsecutive ([LoopInterface::class], ['config ' ])
40+ ->willReturnOnConsecutiveCalls (
41+ $ this ->createMock (LoopInterface::class),
42+ $ config
43+ );
44+
45+ $ factory = new SocketFactory ();
46+ $ factory ($ container );
47+ }
48+
49+ public function getInvalidConfig ()
50+ {
51+ return [
52+ 'Bad Host ' => [
53+ ['server ' => ['port ' => 8080 , 'workers ' => 3 , 'host ' => '756875.67867.7668.787 ' ]]
54+ ],
55+ [
56+ ['server ' => ['host ' => '0.0.0.0 ' , 'port ' => ['test ' ], 'workers ' => 3 ]]
57+ ],
58+ [
59+ ['server ' => ['host ' => '0.0.0.0 ' , 'port ' => 8888 , 'workers ' => 'some ' ]]
60+ ],
61+ [
62+ ['server ' => ['port ' => 43525 , 'workers ' => 3 ]]
63+ ],
64+ [
65+ ['server ' => ['port ' => 43525 , 'host ' => '0.0.0.0 ' ]]
66+ ],
67+ [
68+ ['server ' => ['host ' => '0.0.0.0 ' , 'workers ' => 3 ]]
69+ ],
70+ ];
71+ }
3072}
0 commit comments