From c723df92c90015069ba2c05721f079e3a4a30902 Mon Sep 17 00:00:00 2001 From: Matt Kingshott <51963402+mattkingshott@users.noreply.github.com> Date: Mon, 7 Feb 2022 16:04:03 +0000 Subject: [PATCH] WIP --- src/Models/Statistic.php | 4 ++++ tests/Test.php | 14 +++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Models/Statistic.php b/src/Models/Statistic.php index 141fc04..9ebca96 100644 --- a/src/Models/Statistic.php +++ b/src/Models/Statistic.php @@ -8,6 +8,10 @@ class Statistic extends Model { protected $guarded = []; + protected $casts = [ + 'values' => 'array', + ]; + /** * Get the table associated with the model. * diff --git a/tests/Test.php b/tests/Test.php index 8813797..78c6595 100644 --- a/tests/Test.php +++ b/tests/Test.php @@ -43,11 +43,11 @@ 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(); @@ -55,7 +55,7 @@ public function it_creates_triggers_for_inserted_and_deleted_user_records() : vo $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 */ @@ -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); } }