1010use Pterodactyl \Services \Databases \DeployServerDatabaseService ;
1111use Pterodactyl \Contracts \Repository \DatabaseRepositoryInterface ;
1212use Pterodactyl \Contracts \Repository \DatabaseHostRepositoryInterface ;
13+ use Pterodactyl \Exceptions \Service \Database \NoSuitableDatabaseHostException ;
1314
1415class DeployServerDatabaseServiceTest extends TestCase
1516{
@@ -51,24 +52,17 @@ public function setUp(): void
5152 */
5253 public function testNonRandomFoundHost ($ limit , $ count )
5354 {
54- config ()->set ('pterodactyl.client_features.databases.allow_random ' , false );
55-
5655 $ server = factory (Server::class)->make (['database_limit ' => $ limit ]);
5756 $ model = factory (Database::class)->make ();
5857
59- $ this ->repository ->shouldReceive ('findCountWhere ' )
60- ->once ()
61- ->with ([['server_id ' , '= ' , $ server ->id ]])
62- ->andReturn ($ count );
63-
6458 $ this ->databaseHostRepository ->shouldReceive ('setColumns->findWhere ' )
6559 ->once ()
6660 ->with ([['node_id ' , '= ' , $ server ->node_id ]])
6761 ->andReturn (collect ([$ model ]));
6862
6963 $ this ->managementService ->shouldReceive ('create ' )
7064 ->once ()
71- ->with ($ server-> id , [
65+ ->with ($ server , [
7266 'database_host_id ' => $ model ->id ,
7367 'database ' => 'testdb ' ,
7468 'remote ' => null ,
@@ -83,25 +77,20 @@ public function testNonRandomFoundHost($limit, $count)
8377
8478 /**
8579 * Test that an exception is thrown if in non-random mode and no host is found.
86- *
87- * @expectedException \Pterodactyl\Exceptions\Service\Database\NoSuitableDatabaseHostException
8880 */
8981 public function testNonRandomNoHost ()
9082 {
91- config ()-> set ( ' pterodactyl.client_features.databases.allow_random ' , false );
83+ $ this -> expectException (NoSuitableDatabaseHostException::class );
9284
9385 $ server = factory (Server::class)->make (['database_limit ' => 1 ]);
9486
95- $ this ->repository ->shouldReceive ('findCountWhere ' )
96- ->once ()
97- ->with ([['server_id ' , '= ' , $ server ->id ]])
98- ->andReturn (0 );
99-
10087 $ this ->databaseHostRepository ->shouldReceive ('setColumns->findWhere ' )
10188 ->once ()
10289 ->with ([['node_id ' , '= ' , $ server ->node_id ]])
10390 ->andReturn (collect ());
10491
92+ $ this ->databaseHostRepository ->expects ('setColumns->all ' )->withNoArgs ()->andReturn (collect ());
93+
10594 $ this ->getService ()->handle ($ server , []);
10695 }
10796
@@ -113,11 +102,6 @@ public function testRandomFoundHost()
113102 $ server = factory (Server::class)->make (['database_limit ' => 1 ]);
114103 $ model = factory (Database::class)->make ();
115104
116- $ this ->repository ->shouldReceive ('findCountWhere ' )
117- ->once ()
118- ->with ([['server_id ' , '= ' , $ server ->id ]])
119- ->andReturn (0 );
120-
121105 $ this ->databaseHostRepository ->shouldReceive ('setColumns->findWhere ' )
122106 ->once ()
123107 ->with ([['node_id ' , '= ' , $ server ->node_id ]])
@@ -129,7 +113,7 @@ public function testRandomFoundHost()
129113
130114 $ this ->managementService ->shouldReceive ('create ' )
131115 ->once ()
132- ->with ($ server-> id , [
116+ ->with ($ server , [
133117 'database_host_id ' => $ model ->id ,
134118 'database ' => 'testdb ' ,
135119 'remote ' => null ,
@@ -144,60 +128,22 @@ public function testRandomFoundHost()
144128
145129 /**
146130 * Test that an exception is thrown when no host is found and random is allowed.
147- *
148- * @expectedException \Pterodactyl\Exceptions\Service\Database\NoSuitableDatabaseHostException
149131 */
150132 public function testRandomNoHost ()
151133 {
152- $ server = factory (Server ::class)-> make ([ ' database_limit ' => 1 ] );
134+ $ this -> expectException (NoSuitableDatabaseHostException ::class);
153135
154- $ this ->repository ->shouldReceive ('findCountWhere ' )
155- ->once ()
156- ->with ([['server_id ' , '= ' , $ server ->id ]])
157- ->andReturn (0 );
136+ $ server = factory (Server::class)->make (['database_limit ' => 1 ]);
158137
159- $ this ->databaseHostRepository ->shouldReceive ('setColumns->findWhere ' )
160- ->once ()
138+ $ this ->databaseHostRepository ->expects ('setColumns->findWhere ' )
161139 ->with ([['node_id ' , '= ' , $ server ->node_id ]])
162140 ->andReturn (collect ());
163141
164- $ this ->databaseHostRepository ->shouldReceive ('setColumns->all ' )
165- ->once ()
166- ->andReturn (collect ());
167-
168- $ this ->getService ()->handle ($ server , []);
169- }
170-
171- /**
172- * Test that a server over the database limit throws an exception.
173- *
174- * @dataProvider databaseExceedingLimitDataProvider
175- * @expectedException \Pterodactyl\Exceptions\Service\Database\TooManyDatabasesException
176- */
177- public function testServerOverDatabaseLimit ($ limit , $ count )
178- {
179- $ server = factory (Server::class)->make (['database_limit ' => $ limit ]);
180-
181- $ this ->repository ->shouldReceive ('findCountWhere ' )
182- ->once ()
183- ->with ([['server_id ' , '= ' , $ server ->id ]])
184- ->andReturn ($ count );
142+ $ this ->databaseHostRepository ->expects ('setColumns->all ' )->withNoArgs ()->andReturn (collect ());
185143
186144 $ this ->getService ()->handle ($ server , []);
187145 }
188146
189- /**
190- * Test that an exception is thrown if the feature is not enabled.
191- *
192- * @expectedException \Pterodactyl\Exceptions\Service\Database\DatabaseClientFeatureNotEnabledException
193- */
194- public function testFeatureNotEnabled ()
195- {
196- config ()->set ('pterodactyl.client_features.databases.enabled ' , false );
197-
198- $ this ->getService ()->handle (factory (Server::class)->make (), []);
199- }
200-
201147 /**
202148 * Provide limits and current database counts for testing.
203149 *
0 commit comments