public function testNormalizeObjectWithNullToManyRelations()
 {
     $product = new Object\Product();
     $product->setId(123);
     $product->setName('product_name');
     $owner = new Object\User();
     $owner->setId(456);
     $owner->setName('user_name');
     $owner->addProduct($product);
     $config = ['exclusion_policy' => 'all', 'fields' => ['id' => null, 'name' => ['exclude' => true], 'category1' => ['exclusion_policy' => 'all', 'property_path' => 'category', 'fields' => 'label'], 'owner' => ['exclusion_policy' => 'all', 'fields' => ['name' => null, 'groups1' => ['exclusion_policy' => 'all', 'property_path' => 'groups', 'fields' => 'id']]]]];
     $result = $this->objectNormalizer->normalizeObject($product, $config);
     $this->assertEquals(['id' => 123, 'category1' => null, 'owner' => ['name' => 'user_name', 'groups1' => []]], $result);
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function process(ContextInterface $context)
 {
     /** @var GetContext $context */
     if (!$context->hasResult()) {
         // no result
         return;
     }
     $data = $context->getResult();
     if (empty($data)) {
         // nothing to do because of empty result
         return;
     }
     $config = $context->getConfig();
     $context->setResult($this->objectNormalizer->normalizeObject($data, $config));
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function process(ContextInterface $context)
 {
     /** @var GetListContext $context */
     if (!$context->hasResult()) {
         // no result
         return;
     }
     $data = $context->getResult();
     if (empty($data)) {
         // nothing to do because of empty result
         return;
     }
     $config = $context->getConfig();
     $normalizedData = [];
     foreach ($data as $key => $value) {
         $normalizedData[$key] = $this->objectNormalizer->normalizeObject($value, $config);
     }
     $context->setResult($normalizedData);
 }
 public function testNormalizeEntityWithToManyRelations()
 {
     $result = $this->objectNormalizer->normalizeObject($this->createProductEntity()->getOwner());
     $this->assertEquals(['id' => 456, 'name' => 'user_name', 'category' => 'owner_category_name', 'groups' => [11, 22], 'products' => [123]], $result);
 }