/**
  * Returns the prototype of the items type
  *
  * A collection has always one property with name item representing the type of all items in the collection.
  *
  * @return Prototype
  */
 public static function itemPrototype()
 {
     return TestUser::prototype();
 }
 /**
  * @test
  * @dataProvider provideTestUsers
  */
 public function it_adds_a_user_to_existing_file(TestUserCollection $users)
 {
     if (!is_writable(sys_get_temp_dir())) {
         $this->markTestSkipped(sprintf("Temp dir %s is not writable", sys_get_temp_dir()));
     }
     $this->fileTypeAdapter->writeDataOfType($this->tempFile, $users);
     $donaldDuck = TestUser::fromNativeValue(['id' => 3, 'name' => 'Donald Duck', 'age' => 57]);
     $this->fileTypeAdapter->writeDataOfType($this->tempFile, $donaldDuck);
     $readUsersData = $this->fileTypeAdapter->readDataForType($this->tempFile, $users->prototype());
     $readUsers = TestUserCollection::fromNativeValue($readUsersData);
     $this->assertEquals(3, count($readUsers->value()));
     $this->assertEquals(['John Doe', 'Max Mustermann', 'Donald Duck'], array_map(function (TestUser $user) {
         return $user->property('name')->value();
     }, $readUsers->value()));
 }
 /**
  * @test
  */
 public function it_writes_each_user_to_a_single_file_and_the_item_index_is_available_to_create_unique_file_names()
 {
     $taskListPosition = TaskListPosition::at(TaskListId::linkWith(NodeName::defaultName(), ProcessId::generate()), 1);
     $testUsers = TestUserCollection::fromNativeValue([["id" => 1, "name" => "John Doe", "age" => 34], ["id" => 2, "name" => "Max Mustermann", "age" => 41]]);
     $metadata = [FileGateway::META_FILE_TYPE => 'json', FileGateway::META_PATH => $this->tempPath, FileGateway::META_FILENAME_TEMPLATE => 'user-{{item_index}}.json', FileGateway::META_WRITE_MULTI_FILES => true];
     $this->tempFiles[] = 'user-0.json';
     $this->tempFiles[] = 'user-1.json';
     $workflowMessage = WorkflowMessage::newDataCollected($testUsers, NodeName::defaultName()->toString(), 'file-connector');
     $workflowMessage->connectToProcessTask($taskListPosition);
     $workflowMessage = $workflowMessage->prepareDataProcessing($taskListPosition, NodeName::defaultName()->toString(), $metadata);
     $this->fileGateway->handleWorkflowMessage($workflowMessage);
     $this->assertInstanceOf('Prooph\\Processing\\Message\\WorkflowMessage', $this->messageReceiver->getLastReceivedMessage());
     $this->assertTrue(file_exists($this->tempPath . $this->tempFiles[0]));
     $this->assertTrue(file_exists($this->tempPath . $this->tempFiles[1]));
     $userData = json_decode(file_get_contents($this->tempPath . $this->tempFiles[0]), true);
     $user = TestUser::fromJsonDecodedData($userData);
     $this->assertEquals('John Doe', $user->property('name')->value());
 }
 /**
  * @test
  */
 public function it_reads_data_for_user_from_json()
 {
     $data = $this->fileTypeAdapter->readDataForType($this->getTestDataPath() . 'testuser_john_doe.json', TestUser::prototype());
     $user = TestUser::fromNativeValue($data);
     $this->assertEquals('John Doe', $user->property('name')->value());
 }