Skip to content

Commit 1b64887

Browse files
author
Frederik Ring
committed
test: remove teardown
1 parent 78e4ea9 commit 1b64887

1 file changed

Lines changed: 31 additions & 18 deletions

File tree

tests/Jobs/PlatformStatsSummaryJobTest.php

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,10 @@ protected function setUp(): void {
3535
}
3636

3737
protected function tearDown(): void {
38-
foreach ($this->wikis as $wiki) {
39-
$wiki->wikiDb()->forceDelete();
40-
$wiki->forceDelete();
41-
}
42-
foreach ($this->users as $user) {
43-
$user->forceDelete();
44-
}
38+
Wiki::query()->delete();
39+
User::query()->delete();
40+
WikiManager::query()->delete();
41+
WikiDb::query()->delete();
4542
parent::tearDown();
4643
}
4744

@@ -59,7 +56,7 @@ private function seedWikis() {
5956
$wikiDb = WikiDb::whereName($this->db_name.$n)->first();
6057
$wikiDb->update( ['wiki_id' => $wiki->id] );
6158

62-
$this->wikis[] = Wiki::whereId($wiki->id)->with('wikidb')->first();
59+
$this->wikis[] = $wiki;
6360
$this->users[] = $user;
6461
}
6562

@@ -86,15 +83,15 @@ public function testGroupings()
8683
$job = new PlatformStatsSummaryJob();
8784
$job->setJob($mockJob);
8885

89-
$this->wikis = [
86+
$wikis = [
9087
Wiki::factory()->create( [ 'deleted_at' => null, 'domain' => 'wiki1.com' ] ),
9188
Wiki::factory()->create( [ 'deleted_at' => null, 'domain' => 'wiki2.com' ] ),
9289
Wiki::factory()->create( [ 'deleted_at' => Carbon::now()->subDays(90)->timestamp, 'domain' => 'wiki3.com' ] ),
9390
Wiki::factory()->create( [ 'deleted_at' => null, 'domain' => 'wiki4.com' ] )
9491
];
9592

96-
foreach($this->wikis as $wiki) {
97-
$wikiDB = WikiDb::create([
93+
foreach($wikis as $wiki) {
94+
WikiDb::create([
9895
'name' => 'mwdb_asdasfasfasf' . $wiki->id,
9996
'user' => 'asdasd',
10097
'password' => 'asdasfasfasf',
@@ -149,7 +146,7 @@ public function testGroupings()
149146
];
150147

151148

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

154151
$this->assertEquals(
155152
[
@@ -174,17 +171,33 @@ function testCreationStats() {
174171
$job = new PlatformStatsSummaryJob();
175172
$job->setJob($mockJob);
176173

177-
$testWikis = [];
178-
$testUsers = [];
174+
Wiki::factory()->create([
175+
'created_at' => Carbon::now()->subHours(1)
176+
]);
177+
Wiki::factory()->create([
178+
'created_at' => Carbon::now()->subDays(2)
179+
]);
180+
Wiki::factory()->create([
181+
'created_at' => Carbon::now()->subDays(90)
182+
]);
183+
User::factory()->create([
184+
'created_at' => Carbon::now()->subHours(1)
185+
]);
186+
User::factory()->create([
187+
'created_at' => Carbon::now()->subHours(2)
188+
]);
189+
User::factory()->create([
190+
'created_at' => Carbon::now()->subDays(200)
191+
]);
179192

180193
$stats = $job->getCreationStats();
181194

182195
$this->assertEquals(
183196
[
184-
'wikis_created_PT24H' => 0,
185-
'wikis_created_P30D' => 0,
186-
'users_created_PT24H' => 0,
187-
'users_created_P30D' => 0,
197+
'wikis_created_PT24H' => 1,
198+
'wikis_created_P30D' => 2,
199+
'users_created_PT24H' => 2,
200+
'users_created_P30D' => 2,
188201
],
189202
$stats,
190203
);

0 commit comments

Comments
 (0)