Skip to content

Commit

Permalink
Add test with Mongo
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentchalamon committed Jun 25, 2020
1 parent 57501f8 commit 0298271
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/Bridge/Symfony/Messenger/DataPersister.php
Expand Up @@ -101,6 +101,9 @@ public function loop($data, array $context = []): bool
return 'persist' === $value || (\is_array($value) && \in_array('persist', $value, true));
}

/**
* @return bool|string|array|null
*/
private function getMessengerAttributeValue(ResourceMetadata $resourceMetadata, array $context = [])
{
if (null !== $operationName = $context['collection_operation_name'] ?? $context['item_operation_name'] ?? null) {
Expand Down
Expand Up @@ -15,8 +15,9 @@

use ApiPlatform\Core\DataTransformer\DataTransformerInterface;
use ApiPlatform\Core\Serializer\AbstractItemNormalizer;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\MessengerWithArray as MessengerWithArrayDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Dto\MessengerInput;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\MessengerWithArray;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\MessengerWithArray as MessengerWithArrayEntity;

final class MessengerWithArrayDtoDataTransformer implements DataTransformerInterface
{
Expand All @@ -39,6 +40,6 @@ public function transform($object, string $to, array $context = [])
*/
public function supportsTransformation($object, string $to, array $context = []): bool
{
return MessengerWithArray::class === $to && null !== ($context['input']['class'] ?? null);
return \in_array($to, [MessengerWithArrayEntity::class, MessengerWithArrayDocument::class], true) && null !== ($context['input']['class'] ?? null);
}
}
42 changes: 42 additions & 0 deletions tests/Fixtures/TestBundle/Document/MessengerWithArray.php
@@ -0,0 +1,42 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Core\Tests\Fixtures\TestBundle\Document;

use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Dto\MessengerInput;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/**
* @ApiResource(messenger={"persist", "input"}, input=MessengerInput::class)
* @ODM\Document
*/
class MessengerWithArray
{
/**
* @var int|null
*
* @ApiProperty(identifier=true)
*
* @ODM\Id(strategy="INCREMENT", type="integer")
*/
public $id;

/**
* @var string|null
*
* @ODM\Field
*/
public $name;
}
41 changes: 41 additions & 0 deletions tests/Fixtures/TestBundle/Document/MessengerWithPersist.php
@@ -0,0 +1,41 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Core\Tests\Fixtures\TestBundle\Document;

use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/**
* @ApiResource(messenger="persist")
* @ODM\Document
*/
class MessengerWithPersist
{
/**
* @var int|null
*
* @ApiProperty(identifier=true)
*
* @ODM\Id(strategy="INCREMENT", type="integer")
*/
public $id;

/**
* @var string|null
*
* @ODM\Field
*/
public $name;
}

0 comments on commit 0298271

Please sign in to comment.