/** * @param string $serializedObject * @return NamedCommand */ public function deserialize($serializedObject) { $command = $this->serializer->deserialize(json_decode($serializedObject, true)); if (!$command instanceof NamedCommand) { throw new \InvalidArgumentException('The deserialized object is not a command'); } return $command; }
/** * @test */ public function it_should_throw_an_exception_if_deserialized_string_is_not_a_command() { $command = new \stdClass(); $this->serializer->shouldReceive('deserialize')->andReturn($command); $serializer = new UniversalCommandSerializer($this->serializer); $this->setExpectedException(\InvalidArgumentException::class); $serializer->deserialize('[]'); }
/** * @test */ public function itShouldDeferDeserializationToInnerSerializer() { $serialized = ['test']; $return = ['original']; $this->serializer->shouldReceive('deserialize')->with($serialized)->andReturn($return)->once(); $serializer = new RecursiveSerializer($this->serializer); $actualReturn = $serializer->deserialize($serialized); $this->assertEquals($return, $actualReturn); }
/** * @param array $serializedObject * @throws SerializationException * @return mixed */ public function deserialize(array $serializedObject) { return $this->serializer->deserialize($serializedObject); }
/** * @test */ public function itShouldDeserializeUsingCustomSerializerForDateTimeImmutable() { $serializer = new Serializer($this->classMapper, $this->hydratorFactory, $this->dataFormatter, $this->instantiator); $serializer->addCustomSerializer(new DateTimeCustomSerializer()); $serializer->addCustomSerializer(new TimeZoneCustomSerializer()); $serialized = [1469787919, ['+00:00', '_metadata' => ['name' => 'DateTimeZone']], '_metadata' => ['name' => 'DateTimeImmutable']]; $object = $serializer->deserialize($serialized); $this->assertEquals($object, \DateTimeImmutable::createFromFormat('U', 1469787919, new \DateTimeZone('+00:00'))); }