From d53a98208fc342fb5216bf3d42a87ee765b91850 Mon Sep 17 00:00:00 2001 From: Marcus Bointon Date: Fri, 8 Apr 2022 15:01:49 +0200 Subject: [PATCH 1/3] Add test to check casting when retrieving from DB --- tests/Objects/PointTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/Objects/PointTest.php b/tests/Objects/PointTest.php index a2689c3..8a5e0bb 100644 --- a/tests/Objects/PointTest.php +++ b/tests/Objects/PointTest.php @@ -27,6 +27,19 @@ public function it_stores_point(): void $this->assertDatabaseCount($testPlace->getTable(), 1); } + /** @test */ + public function it_casts_when_retrieved_from_database(): void + { + /** @var TestPlace $testPlace */ + $testPlace = TestPlace::factory()->create([ + 'point' => new Point(180, 0), + ]); + $testPlace2 = TestPlace::find($testPlace->id); + $this->assertEquals($testPlace->point, $testPlace2->point); + dump($testPlace); + dump($testPlace2); + } + /** @test */ public function it_stores_point_from_json(): void { From beed083e232458b48228576a7fd7d7e2497cc95a Mon Sep 17 00:00:00 2001 From: Marcus Bointon Date: Fri, 8 Apr 2022 15:05:36 +0200 Subject: [PATCH 2/3] Add failing test --- tests/Objects/PointTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Objects/PointTest.php b/tests/Objects/PointTest.php index 8a5e0bb..4bee1bc 100644 --- a/tests/Objects/PointTest.php +++ b/tests/Objects/PointTest.php @@ -36,6 +36,7 @@ public function it_casts_when_retrieved_from_database(): void ]); $testPlace2 = TestPlace::find($testPlace->id); $this->assertEquals($testPlace->point, $testPlace2->point); + $this->assertEquals($testPlace, $testPlace2); dump($testPlace); dump($testPlace2); } From 89d7f8ddb84c4b52125b7dcd41fe41350ba23ab3 Mon Sep 17 00:00:00 2001 From: Marcus Bointon Date: Fri, 8 Apr 2022 15:08:41 +0200 Subject: [PATCH 3/3] Set default properties in factory --- tests/TestFactories/TestPlaceFactory.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/TestFactories/TestPlaceFactory.php b/tests/TestFactories/TestPlaceFactory.php index e7fcac0..8ab8a6c 100644 --- a/tests/TestFactories/TestPlaceFactory.php +++ b/tests/TestFactories/TestPlaceFactory.php @@ -18,8 +18,15 @@ class TestPlaceFactory extends Factory public function definition(): array { return [ - 'name' => $this->faker->streetName, - 'address' => $this->faker->address, + 'name' => $this->faker->streetName, + 'address' => $this->faker->address, + 'multi_point' => null, + 'line_string' => null, + 'multi_line_string' => null, + 'polygon' => null, + 'multi_polygon' => null, + 'geometry_collection' => null, + 'point_with_line_string_cast' => null, ]; } }