public function testShouldSkipPropertyReturnsFalseIfNoPredicateMatches()
 {
     $metadata = new StaticPropertyMetadata(\stdClass::class, 'foo', 'bar');
     $context = SerializationContext::create();
     $strat = new DisjunctExclusionStrategy([$first = $this->createMock(ExclusionStrategyInterface::class), $last = $this->createMock(ExclusionStrategyInterface::class)]);
     $first->expects($this->once())->method('shouldSkipProperty')->with($metadata, $context)->will($this->returnValue(false));
     $last->expects($this->once())->method('shouldSkipProperty')->with($metadata, $context)->will($this->returnValue(false));
     $this->assertFalse($strat->shouldSkipProperty($metadata, $context));
 }
Beispiel #2
0
 public function testSerializeNullOption()
 {
     $context = SerializationContext::create();
     $this->assertFalse($context->shouldSerializeNull());
     $context->setSerializeNull(false);
     $this->assertFalse($context->shouldSerializeNull());
     $context->setSerializeNull(true);
     $this->assertTrue($context->shouldSerializeNull());
     $context->setSerializeNull('foo');
     $this->assertTrue($context->shouldSerializeNull());
     $context->setSerializeNull('0');
     $this->assertFalse($context->shouldSerializeNull());
 }
 public function testDepthExclusionStrategy()
 {
     $context = SerializationContext::create()->addExclusionStrategy(new DepthExclusionStrategy());
     $data = new Tree(new Node([new Node([new Node([new Node([new Node()])])])]));
     $this->assertEquals($this->getContent('tree'), $this->serializer->serialize($data, $this->getFormat(), $context));
 }
 public function testObjectWithNamespacesAndList()
 {
     $object = new ObjectWithNamespacesAndList();
     $object->name = 'name';
     $object->nameAlternativeB = 'nameB';
     $object->phones = ['111', '222'];
     $object->addresses = ['A' => 'Street 1', 'B' => 'Street 2'];
     $object->phonesAlternativeB = ['555', '666'];
     $object->addressesAlternativeB = ['A' => 'Street 5', 'B' => 'Street 6'];
     $object->phonesAlternativeC = ['777', '888'];
     $object->addressesAlternativeC = ['A' => 'Street 7', 'B' => 'Street 8'];
     $object->phonesAlternativeD = ['999', 'AAA'];
     $object->addressesAlternativeD = ['A' => 'Street 9', 'B' => 'Street A'];
     $this->assertEquals($this->getContent('object_with_namespaces_and_list'), $this->serialize($object, SerializationContext::create()));
     $this->assertEquals($object, $this->deserialize($this->getContent('object_with_namespaces_and_list'), get_class($object)));
 }