33namespace Tests \Unit \Commands \Server ;
44
55use Mockery as m ;
6+ use Pterodactyl \Models \Node ;
7+ use GuzzleHttp \Psr7 \Response ;
68use Pterodactyl \Models \Server ;
79use Illuminate \Validation \Factory ;
810use Tests \Unit \Commands \CommandTestCase ;
@@ -38,8 +40,13 @@ public function setUp()
3840 */
3941 public function testSendAction ()
4042 {
43+ /** @var \Pterodactyl\Models\Server[] $servers */
4144 $ servers = factory (Server::class)->times (2 )->make ();
4245
46+ foreach ($ servers as &$ server ) {
47+ $ server ->setRelation ('node ' , factory (Node::class)->make ());
48+ }
49+
4350 $ this ->repository ->shouldReceive ('getServersForPowerActionCount ' )
4451 ->once ()
4552 ->with ([], [])
@@ -51,7 +58,7 @@ public function testSendAction()
5158 ->andReturn ($ servers );
5259
5360 for ($ i = 0 ; $ i < count ($ servers ); $ i ++) {
54- $ this ->powerRepository ->shouldReceive ('setServer->sendSignal ' )
61+ $ this ->powerRepository ->shouldReceive ('setNode-> setServer->sendSignal ' )
5562 ->once ()
5663 ->with ('kill ' )
5764 ->andReturnNull ();
@@ -70,6 +77,7 @@ public function testSendAction()
7077 public function testSendWithFilters ()
7178 {
7279 $ server = factory (Server::class)->make ();
80+ $ server ->setRelation ('node ' , $ node = factory (Node::class)->make ());
7381
7482 $ this ->repository ->shouldReceive ('getServersForPowerActionCount ' )
7583 ->once ()
@@ -81,10 +89,9 @@ public function testSendWithFilters()
8189 ->with ([1 , 2 ], [3 , 4 ])
8290 ->andReturn ([$ server ]);
8391
84- $ this ->powerRepository ->shouldReceive ('setServer->sendSignal ' )
85- ->once ()
86- ->with ('kill ' )
87- ->andReturnNull ();
92+ $ this ->powerRepository ->expects ('setNode ' )->with ($ node )->andReturnSelf ();
93+ $ this ->powerRepository ->expects ('setServer ' )->with ($ server )->andReturnSelf ();
94+ $ this ->powerRepository ->expects ('sendSignal ' )->with ('kill ' )->andReturn (new Response );
8895
8996 $ display = $ this ->runCommand ($ this ->getCommand (), [
9097 'action ' => 'kill ' ,
@@ -103,14 +110,15 @@ public function testSendWithFilters()
103110 public function testSendWithEmptyOptions ()
104111 {
105112 $ server = factory (Server::class)->make ();
113+ $ server ->setRelation ('node ' , factory (Node::class)->make ());
106114
107115 $ this ->repository ->shouldReceive ('getServersForPowerActionCount ' )
108116 ->once ()
109117 ->with ([], [])
110118 ->andReturn (1 );
111119
112120 $ this ->repository ->shouldReceive ('getServersForPowerAction ' )->once ()->with ([], [])->andReturn ([$ server ]);
113- $ this ->powerRepository ->shouldReceive ('setServer->sendSignal ' )->once ()->with ('kill ' )->andReturnNull ();
121+ $ this ->powerRepository ->shouldReceive ('setNode-> setServer->sendSignal ' )->once ()->with ('kill ' )->andReturnNull ();
114122
115123 $ display = $ this ->runCommand ($ this ->getCommand (), [
116124 'action ' => 'kill ' ,
0 commit comments