Skip to content

Commit 78e4ea9

Browse files
author
Frederik Ring
committed
test: add test for creation stats
1 parent 5b35a7f commit 78e4ea9

1 file changed

Lines changed: 36 additions & 12 deletions

File tree

tests/Jobs/PlatformStatsSummaryJobTest.php

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Tests\Jobs;
44

5-
use Illuminate\Foundation\Testing\DatabaseTransactions;
5+
use Illuminate\Foundation\Testing\RefreshDatabase;
66
use Tests\TestCase;
77
use App\User;
88
use App\Wiki;
@@ -16,26 +16,31 @@
1616

1717
class PlatformStatsSummaryJobTest extends TestCase
1818
{
19-
use DatabaseTransactions;
19+
use RefreshDatabase;
2020

2121
private $numWikis = 5;
2222
private $wikis = [];
23+
private $users = [];
2324

2425
private $db_prefix = "somecoolprefix";
2526
private $db_name = "some_cool_db_name";
2627

2728
protected function setUp(): void {
2829
parent::setUp();
29-
for($n = 0; $n < $this->numWikis; $n++ ) {
30+
for ($n = 0; $n < $this->numWikis; $n++) {
3031
DB::connection('mysql')->getPdo()->exec("DROP DATABASE IF EXISTS {$this->db_name}{$n};");
3132
}
3233
$this->wikis = [];
34+
$this->users = [];
3335
}
3436

3537
protected function tearDown(): void {
3638
foreach ($this->wikis as $wiki) {
37-
$wiki['wiki']->wikiDb()->forceDelete();
38-
$wiki['wiki']->forceDelete();
39+
$wiki->wikiDb()->forceDelete();
40+
$wiki->forceDelete();
41+
}
42+
foreach ($this->users as $user) {
43+
$user->forceDelete();
3944
}
4045
parent::tearDown();
4146
}
@@ -54,10 +59,8 @@ private function seedWikis() {
5459
$wikiDb = WikiDb::whereName($this->db_name.$n)->first();
5560
$wikiDb->update( ['wiki_id' => $wiki->id] );
5661

57-
$this->wikis[] = [
58-
'user' => $user,
59-
'wiki' => Wiki::whereId($wiki->id)->with('wikidb')->first()
60-
];
62+
$this->wikis[] = Wiki::whereId($wiki->id)->with('wikidb')->first();
63+
$this->users[] = $user;
6164
}
6265

6366
}
@@ -83,14 +86,14 @@ public function testGroupings()
8386
$job = new PlatformStatsSummaryJob();
8487
$job->setJob($mockJob);
8588

86-
$testWikis = [
89+
$this->wikis = [
8790
Wiki::factory()->create( [ 'deleted_at' => null, 'domain' => 'wiki1.com' ] ),
8891
Wiki::factory()->create( [ 'deleted_at' => null, 'domain' => 'wiki2.com' ] ),
8992
Wiki::factory()->create( [ 'deleted_at' => Carbon::now()->subDays(90)->timestamp, 'domain' => 'wiki3.com' ] ),
9093
Wiki::factory()->create( [ 'deleted_at' => null, 'domain' => 'wiki4.com' ] )
9194
];
9295

93-
foreach($testWikis as $wiki) {
96+
foreach($this->wikis as $wiki) {
9497
$wikiDB = WikiDb::create([
9598
'name' => 'mwdb_asdasfasfasf' . $wiki->id,
9699
'user' => 'asdasd',
@@ -146,7 +149,7 @@ public function testGroupings()
146149
];
147150

148151

149-
$groups = $job->prepareStats($stats, $testWikis);
152+
$groups = $job->prepareStats($stats, $this->wikis);
150153

151154
$this->assertEquals(
152155
[
@@ -164,6 +167,27 @@ public function testGroupings()
164167
$groups,
165168
);
166169
}
170+
function testCreationStats() {
171+
$mockJob = $this->createMock(Job::class);
172+
$mockJob->expects($this->never())->method('fail');
173+
174+
$job = new PlatformStatsSummaryJob();
175+
$job->setJob($mockJob);
176+
177+
$testWikis = [];
178+
$testUsers = [];
179+
180+
$stats = $job->getCreationStats();
167181

182+
$this->assertEquals(
183+
[
184+
'wikis_created_PT24H' => 0,
185+
'wikis_created_P30D' => 0,
186+
'users_created_PT24H' => 0,
187+
'users_created_P30D' => 0,
188+
],
189+
$stats,
190+
);
168191

192+
}
169193
}

0 commit comments

Comments
 (0)