Feature: [docgen][person] add a new context to generate document with a

third party

This allow to prepare, for instance, mail (letters) to a thirdparty
about a Person
This commit is contained in:
2022-10-19 14:16:59 +02:00
parent 1b5d5a28fd
commit ea5f8c9d08
6 changed files with 291 additions and 1 deletions

View File

@@ -0,0 +1,93 @@
<?php
declare(strict_types=1);
/*
* 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.
*/
namespace Service\DocGenerator;
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Service\DocGenerator\PersonContextInterface;
use Chill\PersonBundle\Service\DocGenerator\PersonContextWithThirdParty;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* @internal
* @coversNothing
*/
final class PersonContextWithThirdPartyTest extends KernelTestCase
{
use ProphecyTrait;
public function testAdminFormReverseTransform()
{
$personContext = $this->buildPersonContextWithThirdParty();
$actual = $personContext->adminFormReverseTransform(['label' => 'bloup']);
$this->assertArrayHasKey('category', $actual);
$this->assertArrayHasKey('label', $actual);
$this->assertEquals('bloup', $actual['label']);
}
public function testAdminFormTransform()
{
$personContext = $this->buildPersonContextWithThirdParty();
$actual = $personContext->adminFormTransform(['label' => 'bloup']);
$this->assertArrayHasKey('from_person', $actual);
$this->assertArrayHasKey('label', $actual);
$this->assertEquals('bloup', $actual['label']);
}
public function testGetData()
{
$personContext = $this->buildPersonContextWithThirdParty();
$actual = $personContext->getData(
(new DocGeneratorTemplate())->setOptions(['label' => 'bloup']),
new Person(),
['thirdParty' => $tp = new ThirdParty()]
);
$this->assertArrayHasKey('person', $actual);
$this->assertArrayHasKey('thirdParty', $actual);
$this->assertEquals(spl_object_hash($tp), $actual['thirdParty']['hash']);
}
private function buildPersonContextWithThirdParty(): PersonContextWithThirdParty
{
$normalizer = $this->prophesize(NormalizerInterface::class);
$normalizer->normalize(Argument::type(ThirdParty::class), 'docgen', Argument::type('array'))
->will(static function ($args): array {
return ['class' => '3party', 'hash' => spl_object_hash($args[0])];
});
$personContext = $this->prophesize(PersonContextInterface::class);
$personContext->adminFormReverseTransform(Argument::type('array'))->willReturn(
['category' => ['idInsideBundle' => 1, 'bundleId' => 'abc']]
);
$personContext->adminFormTransform(Argument::type('array'))->willReturn(
['from_person' => 'kept']
);
$personContext->getData(Argument::type(DocGeneratorTemplate::class), Argument::type(Person::class), Argument::type('array'))
->willReturn(['person' => 'data']);
return new PersonContextWithThirdParty(
$personContext->reveal(),
$normalizer->reveal()
);
}
}