Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/prooph/common
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Miertsch committed Nov 8, 2015
2 parents da2f3ea + e15928c commit 76bc013
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 12 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ language: php
php:
- 5.5
- 5.6
- 7

before_script:
- composer self-update
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
"prooph",
"common"
],
"homepage": "https://github.com/prooph/common",
"homepage": "http://getprooph.org/",
"license": "BSD-3-Clause",
"require": {
"php": ">=5.5",
"ramsey/uuid" : "~2.7",
"php": "~5.5|~7.0",
"ramsey/uuid" : "~2.8",
"beberlei/assert": "~2.0"
},
"require-dev": {
"phpunit/phpunit": "~4.7",
"phpunit/phpunit": "~4.8",
"fabpot/php-cs-fixer": "1.7.*",
"satooshi/php-coveralls": "dev-master"
},
Expand Down
6 changes: 5 additions & 1 deletion src/Messaging/DomainMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ protected function init()
}

if ($this->createdAt === null) {
$this->createdAt = \DateTimeImmutable::createFromFormat('U.u', microtime(true));
$time = microtime(true);
if (false === strpos($time, '.')) {
$time .= '.0000';
}
$this->createdAt = \DateTimeImmutable::createFromFormat('U.u', $time);
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/Messaging/FQCNMessageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ public function createMessageFromArray($messageName, array $messageData)
throw new \UnexpectedValueException('Given message name is not a valid class: ' . (string)$messageName);
}

$ref = new \ReflectionClass($messageName);

if (!$ref->isSubclassOf(DomainMessage::class)) {
if (!is_subclass_of($messageName, DomainMessage::class)) {
throw new \UnexpectedValueException(sprintf(
'Message class %s is not a sub class of %s',
$messageName,
Expand All @@ -55,7 +53,11 @@ public function createMessageFromArray($messageName, array $messageData)
}

if (! isset($messageData['created_at'])) {
$messageData['created_at'] = \DateTimeImmutable::createFromFormat('U.u', microtime(true));
$time = microtime(true);
if (false === strpos($time, '.')) {
$time .= '.0000';
}
$messageData['created_at'] = \DateTimeImmutable::createFromFormat('U.u', $time);
}

if (! isset($messageData['metadata'])) {
Expand Down
4 changes: 2 additions & 2 deletions src/Messaging/MessageDataAssertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ private static function assertSubPayload($payload)
if (is_array($payload)) {
foreach ($payload as $subPayload) {
self::assertSubPayload($subPayload);
return;
}
return;
}

Assertion::scalar($payload, 'payload must only contain arrays and scalar values');
Assertion::nullOrscalar($payload, 'payload must only contain arrays and scalar values');
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/Messaging/PayloadTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,10 @@ protected function setPayload(array $payload)
{
$this->payload = $payload;
}

/**
* Use this method to initialize message with defaults or extend your class from
* \Prooph\Common\Messaging\DomainMessage
*/
abstract protected function init();
}
28 changes: 28 additions & 0 deletions tests/Event/ProophActionEventEmitterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,34 @@ public function it_stops_dispatching_when_event_propagation_is_stopped()
$this->assertSame($actionEvent, $listener1->lastEvent);
}

/**
* @test
*/
public function it_stops_dispatching_when_event_propagation_is_stopped_2()
{
$lastEvent = null;
$listener1 = new ActionEventListenerMock();
$listener2 = function (ActionEvent $event) {};
$listener3 = function (ActionEvent $event) use (&$lastEvent) {
if ($event->getParam('payload', false)) {
$lastEvent = $event;
}
};

$actionEvent = $this->proophActionEventEmitter->getNewActionEvent("test", $this, ['payload' => true]);

$this->proophActionEventEmitter->attachListener("test", $listener1);
$this->proophActionEventEmitter->attachListener("test", $listener2);
$this->proophActionEventEmitter->attachListener("test", $listener3);

$this->proophActionEventEmitter->dispatchUntil($actionEvent, function (ActionEvent $e) {
$e->stopPropagation(true);
});

$this->assertNull($lastEvent);
$this->assertSame($actionEvent, $listener1->lastEvent);
}

/**
* @test
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/Messaging/MessageDataAssertionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class MessageDataAssertionTest extends \PHPUnit_Framework_TestCase
*/
public function it_asserts_message_data_returned_by_the_no_op_message_converter()
{
$testAssertions = new DoSomething(['test' => 'assertions']);
$testAssertions = new DoSomething(['test' => 'assertions', ['null' => null]]);

$messageConverter = new NoOpMessageConverter();

Expand Down

0 comments on commit 76bc013

Please sign in to comment.