1414use Prologue \Alerts \AlertsMessageBag ;
1515use Tests \Assertions \ControllerAssertionsTrait ;
1616use Pterodactyl \Http \Controllers \Admin \DatabaseController ;
17+ use Pterodactyl \Services \Databases \Hosts \HostUpdateService ;
18+ use Pterodactyl \Services \Databases \Hosts \HostCreationService ;
19+ use Pterodactyl \Services \Databases \Hosts \HostDeletionService ;
1720use Pterodactyl \Contracts \Repository \LocationRepositoryInterface ;
1821use Pterodactyl \Contracts \Repository \DatabaseHostRepositoryInterface ;
1922
@@ -22,29 +25,34 @@ class DatabaseControllerTest extends TestCase
2225 use ControllerAssertionsTrait;
2326
2427 /**
25- * @var \Prologue\Alerts\AlertsMessageBag
28+ * @var \Prologue\Alerts\AlertsMessageBag|\Mockery\Mock
2629 */
27- protected $ alert ;
30+ private $ alert ;
2831
2932 /**
30- * @var \Pterodactyl\Http\Controllers\Admin\DatabaseController
33+ * @var \Pterodactyl\Services\Databases\Hosts\HostCreationService|\Mockery\Mock
3134 */
32- protected $ controller ;
35+ private $ creationService ;
3336
3437 /**
35- * @var \Pterodactyl\Contracts\Repository\LocationRepositoryInterface
38+ * @var \Pterodactyl\Services\Databases\Hosts\HostDeletionService|\Mockery\Mock
3639 */
37- protected $ locationRepository ;
40+ private $ deletionService ;
3841
3942 /**
40- * @var \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface
43+ * @var \Pterodactyl\Contracts\Repository\LocationRepositoryInterface|\Mockery\Mock
4144 */
42- protected $ repository ;
45+ private $ locationRepository ;
4346
4447 /**
45- * @var \Pterodactyl\Services\Databases\HostsUpdateService
48+ * @var \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface|\Mockery\Mock
4649 */
47- protected $ service ;
50+ private $ repository ;
51+
52+ /**
53+ * @var \Pterodactyl\Services\Databases\Hosts\HostUpdateService|\Mockery\Mock
54+ */
55+ private $ updateService ;
4856
4957 /**
5058 * Setup tests.
@@ -54,16 +62,11 @@ public function setUp()
5462 parent ::setUp ();
5563
5664 $ this ->alert = m::mock (AlertsMessageBag::class);
65+ $ this ->creationService = m::mock (HostCreationService::class);
66+ $ this ->deletionService = m::mock (HostDeletionService::class);
5767 $ this ->locationRepository = m::mock (LocationRepositoryInterface::class);
5868 $ this ->repository = m::mock (DatabaseHostRepositoryInterface::class);
59- $ this ->service = m::mock (HostUpdateService::class);
60-
61- $ this ->controller = new DatabaseController (
62- $ this ->alert ,
63- $ this ->repository ,
64- $ this ->service ,
65- $ this ->locationRepository
66- );
69+ $ this ->updateService = m::mock (HostUpdateService::class);
6770 }
6871
6972 /**
@@ -74,7 +77,7 @@ public function testIndexController()
7477 $ this ->locationRepository ->shouldReceive ('getAllWithNodes ' )->withNoArgs ()->once ()->andReturn ('getAllWithNodes ' );
7578 $ this ->repository ->shouldReceive ('getWithViewDetails ' )->withNoArgs ()->once ()->andReturn ('getWithViewDetails ' );
7679
77- $ response = $ this ->controller ->index ();
80+ $ response = $ this ->getController () ->index ();
7881
7982 $ this ->assertIsViewResponse ($ response );
8083 $ this ->assertViewNameEquals ('admin.databases.index ' , $ response );
@@ -92,7 +95,7 @@ public function testViewController()
9295 $ this ->locationRepository ->shouldReceive ('getAllWithNodes ' )->withNoArgs ()->once ()->andReturn ('getAllWithNodes ' );
9396 $ this ->repository ->shouldReceive ('getWithServers ' )->with (1 )->once ()->andReturn ('getWithServers ' );
9497
95- $ response = $ this ->controller ->view (1 );
98+ $ response = $ this ->getController () ->view (1 );
9699
97100 $ this ->assertIsViewResponse ($ response );
98101 $ this ->assertViewNameEquals ('admin.databases.view ' , $ response );
@@ -101,4 +104,21 @@ public function testViewController()
101104 $ this ->assertViewKeyEquals ('locations ' , 'getAllWithNodes ' , $ response );
102105 $ this ->assertViewKeyEquals ('host ' , 'getWithServers ' , $ response );
103106 }
107+
108+ /**
109+ * Return an instance of the DatabaseController with mock dependencies.
110+ *
111+ * @return \Pterodactyl\Http\Controllers\Admin\DatabaseController
112+ */
113+ private function getController (): DatabaseController
114+ {
115+ return new DatabaseController (
116+ $ this ->alert ,
117+ $ this ->repository ,
118+ $ this ->creationService ,
119+ $ this ->deletionService ,
120+ $ this ->updateService ,
121+ $ this ->locationRepository
122+ );
123+ }
104124}
0 commit comments