예제 #1
0
 public function testToList()
 {
     $projection = Mockery::mock(ProjectionInterface::CLASS);
     $projection->shouldReceive('getIdentifier')->once()->withNoArgs()->andReturn('projection1');
     $projection->shouldReceive('addEntityChangedListener')->once()->with(Mockery::on(function ($listener) {
         $this->assertInstanceOf(ProjectionList::CLASS, $listener);
         return true;
     }));
     $projection_map = new ProjectionMap([$projection]);
     $projection_list = $projection_map->toList();
     $this->assertInstanceOf(ProjectionList::CLASS, $projection_list);
     $this->assertCount(1, $projection_list);
     $this->assertEquals([$projection], $projection_list->getItems());
 }
 protected function storeUpdatedProjections(ProjectionMap $affected_relatives, ProjectionMap $updated_relatives)
 {
     $modified_relatives = $updated_relatives->filter(function (ProjectionInterface $projection) use($affected_relatives) {
         $identifier = $projection->getIdentifier();
         return $projection->toArray() !== $affected_relatives->getItem($identifier)->toArray();
     });
     // store updates and distribute events
     $this->getStorageWriter()->writeMany($modified_relatives);
     foreach ($modified_relatives as $identifier => $modified_relative) {
         $update_event = new ProjectionUpdatedEvent(['uuid' => Uuid::uuid4()->toString(), 'projection_identifier' => $identifier, 'projection_type' => $modified_relative->getType()->getVariantPrefix(), 'data' => $modified_relative->toArray()]);
         $this->event_bus->distribute(ChannelMap::CHANNEL_INFRA, $update_event);
     }
 }