/** * @TODO: Improve test, the merge_files strategy is not the best choice for the tested scenario * @test */ public function it_collects_users_from_multiple_json_files_using_merge_files_strategy() { $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, 'merge_files' => true]; $message = WorkflowMessage::collectDataOf(TestUser::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(); $user = $wfMessage->payload()->toType(); $this->assertInstanceOf('ProophTest\\Link\\FileConnector\\DataType\\TestUser', $user); //The FileGateway should have found both user files. It uses scandir with descending order so //testuser_max_mustermann.json should be handled before testuser_john_doe.json. //When merging the data of both users John Doe overrides Max Mustermann. $this->assertEquals('John Doe', $user->property('name')->value()); }
/** * 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 */ 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()); }