protected function setUp() { parent::setUp(); $this->logger = $this->prophesize(LoggerInterface::class); $this->messageSerializer = $this->prophesize(MessageSerializer::class); $this->SUT = new CommandAuditor($this->logger->reveal(), $this->messageSerializer->reveal()); }
/** * @test */ public function it_asserts_message_data_returned_by_the_no_op_message_converter() { $testAssertions = new DoSomething(['test' => 'assertions', ['null' => null]]); $messageConverter = new NoOpMessageConverter(); MessageDataAssertion::assert($messageConverter->convertToArray($testAssertions)); //No exception thrown means test green $this->assertTrue(true); }
/** * @param DomainMessage $command * @return \Prophecy\Argument\Token\CallbackToken */ protected function validate_message_body($command) { return Argument::that(function ($actual) use($command) { $messageData = $this->messageConverter->convertToArray($command); $messageData['created_at'] = $command->createdAt()->format('Y-m-d\\TH:i:s.u'); $expected = json_encode($messageData); return $expected === $actual; }); }
/** * @test */ public function it_appends_events_to_a_stream() { $this->adapter->create($this->getTestStream()); $streamEvent = UsernameChanged::with(['name' => 'John Doe'], 2); $streamEvent = $streamEvent->withAddedMetadata('tag', 'person'); $this->adapter->appendTo(new StreamName('Prooph\\Model\\User'), new \ArrayIterator([$streamEvent])); $stream = $this->adapter->load(new StreamName('Prooph\\Model\\User')); $this->assertEquals('Prooph\\Model\\User', $stream->streamName()->toString()); $count = 0; $lastEvent = null; foreach ($stream->streamEvents() as $event) { $count++; $lastEvent = $event; } $this->assertEquals(2, $count); $this->assertInstanceOf(UsernameChanged::class, $lastEvent); $messageConverter = new NoOpMessageConverter(); $streamEventData = $messageConverter->convertToArray($streamEvent); $lastEventData = $messageConverter->convertToArray($lastEvent); $this->assertEquals($streamEventData, $lastEventData); }
/** * @test * @expectedException Assert\InvalidArgumentException * @expectedExceptionMessage was expected to be instanceof of "Prooph\Common\Messaging\DomainMessage" but is not. */ public function it_throws_exception_when_message_is_not_a_domain_message() { $messageMock = $this->getMockForAbstractClass(Message::class); $converter = new NoOpMessageConverter(); $converter->convertToArray($messageMock); }
/** * @test */ public function it_appends_events_to_a_stream() { // Create stream $stream = $this->createStream(); $this->adapter->create($stream); // Append a new event to the stream $newStream = UsernameChanged::with(['name' => 'John Doe'], 2); $newStream = $newStream->withAddedMetadata('tag', 'person'); $this->adapter->appendTo(new StreamName('user_stream'), new \ArrayIterator([$newStream])); // Load events $events = $this->adapter->loadEvents(new StreamName('user_stream'), ['tag' => 'person']); $this->assertCount(2, $events); // Assertion on the last events $lastEvent = $events[1]; $messageConverter = new NoOpMessageConverter(); $this->assertInstanceOf(UsernameChanged::class, $lastEvent); $this->assertEquals($messageConverter->convertToArray($newStream), $messageConverter->convertToArray($lastEvent), 'Loaded event equals the inserted event'); }