/**
  * @test
  */
 public function it_writes_users_to_json_file()
 {
     $users = TestUserCollection::fromNativeValue([['id' => 1, 'name' => 'John Doe', 'age' => 34], ['id' => 2, 'name' => 'Max Mustermann', 'age' => 41]]);
     $this->fileTypeAdapter->writeDataOfType($this->tempFile, $users);
     $readUsersData = $this->fileTypeAdapter->readDataForType($this->tempFile, TestUserCollection::prototype());
     $readUsers = TestUserCollection::fromNativeValue($readUsersData);
     $this->assertEquals(2, count($readUsers->value()));
     $this->assertEquals(['John Doe', 'Max Mustermann'], array_map(function (TestUser $user) {
         return $user->property('name')->value();
     }, $readUsers->value()));
 }
Ejemplo n.º 2
0
 /**
  * @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());
 }
 /**
  * @return array
  */
 public function provideTestUsers()
 {
     $users = TestUserCollection::fromNativeValue([['id' => 1, 'name' => 'John Doe', 'age' => 34], ['id' => 2, 'name' => 'Max Mustermann', 'age' => 41]]);
     return [[$users]];
 }