From 7cb84649660e519a5019b50c137384f3c5580696 Mon Sep 17 00:00:00 2001 From: Ronan Giron Date: Tue, 23 Apr 2019 18:54:11 +0200 Subject: [PATCH 1/7] New test to illustrate exception for new domain entity --- tests/ValueObjectTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/ValueObjectTest.php b/tests/ValueObjectTest.php index 6b45d49..36cee1e 100644 --- a/tests/ValueObjectTest.php +++ b/tests/ValueObjectTest.php @@ -112,5 +112,17 @@ public function test() ]; $actual = $fakeRecord->getArrayCopy(); $this->assertEquals($expect, $actual); + + + // Test new entity + $newFakeEntity = new Fake(new Email('fake@example.com'), + new Address('456 Central', + 'Bel Air', + '90007', + 'CA'), + new DateTime('now'), + new Bag([])); + $this->transit->store($newFakeEntity); + $this->transit->persist(); } } From 54573160669dca95aee39e8eb5d9a026d56d8bee Mon Sep 17 00:00:00 2001 From: Ronan Giron Date: Thu, 25 Apr 2019 09:33:32 +0200 Subject: [PATCH 2/7] Fix thrown exception with no mapped handler during creation of new domain entity --- src/Handler/EntityHandler.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Handler/EntityHandler.php b/src/Handler/EntityHandler.php index a80d51f..f43ea6a 100644 --- a/src/Handler/EntityHandler.php +++ b/src/Handler/EntityHandler.php @@ -174,6 +174,10 @@ protected function refreshDomainProperty( } // refresh the underlying domain object - $this->handlerLocator->get($datum)->refreshDomain($datum, $refresh); + $handler = $this->handlerLocator->get($datum); + if (!$handler instanceof MappedHandler) { + return; + } + $handler->refreshDomain($datum, $refresh); } } From 6bb8e26e3251a233b3a1e70f147db6fc566482f1 Mon Sep 17 00:00:00 2001 From: Ronan Giron Date: Tue, 30 Apr 2019 17:54:31 +0200 Subject: [PATCH 3/7] Separate/Update test of new entity --- tests/ValueObjectTest.php | 86 ++++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 33 deletions(-) diff --git a/tests/ValueObjectTest.php b/tests/ValueObjectTest.php index 36cee1e..6b77d6f 100644 --- a/tests/ValueObjectTest.php +++ b/tests/ValueObjectTest.php @@ -33,15 +33,15 @@ public function test() // fake a record from the database $fakeRecord = new FakeRecord( new FakeRow([ - 'fake_id' => '1', - 'email_address' => 'fake@example.com', - 'date_time' => '1970-08-08', - 'json_blob' => json_encode(['foo' => 'bar', 'baz' => 'dib']), - 'address_street' => '123 Main', - 'address_city' => 'Beverly Hills', - 'address_state' => 'CA', - 'address_zip' => '90210' - ]), + 'fake_id' => '1', + 'email_address' => 'fake@example.com', + 'date_time' => '1970-08-08', + 'json_blob' => json_encode(['foo' => 'bar', 'baz' => 'dib']), + 'address_street' => '123 Main', + 'address_city' => 'Beverly Hills', + 'address_state' => 'CA', + 'address_zip' => '90210', + ]), new Related([]) ); @@ -62,20 +62,20 @@ public function test() 'emailAddress' => [ 'address' => 'fake@example.com', ], - 'dateTime' => [ + 'dateTime' => [ 'date' => '1970-08-08', 'time' => '00:00:00', ], - 'jsonBlob' => [ - 'foo' => 'bar', - 'baz' => 'dib', + 'jsonBlob' => [ + 'foo' => 'bar', + 'baz' => 'dib', ], - 'fakeId' => 1, - 'address' => [ + 'fakeId' => 1, + 'address' => [ 'street' => '123 Main', - 'city' => 'Beverly Hills', - 'state' => 'CA', - 'zip' => '90210', + 'city' => 'Beverly Hills', + 'state' => 'CA', + 'zip' => '90210', ], ]; @@ -101,28 +101,48 @@ public function test() $this->transit->persist(); $expect = [ - 'fake_id' => 1, - 'email_address' => 'fake_changed@example.com', - 'date_time' => '1970-08-08 00:00:00', - 'json_blob' => '{"foo":"bar","baz":"dib"}', + 'fake_id' => 1, + 'email_address' => 'fake_changed@example.com', + 'date_time' => '1970-08-08 00:00:00', + 'json_blob' => '{"foo":"bar","baz":"dib"}', 'address_street' => '456 Central', - 'address_city' => 'Bel Air', - 'address_state' => '90007', - 'address_zip' => 'CA', + 'address_city' => 'Bel Air', + 'address_state' => '90007', + 'address_zip' => 'CA', ]; $actual = $fakeRecord->getArrayCopy(); $this->assertEquals($expect, $actual); + } + public function testNewEntity() + { + // Create new entity + $newFakeEntity = new Fake($email = new Email('fake@example.com'), + $address = new Address('456 Central', + 'Bel Air', + 'CA', + '90007'), + $dateTime = new DateTime('now'), + $bag = new Bag([])); - // Test new entity - $newFakeEntity = new Fake(new Email('fake@example.com'), - new Address('456 Central', - 'Bel Air', - '90007', - 'CA'), - new DateTime('now'), - new Bag([])); + // Store and persist data $this->transit->store($newFakeEntity); $this->transit->persist(); + + $newFakeRecord = $this->transit->getStorage()->offsetGet($newFakeEntity); + + $expect = [ + 'fake_id' => null, + 'email_address' => 'fake@example.com', + 'date_time' => $dateTime->format('Y-m-d H:i:s'), + 'json_blob' => '[]', + 'address_street' => '456 Central', + 'address_city' => 'Bel Air', + 'address_state' => 'CA', + 'address_zip' => '90007', + ]; + $actual = $newFakeRecord->getArrayCopy(); + + $this->assertEquals($expect, $actual); } } From 90b1e36b5feaadfcd568b4387f1346afd2d65cb6 Mon Sep 17 00:00:00 2001 From: Ronan Giron Date: Thu, 9 Jan 2020 18:39:17 +0100 Subject: [PATCH 4/7] Ignore plan if method is null --- src/Transit.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Transit.php b/src/Transit.php index f3d163a..c305a9b 100644 --- a/src/Transit.php +++ b/src/Transit.php @@ -93,6 +93,9 @@ public function persist() : void foreach ($this->plan as $domain) { $handler = $this->handlerLocator->get($domain); $method = $this->plan->getInfo(); + if (null === $method) { + continue; + } $source = $handler->$method($domain, $refresh); if ($source instanceof RecordSet) { $this->atlas->persistRecordSet($source); From 857c037375afee403cf76203cc9e12d2de1e34f1 Mon Sep 17 00:00:00 2001 From: Ronan Giron Date: Fri, 31 Jul 2020 09:44:04 +0200 Subject: [PATCH 5/7] Replace deprecated ReflectionParameter::getClass() method --- src/Reflection/ParametersTrait.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Reflection/ParametersTrait.php b/src/Reflection/ParametersTrait.php index a6af72b..cfe767f 100644 --- a/src/Reflection/ParametersTrait.php +++ b/src/Reflection/ParametersTrait.php @@ -3,7 +3,6 @@ namespace Atlas\Transit\Reflection; -use Atlas\Transit\Inflector\Inflector; use ReflectionClass; trait ParametersTrait @@ -57,13 +56,14 @@ protected function setParameters( $this->types[$name] = null; $this->classes[$name] = null; - $class = $rparam->getClass(); + $type = $rparam->getType(); + $class = null !== $type && !$type->isBuiltin() ? $type->getName() : null; + if ($class !== null) { - $this->classes[$name] = $class->getName(); + $this->classes[$name] = $class; continue; } - $type = $rparam->getType(); if ($type === null) { continue; } From 05bcd01ede5cd536bfb1a653e06b7c2c8a8b4e07 Mon Sep 17 00:00:00 2001 From: Ronan Giron Date: Tue, 30 Aug 2022 15:10:06 +0200 Subject: [PATCH 6/7] Remove entity from plan if exception is thrown --- src/Transit.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Transit.php b/src/Transit.php index c305a9b..25c8070 100644 --- a/src/Transit.php +++ b/src/Transit.php @@ -96,11 +96,16 @@ public function persist() : void if (null === $method) { continue; } - $source = $handler->$method($domain, $refresh); - if ($source instanceof RecordSet) { - $this->atlas->persistRecordSet($source); - } else { - $this->atlas->persist($source); + try { + $source = $handler->$method($domain, $refresh); + if ($source instanceof RecordSet) { + $this->atlas->persistRecordSet($source); + } else { + $this->atlas->persist($source); + } + } catch (\Exception $exception) { + $this->plan->setInfo(null); + throw $exception; } } From e6ce03435d3520fb3d51079daddb79530750174a Mon Sep 17 00:00:00 2001 From: Ronan Giron Date: Mon, 26 May 2025 11:07:21 +0200 Subject: [PATCH 7/7] Fix deprecated creation of dynamic property --- src/Handler/HandlerLocator.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Handler/HandlerLocator.php b/src/Handler/HandlerLocator.php index 2aa9ce6..9a9e206 100644 --- a/src/Handler/HandlerLocator.php +++ b/src/Handler/HandlerLocator.php @@ -8,6 +8,8 @@ class HandlerLocator { + private $atlas; + protected $instances = []; protected $storage;