/** * @dataProvider provideShortcodes */ public function testSerializer(SerializerInterface $serializer, $text, ShortcodeInterface $shortcode) { $serialized = $serializer->serialize($shortcode); $this->assertSame($text, $serialized); $s = $serializer->unserialize($text); $this->assertSame($shortcode->getName(), $s->getName()); $this->assertSame($shortcode->getParameters(), $s->getParameters()); $this->assertSame($shortcode->getContent(), $s->getContent()); }
public function unserialize($text, $format) { switch ($format) { case 'text': return $this->textSerializer->unserialize($text); case 'json': return $this->jsonSerializer->unserialize($text); case 'yaml': return $this->yamlSerializer->unserialize($text); case 'xml': return $this->xmlSerializer->unserialize($text); default: throw new \InvalidArgumentException(sprintf('Invalid unserialization format %s!', $format)); } }
/** * [text arg=val /] * [text arg=val]content[/text] * [json arg=val /] * [json arg=val]content[/json] * [xml arg=val /] * [xml arg=val]content[/xml] * [yaml arg=val /] * [yaml arg=val]content[/yaml] * * @param ShortcodeInterface $shortcode * * @return string */ public function __invoke(ShortcodeInterface $shortcode) { return $this->serializer->serialize($shortcode); }
/** * @dataProvider provideExceptions */ public function testSerializerExceptions(SerializerInterface $serializer, $value, $exceptionClass) { $this->setExpectedException($exceptionClass); $serializer->unserialize($value); }