Skip to content

Commit

Permalink
Merge branch 'feature/use-standard-date-time-in-domain-message' into …
Browse files Browse the repository at this point in the history
…develop
  • Loading branch information
mrsimonbennett committed Aug 7, 2017
2 parents 3965e96 + 00ad19d commit 88e8761
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Contracts/Domain/DomainMessage.php
@@ -1,7 +1,8 @@
<?php
namespace SmoothPhp\Contracts\Domain;

use SmoothPhp\Domain\DateTime;
use DateTime;
use SmoothPhp\Domain\Metadata;

/**
* Interface DomainMessage
Expand Down
3 changes: 2 additions & 1 deletion src/Domain/DomainMessage.php
@@ -1,6 +1,7 @@
<?php
namespace SmoothPhp\Domain;

use DateTime;
use SmoothPhp\Contracts\Domain\DomainMessage as DomainMessageInterface;

/**
Expand Down Expand Up @@ -61,7 +62,7 @@ public function __construct($id, $playHead, Metadata $metadata, $payload, DateTi
*/
public static function recordNow($id, $playHead, Metadata $metadata, $payload)
{
return new DomainMessage($id, $playHead, $metadata, $payload, DateTime::now());
return new DomainMessage($id, $playHead, $metadata, $payload, new DateTime);
}

/**
Expand Down
15 changes: 14 additions & 1 deletion tests/Domain/DomainMessageTest.php
@@ -1,6 +1,7 @@
<?php
namespace SmoothPhp\Test\Domain;

use Carbon\Carbon;
use SmoothPhp\Contracts\EventSourcing\Event;
use SmoothPhp\Domain\DateTime;
use SmoothPhp\Domain\DomainMessage;
Expand Down Expand Up @@ -45,10 +46,22 @@ public function test_default_domain_message_static()
$this->assertEquals(0, $domainMessage->getPlayHead());
$this->assertSame($metaData, $domainMessage->getMetadata());
$this->assertSame($payload, $domainMessage->getPayload());
$this->assertTrue($domainMessage->getRecordedOn()->diffInSeconds() <= 1);
$this->assertTrue(Carbon::instance($domainMessage->getRecordedOn())->diffInSeconds() <= 1);

$this->assertEquals('SmoothPhp.Test.Domain.TestEvent', $domainMessage->getType());
}

public function test_carbon_test_date_does_not_affect()
{
$metaData = new Metadata();
$payload = new TestEvent();
$date = Carbon::create(2017, 1, 1);
Carbon::setTestNow($date);
$domainMessage = DomainMessage::recordNow('1', 0, $metaData, $payload);

$formatted = $domainMessage->getRecordedOn()->format('d/m/Y');
$this->assertNotSame($date->format('d/m/Y'), $formatted);
}
}

class TestEvent implements Event
Expand Down

0 comments on commit 88e8761

Please sign in to comment.