/** * @test */ function it_can_be_set_up_from_array() { $task = ManipulatePayload::with(__DIR__ . '/../../Mock/manipulation/append_world.php'); $taskData = $task->getArrayCopy(); $copiedTask = ManipulatePayload::reconstituteFromArray($taskData); $payload = Payload::fromType(String::fromNativeValue('Hello')); $copiedTask->performManipulationOn($payload); $this->assertEquals('Hello World', $payload->extractTypeData()); }
/** * @test */ public function it_applies_premap_callback_to_payload_collection() { $stringCollection = ["a string", 100, "yet another string"]; $collection = StringCollection::fromNativeValue($stringCollection); $payload = Payload::fromType($collection); $string_cast = Func::prepare('premap', null, function ($item, $key, \Iterator $collection) { return (string) $item; }); $string_cast($payload); $this->assertEquals(["a string", "100", "yet another string"], $payload->extractTypeData()); }
/** * Transforms current message to a data collected event and replaces payload data with collected data * * @param Type $collectedData * @param array $metadata * @throws \Prooph\Processing\Type\Exception\InvalidTypeException If answer type does not match with the previous requested type * @return WorkflowMessage */ public function answerWith(Type $collectedData, array $metadata = []) { $collectedPayload = Payload::fromType($collectedData); $collectedDataTypeClass = $collectedPayload->getTypeClass(); if ($this->payload->getTypeClass() !== $collectedPayload->getTypeClass()) { throw InvalidTypeException::fromInvalidArgumentExceptionAndPrototype(new \InvalidArgumentException(sprintf("Type %s of collected data does not match the type of requested data %s", $collectedPayload->getTypeClass(), $this->payload->getTypeClass())), $collectedDataTypeClass::prototype()); } $type = MessageNameUtils::getTypePartOfMessageName($this->messageName); $metadata = ArrayUtils::merge($this->metadata, $metadata); return new self($collectedPayload, MessageNameUtils::getDataCollectedEventName($type), $this->target, $this->origin, $metadata, $this->processTaskListPosition, $this->version + 1); }
/** * @test */ public function it_is_possible_to_change_type_class() { $userData = array('id' => 1, 'name' => 'Alex', 'address' => array('street' => 'Main Street', 'streetNumber' => 10, 'zip' => '12345', 'city' => 'Test City')); $user = UserDictionary::fromNativeValue($userData); $payload = Payload::fromType($user); $payload->changeTypeClass('Prooph\\ProcessingTest\\Mock\\AddressDictionary'); //Current data should be the user data even if type is already changed $this->assertEquals($userData, $payload->extractTypeData()); $payload->replaceData($userData['address']); $address = $payload->toType(); $this->assertInstanceOf('Prooph\\ProcessingTest\\Mock\\AddressDictionary', $address); $this->assertTrue($user->property("address")->type()->sameAs($address)); }