/** * @test */ public function it_only_collects_specified_range_but_returns_total_item_count() { $metadata = ['offset' => 1, 'limit' => 2]; $usersData = $this->fileTypeAdapter->readDataForType($this->getTestDataPath() . "users-header.csv", TestUserCollection::prototype(), $metadata); $testUsers = TestUserCollection::fromNativeValue($usersData); $this->assertEquals(2, count($testUsers->value())); $this->assertEquals(3, $metadata['total_items']); $this->assertEquals(['Max Mustermann', 'Donald Duck'], array_map(function (TestUser $user) { return $user->property('name')->value(); }, $testUsers->value())); }
/** * @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())); }
/** * @test */ public function it_collects_users_from_multiple_json_files() { $taskListPosition = TaskListPosition::at(TaskListId::linkWith(NodeName::defaultName(), ProcessId::generate()), 1); $metadata = ['filename_pattern' => '/^testuser_.+\\.json$/', 'path' => $this->getTestDataPath(), 'file_type' => 'json', 'fetch_mode' => FileGateway::META_FETCH_MODE_MULTI_FILES, 'file_data_type' => TestUser::prototype()->of()]; $message = WorkflowMessage::collectDataOf(TestUserCollection::prototype(), NodeName::defaultName()->toString(), 'file-connector', $metadata); $message->connectToProcessTask($taskListPosition); $this->fileGateway->handleWorkflowMessage($message); $this->assertInstanceOf('Prooph\\Processing\\Message\\WorkflowMessage', $this->messageReceiver->getLastReceivedMessage()); /** @var $wfMessage WorkflowMessage */ $wfMessage = $this->messageReceiver->getLastReceivedMessage(); $userCollection = $wfMessage->payload()->toType(); $this->assertInstanceOf('ProophTest\\Link\\FileConnector\\DataType\\TestUserCollection', $userCollection); $this->assertEquals(2, count($userCollection->value())); $this->assertEquals(2, $wfMessage->metadata()['total_items']); foreach ($userCollection->value() as $testUser) { $this->assertInstanceOf('ProophTest\\Link\\FileConnector\\DataType\\TestUser', $testUser); } }