22
33namespace Tests \Jobs ;
44
5- use Illuminate \Database \DatabaseManager ;
6- use Illuminate \Foundation \Testing \RefreshDatabase ;
5+ use Illuminate \Foundation \Testing \DatabaseTransactions ;
76use Tests \TestCase ;
87use App \User ;
98use App \Wiki ;
1716
1817class PlatformStatsSummaryJobTest extends TestCase
1918{
20- use RefreshDatabase ;
19+ use DatabaseTransactions ;
2120
2221 private $ numWikis = 5 ;
2322 private $ wikis = [];
@@ -31,6 +30,7 @@ protected function setUp(): void {
3130 DB ::connection ('mysql ' )->getPdo ()->exec ("DROP DATABASE IF EXISTS {$ this ->db_name }{$ n }; " );
3231 }
3332 $ this ->seedWikis ();
33+ $ this ->manager = $ this ->app ->make ('db ' );
3434 }
3535
3636 protected function tearDown (): void {
@@ -42,14 +42,15 @@ protected function tearDown(): void {
4242 }
4343
4444 private function seedWikis () {
45+ $ manager = $ this ->app ->make ('db ' );
4546 for ($ n = 0 ; $ n < $ this ->numWikis ; $ n ++ ) {
4647
4748 $ user = User::factory ()->create (['verified ' => true ]);
4849 $ wiki = Wiki::factory ()->create ( [ 'deleted_at ' => null ] );
4950 WikiManager::factory ()->create (['wiki_id ' => $ wiki ->id , 'user_id ' => $ user ->id ]);
5051
5152 $ job = new ProvisionWikiDbJob ($ this ->db_prefix . $ n , $ this ->db_name . $ n , null );
52- $ job ->handle ($ this -> app -> make (DatabaseManager::class) );
53+ $ job ->handle ($ manager );
5354
5455 $ wikiDb = WikiDb::whereName ($ this ->db_name .$ n )->first ();
5556 $ wikiDb ->update ( ['wiki_id ' => $ wiki ->id ] );
@@ -63,13 +64,15 @@ private function seedWikis() {
6364 }
6465 public function testQueryGetsStats ()
6566 {
67+ $ manager = $ this ->app ->make ('db ' );
68+
6669 $ mockJob = $ this ->createMock (Job::class);
6770 $ mockJob ->expects ($ this ->never ())->method ('fail ' );
6871
6972 $ job = new PlatformStatsSummaryJob ();
7073 $ job ->setJob ($ mockJob );
7174
72- $ job ->handle ($ this -> app -> make (DatabaseManager::class) );
75+ $ job ->handle ($ manager );
7376 }
7477
7578 public function testGroupings ()
@@ -79,7 +82,7 @@ public function testGroupings()
7982
8083 $ job = new PlatformStatsSummaryJob ();
8184 $ job ->setJob ($ mockJob );
82-
85+
8386 $ testWikis = [
8487 Wiki::factory ()->create ( [ 'deleted_at ' => null , 'domain ' => 'wiki1.com ' ] ),
8588 Wiki::factory ()->create ( [ 'deleted_at ' => null , 'domain ' => 'wiki2.com ' ] ),
@@ -96,7 +99,7 @@ public function testGroupings()
9699 'version ' => 'asdasdasdas ' ,
97100 'prefix ' => 'asdasd ' ,
98101 'wiki_id ' => $ wiki ->id
99- ]);
102+ ]);
100103 }
101104 $ stats = [
102105 [ // inactive
@@ -142,10 +145,10 @@ public function testGroupings()
142145 "platform_summary_version " => "v1 "
143146 ],
144147 ];
145-
148+
146149
147150 $ groups = $ job ->prepareStats ($ stats , $ testWikis );
148-
151+
149152 $ this ->assertEquals (
150153 [
151154 "total " => 4 ,
@@ -159,32 +162,9 @@ public function testGroupings()
159162 "total_non_deleted_edits " => 1 ,
160163 "platform_summary_version " => "v1 "
161164 ],
162- $ groups ,
165+ $ groups ,
163166 );
164167 }
165168
166- function testCreationStats () {
167- $ mockJob = $ this ->createMock (Job::class);
168- $ mockJob ->expects ($ this ->never ())->method ('fail ' );
169-
170- $ job = new PlatformStatsSummaryJob ();
171- $ job ->setJob ($ mockJob );
172-
173- $ testWikis = [];
174- $ testUsers = [];
175-
176- $ stats = $ job ->getCreationStats ();
177-
178- $ this ->assertEquals (
179- [
180- 'wikis_created_PT24H ' => 0 ,
181- 'wikis_created_P30D ' => 0 ,
182- 'users_created_PT24H ' => 0 ,
183- 'users_created_P30D ' => 0 ,
184- ],
185- $ stats ,
186- );
187-
188- }
189169
190170}
0 commit comments