mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
Docgen/action add missing goals
This commit is contained in:
@@ -24,6 +24,7 @@ use DateTimeInterface;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Annotation\Context;
|
||||
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
@@ -64,7 +65,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
||||
* @var string
|
||||
* @ORM\Column(name="acronym", type="string", length=64, nullable=true)
|
||||
* @Assert\Length(min="2")
|
||||
* @Groups({"read", "write", "docgen:read"})
|
||||
* @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
|
||||
*/
|
||||
private ?string $acronym = '';
|
||||
|
||||
@@ -79,7 +80,8 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
||||
* @ORM\ManyToOne(targetEntity="\Chill\MainBundle\Entity\Address",
|
||||
* cascade={"persist", "remove"})
|
||||
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
|
||||
* @Groups({"read", "write", "docgen:read"})
|
||||
* @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
|
||||
* @Context(normalizationContext={"groups": "docgen:read"}, groups={"docgen:read:3party:parent"})
|
||||
*/
|
||||
private ?Address $address = null;
|
||||
|
||||
@@ -98,7 +100,8 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
||||
* @ORM\JoinTable(name="chill_3party.thirdparty_category",
|
||||
* joinColumns={@ORM\JoinColumn(name="thirdparty_id", referencedColumnName="id")},
|
||||
* inverseJoinColumns={@ORM\JoinColumn(name="category_id", referencedColumnName="id")})
|
||||
* @Groups({"docgen:read"})
|
||||
* @Groups({"docgen:read", "docgen:read:3party:parent"})
|
||||
* @Context(normalizationContext={"groups": "docgen:read"}, groups={"docgen:read:3party:parent"})
|
||||
*/
|
||||
private Collection $categories;
|
||||
|
||||
@@ -123,7 +126,8 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
||||
* @var Civility
|
||||
* @ORM\ManyToOne(targetEntity=Civility::class)
|
||||
* ORM\JoinColumn(name="civility", referencedColumnName="id", nullable=true)
|
||||
* @Groups({"docgen:read", "read"})
|
||||
* @Groups({"docgen:read", "read", "docgen:read:3party:parent"})
|
||||
* @Context(normalizationContext={"groups": "docgen:read"}, groups={"docgen:read:3party:parent"})
|
||||
*/
|
||||
private ?Civility $civility = null;
|
||||
|
||||
@@ -135,7 +139,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="contact_data_anonymous", type="boolean", options={"default": false})
|
||||
* @Groups({"read", "docgen:read"})
|
||||
* @Groups({"read", "docgen:read", "docgen:read:3party:parent"})
|
||||
*/
|
||||
private bool $contactDataAnonymous = false;
|
||||
|
||||
@@ -153,7 +157,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
||||
/**
|
||||
* @ORM\Column(name="email", type="string", length=255, nullable=true)
|
||||
* @Assert\Email(checkMX=false)
|
||||
* @Groups({"read", "write", "docgen:read"})
|
||||
* @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
|
||||
*/
|
||||
private ?string $email = null;
|
||||
|
||||
@@ -162,7 +166,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
* @Groups({"read", "write", "docgen:read"})
|
||||
* @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
|
||||
*/
|
||||
private ?int $id = null;
|
||||
|
||||
@@ -176,7 +180,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
||||
* @var string
|
||||
* @ORM\Column(name="name", type="string", length=255)
|
||||
* @Assert\Length(min="2")
|
||||
* @Groups({"read", "write", "docgen:read"})
|
||||
* @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
|
||||
*/
|
||||
private ?string $name = '';
|
||||
|
||||
@@ -186,7 +190,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
||||
* @var string
|
||||
* @ORM\Column(name="name_company", type="string", length=255, nullable=true)
|
||||
* @Assert\Length(min="3")
|
||||
* @Groups({"read", "write", "docgen:read"})
|
||||
* @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
|
||||
*/
|
||||
private ?string $nameCompany = '';
|
||||
|
||||
@@ -196,6 +200,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
||||
* @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty", inversedBy="children")
|
||||
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
|
||||
* @Groups({"read", "docgen:read"})
|
||||
* @Context(normalizationContext={"groups": "docgen:read:3party:parent"}, groups={"docgen:read"})
|
||||
*/
|
||||
private ?ThirdParty $parent = null;
|
||||
|
||||
@@ -205,7 +210,8 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
||||
* @var ThirdPartyProfession
|
||||
* @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdPartyProfession")
|
||||
* ORM\JoinColumn(name="profession", referencedColumnName="id", nullable=true)
|
||||
* @Groups({"docgen:read"})
|
||||
* @Groups({"docgen:read", "docgen:read:3party:parent"})
|
||||
* @Context(normalizationContext={"groups": "docgen:read"}, groups={"docgen:read:3party:parent"})
|
||||
*/
|
||||
private ?ThirdPartyProfession $profession = null;
|
||||
|
||||
@@ -215,7 +221,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
||||
* message="Invalid phone number: it should begin with the international prefix starting with ""+"", hold only digits and be smaller than 20 characters. Ex: +33123456789"
|
||||
* )
|
||||
* @PhonenumberConstraint(type="any")
|
||||
* @Groups({"read", "write", "dogen:read"})
|
||||
* @Groups({"read", "write", "dogen:read", "docgen:read:3party:parent"})
|
||||
*/
|
||||
private ?string $telephone = null;
|
||||
|
||||
@@ -498,7 +504,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @Groups({"read", "docgen:read"})
|
||||
* @Groups({"read", "docgen:read", "docgen:read:3party:parent"})
|
||||
*/
|
||||
public function isChild(): bool
|
||||
{
|
||||
|
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\ThirdPartyBundle\Test\Serializer\Normalizer;
|
||||
|
||||
use Chill\MainBundle\Entity\Civility;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdPartyCategory;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class ThirdPartyDocGenNormalizerTest extends KernelTestCase
|
||||
{
|
||||
private NormalizerInterface $normalizer;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
$this->normalizer = self::$container->get(NormalizerInterface::class);
|
||||
}
|
||||
|
||||
public function testAvoidRecursionWithNullParent()
|
||||
{
|
||||
$thirdparty = new ThirdParty();
|
||||
$thirdparty
|
||||
->setAcronym('ABCD')
|
||||
->setName('test')
|
||||
->setCivility((new Civility())->setName(['fr' => 'Monsieur'])->setAbbreviation(['fr' => 'M.']))
|
||||
->setEmail('info@cl.coop')
|
||||
->addTypesAndCategories('kind')
|
||||
->addTypesAndCategories((new ThirdPartyCategory())->setName(['fr' => 'category']))
|
||||
->setParent(new ThirdParty());
|
||||
|
||||
$actual = $this->normalizer->normalize($thirdparty, 'docgen', ['groups' => ['docgen:read']]);
|
||||
|
||||
$this->assertIsArray($actual);
|
||||
$this->assertArrayHasKey('parent', $actual);
|
||||
$this->assertIsArray($actual['parent']);
|
||||
$this->assertArrayNotHasKey('parent', $actual['parent']);
|
||||
// check that other keys exists for parent
|
||||
$this->assertArrayHasKey('acronym', $actual['parent']);
|
||||
$this->assertEquals('', $actual['parent']['acronym']);
|
||||
|
||||
$thirdparty = new ThirdParty();
|
||||
$thirdparty
|
||||
->setAcronym('ABCD')
|
||||
->setName('test')
|
||||
->setCivility((new Civility())->setName(['fr' => 'Monsieur'])->setAbbreviation(['fr' => 'M.']))
|
||||
->setEmail('info@cl.coop')
|
||||
->addTypesAndCategories('kind')
|
||||
->addTypesAndCategories((new ThirdPartyCategory())->setName(['fr' => 'category']));
|
||||
|
||||
$actual = $this->normalizer->normalize($thirdparty, 'docgen', ['groups' => ['docgen:read']]);
|
||||
|
||||
$this->assertIsArray($actual);
|
||||
$this->assertArrayHasKey('parent', $actual);
|
||||
$this->assertIsArray($actual['parent']);
|
||||
$this->assertArrayNotHasKey('parent', $actual['parent']);
|
||||
// check that other keys exists for parent
|
||||
$this->assertArrayHasKey('acronym', $actual['parent']);
|
||||
$this->assertEquals('', $actual['parent']['acronym']);
|
||||
|
||||
$actual = $this->normalizer->normalize(null, 'docgen', ['groups' => ['docgen:read'], 'docgen:expects' => ThirdParty::class]);
|
||||
|
||||
$this->assertIsArray($actual);
|
||||
$this->assertArrayHasKey('parent', $actual);
|
||||
$this->assertIsArray($actual['parent']);
|
||||
$this->assertArrayNotHasKey('parent', $actual['parent']);
|
||||
// check that other keys exists for parent
|
||||
$this->assertArrayHasKey('acronym', $actual['parent']);
|
||||
$this->assertEquals('', $actual['parent']['acronym']);
|
||||
}
|
||||
|
||||
public function testNormalize()
|
||||
{
|
||||
$thirdparty = new ThirdParty();
|
||||
$thirdparty
|
||||
->setAcronym('ABCD')
|
||||
->setName('test')
|
||||
->setCivility((new Civility())->setName(['fr' => 'Monsieur'])->setAbbreviation(['fr' => 'M.']))
|
||||
->setEmail('info@cl.coop')
|
||||
->addTypesAndCategories('kind')
|
||||
->addTypesAndCategories((new ThirdPartyCategory())->setName(['fr' => 'category']));
|
||||
|
||||
$actual = $this->normalizer->normalize($thirdparty, 'docgen', ['groups' => ['docgen:read']]);
|
||||
|
||||
$this->assertIsArray($actual);
|
||||
}
|
||||
}
|
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\ThirdPartyBundle\Test\Serializer\Normalizer;
|
||||
|
||||
use Chill\MainBundle\Entity\Civility;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdPartyCategory;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class ThirdpartyDocGenNormalizerTest extends KernelTestCase
|
||||
{
|
||||
private NormalizerInterface $normalizer;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
$this->normalizer = self::$container->get(NormalizerInterface::class);
|
||||
}
|
||||
|
||||
public function testNormalize()
|
||||
{
|
||||
$thirdparty = new ThirdParty();
|
||||
$thirdparty
|
||||
->setAcronym('ABCD')
|
||||
->setName('test')
|
||||
->setCivility((new Civility())->setName(['fr' => 'Monsieur'])->setAbbreviation(['fr' => 'M.']))
|
||||
->setEmail('info@cl.coop')
|
||||
->addTypesAndCategories('kind')
|
||||
->addTypesAndCategories((new ThirdPartyCategory())->setName(['fr' => 'category']));
|
||||
|
||||
$actual = $this->normalizer->normalize($thirdparty, 'docgen', ['groups' => ['docgen:read']]);
|
||||
|
||||
$this->assertIsArray($actual);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user