Skip to content
6 changes: 5 additions & 1 deletion src/Handler/EntityHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 2 additions & 0 deletions src/Handler/HandlerLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

class HandlerLocator
{
private $atlas;

protected $instances = [];

protected $storage;
Expand Down
8 changes: 4 additions & 4 deletions src/Reflection/ParametersTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace Atlas\Transit\Reflection;

use Atlas\Transit\Inflector\Inflector;
use ReflectionClass;

trait ParametersTrait
Expand Down Expand Up @@ -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;
}
Expand Down
18 changes: 13 additions & 5 deletions src/Transit.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,19 @@ public function persist() : void
foreach ($this->plan as $domain) {
$handler = $this->handlerLocator->get($domain);
$method = $this->plan->getInfo();
$source = $handler->$method($domain, $refresh);
if ($source instanceof RecordSet) {
$this->atlas->persistRecordSet($source);
} else {
$this->atlas->persist($source);
if (null === $method) {
continue;
}
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;
}
}

Expand Down
82 changes: 57 additions & 25 deletions tests/ValueObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([])
);

Expand All @@ -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',
],
];

Expand All @@ -101,16 +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([]));

// 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);
}
}