Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkingshott committed Feb 7, 2022
1 parent b613e8e commit c723df9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/Models/Statistic.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class Statistic extends Model
{
protected $guarded = [];

protected $casts = [
'values' => 'array',
];

/**
* Get the table associated with the model.
*
Expand Down
14 changes: 7 additions & 7 deletions tests/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ public function it_creates_triggers_for_inserted_and_deleted_user_records() : vo

$this->assertEquals('', $statistics[0]->getRawOriginal('id'));
$this->assertEquals('users', $statistics[0]->table);
$this->assertEquals(['count' => 1], json_decode($statistics[0]->values, true));
$this->assertEquals(['count' => 1], $statistics[0]->values);

$this->assertEquals('1', $statistics[1]->getRawOriginal('id'));
$this->assertEquals('users', $statistics[1]->table);
$this->assertEquals(['post_sum_likes' => '', 'post_count' => ''], json_decode($statistics[1]->values, true));
$this->assertEquals(['post_sum_likes' => '', 'post_count' => ''], $statistics[1]->values);

User::query()->delete();

$this->assertCount(1, Statistic::get());

$this->assertEquals('', Statistic::first()->getRawOriginal('id'));
$this->assertEquals('users', Statistic::first()->table);
$this->assertEquals(['count' => 0], json_decode(Statistic::first()->values, true));
$this->assertEquals(['count' => 0], Statistic::first()->values);
}

/** @test */
Expand All @@ -82,18 +82,18 @@ public function it_creates_triggers_and_statistics_for_seeded_records() : void

$this->assertEquals('', $statistics[0]->getRawOriginal('id'));
$this->assertEquals('posts', $statistics[0]->table);
$this->assertEquals($expected, json_decode($statistics[0]->values, true));
$this->assertEquals($expected, $statistics[0]->values);

$this->assertEquals('', $statistics[1]->getRawOriginal('id'));
$this->assertEquals('users', $statistics[1]->table);
$this->assertEquals(['count' => 2], json_decode($statistics[1]->values, true));
$this->assertEquals(['count' => 2], $statistics[1]->values);

$this->assertEquals('1', $statistics[2]->getRawOriginal('id'));
$this->assertEquals('users', $statistics[2]->table);
$this->assertEquals(['post_sum_likes' => 8, 'post_count' => 4], json_decode($statistics[2]->values, true));
$this->assertEquals(['post_sum_likes' => 8, 'post_count' => 4], $statistics[2]->values);

$this->assertEquals('2', $statistics[3]->getRawOriginal('id'));
$this->assertEquals('users', $statistics[3]->table);
$this->assertEquals(['post_sum_likes' => 14, 'post_count' => 4], json_decode($statistics[3]->values, true));
$this->assertEquals(['post_sum_likes' => 14, 'post_count' => 4], $statistics[3]->values);
}
}

0 comments on commit c723df9

Please sign in to comment.