mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
php cs fixes
This commit is contained in:
parent
1f4438690e
commit
f07ea3259e
@ -50,7 +50,7 @@ class LocationFilter implements FilterInterface
|
||||
{
|
||||
$builder->add('accepted_location', PickUserLocationType::class, [
|
||||
'multiple' => true,
|
||||
'label' => 'pick location'
|
||||
'label' => 'pick location',
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,18 @@
|
||||
<?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 Chill\AsideActivityBundle\Export\Export;
|
||||
|
||||
use Chill\AsideActivityBundle\Entity\AsideActivity;
|
||||
use Chill\AsideActivityBundle\Export\Declarations;
|
||||
use Chill\AsideActivityBundle\Form\AsideActivityCategoryType;
|
||||
use Chill\AsideActivityBundle\Repository\AsideActivityCategoryRepository;
|
||||
use Chill\AsideActivityBundle\Security\AsideActivityVoter;
|
||||
use Chill\AsideActivityBundle\Templating\Entity\CategoryRender;
|
||||
@ -16,32 +24,32 @@ use Chill\MainBundle\Export\Helper\UserHelper;
|
||||
use Chill\MainBundle\Export\ListInterface;
|
||||
use Chill\MainBundle\Repository\CenterRepositoryInterface;
|
||||
use Chill\MainBundle\Repository\ScopeRepositoryInterface;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Closure;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\ORM\AbstractQuery;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use LogicException;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
final class ListAsideActivity implements ListInterface, GroupedExportInterface
|
||||
{
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
private UserHelper $userHelper;
|
||||
|
||||
private DateTimeHelper $dateTimeHelper;
|
||||
|
||||
private ScopeRepositoryInterface $scopeRepository;
|
||||
|
||||
private CenterRepositoryInterface $centerRepository;
|
||||
|
||||
private AsideActivityCategoryRepository $asideActivityCategoryRepository;
|
||||
|
||||
private CategoryRender $categoryRender;
|
||||
|
||||
private CenterRepositoryInterface $centerRepository;
|
||||
|
||||
private DateTimeHelper $dateTimeHelper;
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
private ScopeRepositoryInterface $scopeRepository;
|
||||
|
||||
private TranslatableStringHelperInterface $translatableStringHelper;
|
||||
|
||||
private UserHelper $userHelper;
|
||||
|
||||
public function __construct(
|
||||
EntityManagerInterface $em,
|
||||
DateTimeHelper $dateTimeHelper,
|
||||
@ -76,11 +84,6 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface
|
||||
return 'export.aside_activity.List of aside activities';
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'export.aside_activity.List of aside activities';
|
||||
}
|
||||
|
||||
public function getGroup(): string
|
||||
{
|
||||
return 'export.Exports of aside activities';
|
||||
@ -91,15 +94,16 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface
|
||||
switch ($key) {
|
||||
case 'id':
|
||||
case 'note':
|
||||
return function ($value) use ($key) {
|
||||
return static function ($value) use ($key) {
|
||||
if ('_header' === $value) {
|
||||
return 'export.aside_activity.' . $key;
|
||||
}
|
||||
|
||||
return $value ?? '';
|
||||
};
|
||||
|
||||
case 'duration':
|
||||
return function ($value) use ($key) {
|
||||
return static function ($value) use ($key) {
|
||||
if ('_header' === $value) {
|
||||
return 'export.aside_activity.' . $key;
|
||||
}
|
||||
@ -108,7 +112,7 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($value instanceof \DateTimeInterface) {
|
||||
if ($value instanceof DateTimeInterface) {
|
||||
return $value->format('H:i:s');
|
||||
}
|
||||
|
||||
@ -118,7 +122,7 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface
|
||||
case 'createdAt':
|
||||
case 'updatedAt':
|
||||
case 'date':
|
||||
return $this->dateTimeHelper->getLabel('export.aside_activity.'.$key);
|
||||
return $this->dateTimeHelper->getLabel('export.aside_activity.' . $key);
|
||||
|
||||
case 'agent_id':
|
||||
case 'creator_id':
|
||||
@ -165,7 +169,7 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface
|
||||
};
|
||||
|
||||
default:
|
||||
throw new \LogicException('this key is not supported : ' . $key);
|
||||
throw new LogicException('this key is not supported : ' . $key);
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,7 +186,7 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface
|
||||
'aside_activity_type',
|
||||
'date',
|
||||
'duration',
|
||||
'note'
|
||||
'note',
|
||||
];
|
||||
}
|
||||
|
||||
@ -195,6 +199,11 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface
|
||||
return $query->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'export.aside_activity.List of aside activities';
|
||||
}
|
||||
|
||||
public function getType(): string
|
||||
{
|
||||
return Declarations::ASIDE_ACTIVITY_TYPE;
|
||||
@ -204,8 +213,7 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface
|
||||
{
|
||||
$qb = $this->em->createQueryBuilder()
|
||||
->from(AsideActivity::class, 'aside')
|
||||
->leftJoin('aside.agent', 'agent')
|
||||
;
|
||||
->leftJoin('aside.agent', 'agent');
|
||||
|
||||
$qb
|
||||
->addSelect('aside.id AS id')
|
||||
@ -218,8 +226,7 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface
|
||||
->addSelect('IDENTITY(aside.type) AS aside_activity_type')
|
||||
->addSelect('aside.date')
|
||||
->addSelect('aside.duration')
|
||||
->addSelect('aside.note')
|
||||
;
|
||||
->addSelect('aside.note');
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ use Chill\MainBundle\Form\Type\Export\FilterType;
|
||||
use Chill\MainBundle\Form\Type\PickRollingDateType;
|
||||
use Chill\MainBundle\Service\RollingDate\RollingDate;
|
||||
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
|
||||
use Doctrine\ORM\Query\Expr\Andx;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormError;
|
||||
|
@ -15,7 +15,6 @@ use Chill\AsideActivityBundle\Export\Declarations;
|
||||
use Chill\MainBundle\Export\FilterInterface;
|
||||
use Chill\MainBundle\Form\Type\PickUserDynamicType;
|
||||
use Chill\MainBundle\Templating\Entity\UserRender;
|
||||
use Doctrine\ORM\Query\Expr\Andx;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
|
@ -30,7 +30,7 @@ class ChargeKindType extends AbstractType
|
||||
])
|
||||
->add('kind', TextType::class, [
|
||||
'label' => 'budget.admin.form.Charge_kind_key',
|
||||
'help' => 'budget.admin.form.This kind must contains only alphabeticals characters, and dashes. This string is in use during document generation. Changes may have side effect on document'
|
||||
'help' => 'budget.admin.form.This kind must contains only alphabeticals characters, and dashes. This string is in use during document generation. Changes may have side effect on document',
|
||||
])
|
||||
->add('ordering', NumberType::class)
|
||||
->add('isActive', CheckboxType::class, [
|
||||
|
@ -30,7 +30,7 @@ class ResourceKindType extends AbstractType
|
||||
])
|
||||
->add('kind', TextType::class, [
|
||||
'label' => 'budget.admin.form.Resource_kind_key',
|
||||
'help' => 'budget.admin.form.This kind must contains only alphabeticals characters, and dashes. This string is in use during document generation. Changes may have side effect on document'
|
||||
'help' => 'budget.admin.form.This kind must contains only alphabeticals characters, and dashes. This string is in use during document generation. Changes may have side effect on document',
|
||||
])
|
||||
->add('ordering', NumberType::class)
|
||||
->add('isActive', CheckboxType::class, [
|
||||
|
@ -49,8 +49,7 @@ final class ChargeKindRepository implements ChargeKindRepositoryInterface
|
||||
->where($qb->expr()->eq('c.isActive', 'true'))
|
||||
->orderBy('c.ordering', 'ASC')
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,8 +28,6 @@ interface ChargeKindRepositoryInterface extends ObjectRepository
|
||||
*/
|
||||
public function findAllActive(): array;
|
||||
|
||||
public function findOneByKind(string $kind): ?ChargeKind;
|
||||
|
||||
/**
|
||||
* @return ChargeType[]
|
||||
*/
|
||||
@ -45,5 +43,7 @@ interface ChargeKindRepositoryInterface extends ObjectRepository
|
||||
|
||||
public function findOneBy(array $criteria): ?ChargeKind;
|
||||
|
||||
public function findOneByKind(string $kind): ?ChargeKind;
|
||||
|
||||
public function getClassName(): string;
|
||||
}
|
||||
|
@ -49,8 +49,7 @@ final class ResourceKindRepository implements ResourceKindRepositoryInterface
|
||||
->where($qb->expr()->eq('r.isActive', 'true'))
|
||||
->orderBy('r.ordering', 'ASC')
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,7 +34,7 @@ class ResourceRepository extends EntityRepository
|
||||
//->andWhere('c.startDate < :date')
|
||||
// TODO: there is a misconception here, the end date must be lower or null. startDate are never null
|
||||
//->andWhere('c.startDate < :date OR c.startDate IS NULL');
|
||||
;
|
||||
;
|
||||
|
||||
if (null !== $sort) {
|
||||
$qb->orderBy($sort);
|
||||
|
@ -13,9 +13,7 @@ namespace Chill\BudgetBundle\Service\Summary;
|
||||
|
||||
use Chill\BudgetBundle\Entity\ChargeKind;
|
||||
use Chill\BudgetBundle\Entity\ResourceKind;
|
||||
use Chill\BudgetBundle\Repository\ChargeKindRepository;
|
||||
use Chill\BudgetBundle\Repository\ChargeKindRepositoryInterface;
|
||||
use Chill\BudgetBundle\Repository\ResourceKindRepository;
|
||||
use Chill\BudgetBundle\Repository\ResourceKindRepositoryInterface;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
|
@ -20,12 +20,15 @@ use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\ORM\AbstractQuery;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Query;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use ReflectionClass;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@ -47,10 +50,9 @@ final class SummaryBudgetTest extends TestCase
|
||||
],
|
||||
]);
|
||||
$queryCharges->setParameters(Argument::type('array'))
|
||||
->will(function ($args, $query) {
|
||||
->will(static function ($args, $query) {
|
||||
return $query;
|
||||
})
|
||||
;
|
||||
});
|
||||
|
||||
$queryResources = $this->prophesize(AbstractQuery::class);
|
||||
$queryResources->getResult()->willReturn([
|
||||
@ -61,23 +63,23 @@ final class SummaryBudgetTest extends TestCase
|
||||
],
|
||||
]);
|
||||
$queryResources->setParameters(Argument::type('array'))
|
||||
->will(function ($args, $query) {
|
||||
->will(static function ($args, $query) {
|
||||
return $query;
|
||||
})
|
||||
;
|
||||
});
|
||||
|
||||
$em = $this->prophesize(EntityManagerInterface::class);
|
||||
$em->createNativeQuery(Argument::type('string'), Argument::type(Query\ResultSetMapping::class))
|
||||
->will(function ($args) use ($queryResources, $queryCharges) {
|
||||
->will(static function ($args) use ($queryResources, $queryCharges) {
|
||||
if (false !== strpos($args[0], 'chill_budget.resource')) {
|
||||
return $queryResources->reveal();
|
||||
}
|
||||
|
||||
if (false !== strpos($args[0], 'chill_budget.charge')) {
|
||||
return $queryCharges->reveal();
|
||||
}
|
||||
throw new \RuntimeException('this query does not have a stub counterpart: '.$args[0]);
|
||||
})
|
||||
;
|
||||
|
||||
throw new RuntimeException('this query does not have a stub counterpart: ' . $args[0]);
|
||||
});
|
||||
|
||||
$chargeRepository = $this->prophesize(ChargeKindRepositoryInterface::class);
|
||||
$chargeRepository->findAll()->willReturn([
|
||||
@ -98,24 +100,23 @@ final class SummaryBudgetTest extends TestCase
|
||||
$resourceRepository->findOneByKind('misc')->willReturn($misc);
|
||||
|
||||
$translatableStringHelper = $this->prophesize(TranslatableStringHelperInterface::class);
|
||||
$translatableStringHelper->localize(Argument::type('array'))->will(function ($arg) {
|
||||
$translatableStringHelper->localize(Argument::type('array'))->will(static function ($arg) {
|
||||
return $arg[0]['fr'];
|
||||
});
|
||||
|
||||
$person = new Person();
|
||||
$personReflection = new \ReflectionClass($person);
|
||||
$personReflection = new ReflectionClass($person);
|
||||
$personIdReflection = $personReflection->getProperty('id');
|
||||
$personIdReflection->setAccessible(true);
|
||||
$personIdReflection->setValue($person, 1);
|
||||
|
||||
$household = new Household();
|
||||
$householdReflection = new \ReflectionClass($household);
|
||||
$householdReflection = new ReflectionClass($household);
|
||||
$householdId = $householdReflection->getProperty('id');
|
||||
$householdId->setAccessible(true);
|
||||
$householdId->setValue($household, 1);
|
||||
$householdMember = (new HouseholdMember())->setPerson($person)
|
||||
->setStartDate(new \DateTimeImmutable('1 month ago'))
|
||||
;
|
||||
->setStartDate(new DateTimeImmutable('1 month ago'));
|
||||
$household->addMember($householdMember);
|
||||
|
||||
$summaryBudget = new SummaryBudget(
|
||||
|
@ -2,6 +2,13 @@
|
||||
|
||||
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 Chill\Migrations\Budget;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
@ -9,6 +16,12 @@ use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20230209161546 extends AbstractMigration
|
||||
{
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('DROP INDEX resource_kind_unique_type_idx');
|
||||
$this->addSql('DROP INDEX charge_kind_unique_type_idx');
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Budget: add unique constraint on kind for charge_kind and resource_kind';
|
||||
@ -21,10 +34,4 @@ final class Version20230209161546 extends AbstractMigration
|
||||
$this->addSql('CREATE UNIQUE INDEX resource_kind_unique_type_idx ON chill_budget.resource_type (kind);');
|
||||
$this->addSql('CREATE UNIQUE INDEX charge_kind_unique_type_idx ON chill_budget.charge_type (kind);');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('DROP INDEX resource_kind_unique_type_idx');
|
||||
$this->addSql('DROP INDEX charge_kind_unique_type_idx');
|
||||
}
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
use Throwable;
|
||||
use function strlen;
|
||||
use const JSON_PRETTY_PRINT;
|
||||
|
||||
final class DocGeneratorTemplateController extends AbstractController
|
||||
{
|
||||
@ -273,7 +274,7 @@ final class DocGeneratorTemplateController extends AbstractController
|
||||
|
||||
if ($isTest && isset($form) && $form['show_data']->getData()) {
|
||||
return $this->render('@ChillDocGenerator/Generator/debug_value.html.twig', [
|
||||
'datas' => json_encode($context->getData($template, $entity, $contextGenerationData), JSON_PRETTY_PRINT)
|
||||
'datas' => json_encode($context->getData($template, $entity, $contextGenerationData), JSON_PRETTY_PRINT),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,14 @@
|
||||
<?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 Chill\DocGeneratorBundle\Service\Generator;
|
||||
|
||||
use Chill\DocGeneratorBundle\Context\ContextManagerInterface;
|
||||
@ -9,8 +18,10 @@ use Chill\DocGeneratorBundle\GeneratorDriver\Exception\TemplateException;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\DocStoreBundle\Service\StoredObjectManagerInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Exception;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\File\File;
|
||||
use Throwable;
|
||||
|
||||
class Generator
|
||||
{
|
||||
@ -41,18 +52,20 @@ class Generator
|
||||
/**
|
||||
* @template T of File|null
|
||||
* @template B of bool
|
||||
*
|
||||
* @param B $isTest
|
||||
* @param (B is true ? T : null) $testFile
|
||||
* @psalm-return (B is true ? string : null)
|
||||
* @throws \Symfony\Component\Serializer\Exception\ExceptionInterface|\Throwable
|
||||
*
|
||||
* @throws \Symfony\Component\Serializer\Exception\ExceptionInterface|Throwable
|
||||
*/
|
||||
public function generateDocFromTemplate(
|
||||
DocGeneratorTemplate $template,
|
||||
string $entityClassName,
|
||||
int $entityId,
|
||||
?StoredObject $destinationStoredObject = null,
|
||||
bool $isTest = false,
|
||||
?File $testFile = null
|
||||
string $entityClassName,
|
||||
int $entityId,
|
||||
?StoredObject $destinationStoredObject = null,
|
||||
bool $isTest = false,
|
||||
?File $testFile = null
|
||||
): ?string {
|
||||
if ($destinationStoredObject instanceof StoredObject && StoredObject::STATUS_PENDING !== $destinationStoredObject->getStatus()) {
|
||||
throw new ObjectReadyException();
|
||||
@ -63,8 +76,7 @@ class Generator
|
||||
|
||||
$entity = $this
|
||||
->entityManager
|
||||
->find($context->getEntityClass(), $entityId)
|
||||
;
|
||||
->find($context->getEntityClass(), $entityId);
|
||||
|
||||
if (null === $entity) {
|
||||
throw new RelatedEntityNotFoundException($entityClassName, $entityId);
|
||||
@ -97,8 +109,7 @@ class Generator
|
||||
$destinationStoredObject
|
||||
->setType($template->getFile()->getType())
|
||||
->setFilename(sprintf('%s_odt', uniqid('doc_', true)))
|
||||
->setStatus(StoredObject::STATUS_READY)
|
||||
;
|
||||
->setStatus(StoredObject::STATUS_READY);
|
||||
|
||||
$this->storedObjectManager->write($destinationStoredObject, $generatedResource);
|
||||
|
||||
@ -110,7 +121,7 @@ class Generator
|
||||
$entity,
|
||||
$contextGenerationData
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
$this
|
||||
->logger
|
||||
->error(
|
||||
|
@ -1,18 +1,33 @@
|
||||
<?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 Chill\DocGeneratorBundle\Service\Generator;
|
||||
|
||||
class GeneratorException extends \RuntimeException
|
||||
use RuntimeException;
|
||||
use Throwable;
|
||||
|
||||
class GeneratorException extends RuntimeException
|
||||
{
|
||||
/**
|
||||
* @var list<string>
|
||||
*/
|
||||
private array $errors;
|
||||
|
||||
public function __construct(array $errors = [], \Throwable $previous = null)
|
||||
public function __construct(array $errors = [], ?Throwable $previous = null)
|
||||
{
|
||||
$this->errors = $errors;
|
||||
parent::__construct("Could not generate the document", 15252,
|
||||
$previous);
|
||||
parent::__construct(
|
||||
'Could not generate the document',
|
||||
15252,
|
||||
$previous
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,22 @@
|
||||
<?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 Chill\DocGeneratorBundle\Service\Generator;
|
||||
|
||||
class ObjectReadyException extends \RuntimeException
|
||||
use RuntimeException;
|
||||
|
||||
class ObjectReadyException extends RuntimeException
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct("object is already ready", 6698856);
|
||||
parent::__construct('object is already ready', 6698856);
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,26 @@
|
||||
<?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 Chill\DocGeneratorBundle\Service\Generator;
|
||||
|
||||
class RelatedEntityNotFoundException extends \RuntimeException
|
||||
use RuntimeException;
|
||||
|
||||
class RelatedEntityNotFoundException extends RuntimeException
|
||||
{
|
||||
public function __construct(string $relatedEntityClass, int $relatedEntityId, Throwable $previous = null)
|
||||
public function __construct(string $relatedEntityClass, int $relatedEntityId, ?Throwable $previous = null)
|
||||
{
|
||||
parent::__construct(
|
||||
sprintf("Related entity not found: %s, %s", $relatedEntityClass, $relatedEntityId),
|
||||
sprintf('Related entity not found: %s, %s', $relatedEntityClass, $relatedEntityId),
|
||||
99876652,
|
||||
$previous);
|
||||
$previous
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,14 @@
|
||||
<?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 Chill\DocGeneratorBundle\Service\Messenger;
|
||||
|
||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
@ -7,13 +16,13 @@ use Chill\MainBundle\Entity\User;
|
||||
|
||||
class RequestGenerationMessage
|
||||
{
|
||||
private int $creatorId;
|
||||
private int $creatorId;
|
||||
|
||||
private int $templateId;
|
||||
private string $entityClassName;
|
||||
|
||||
private int $entityId;
|
||||
private int $entityId;
|
||||
|
||||
private string $entityClassName;
|
||||
private int $templateId;
|
||||
|
||||
public function __construct(User $creator, DocGeneratorTemplate $template, int $entityId, string $entityClassName)
|
||||
{
|
||||
@ -28,9 +37,9 @@ class RequestGenerationMessage
|
||||
return $this->creatorId;
|
||||
}
|
||||
|
||||
public function getTemplateId(): int
|
||||
public function getEntityClassName(): string
|
||||
{
|
||||
return $this->templateId;
|
||||
return $this->entityClassName;
|
||||
}
|
||||
|
||||
public function getEntityId(): int
|
||||
@ -38,8 +47,8 @@ class RequestGenerationMessage
|
||||
return $this->entityId;
|
||||
}
|
||||
|
||||
public function getEntityClassName(): string
|
||||
public function getTemplateId(): int
|
||||
{
|
||||
return $this->entityClassName;
|
||||
return $this->templateId;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,14 @@
|
||||
<?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 Chill\DocGeneratorBundle\tests\Service\Context\Generator;
|
||||
|
||||
use Chill\DocGeneratorBundle\Context\ContextManagerInterface;
|
||||
@ -17,60 +26,14 @@ use Prophecy\Argument;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Psr\Log\NullLogger;
|
||||
|
||||
class GeneratorTest extends TestCase
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class GeneratorTest extends TestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
public function testSuccessfulGeneration(): void
|
||||
{
|
||||
$template = (new DocGeneratorTemplate())->setFile($templateStoredObject = (new StoredObject())
|
||||
->setType('application/test'));
|
||||
$destinationStoredObject = (new StoredObject())->setStatus(StoredObject::STATUS_PENDING);
|
||||
$entity = new class {};
|
||||
$data = [];
|
||||
|
||||
$context = $this->prophesize(DocGeneratorContextInterface::class);
|
||||
$context->getData($template, $entity, Argument::type('array'))->willReturn($data);
|
||||
$context->storeGenerated($template, $destinationStoredObject, $entity, Argument::type('array'))
|
||||
->shouldBeCalled();
|
||||
$context->getName()->willReturn('dummy_context');
|
||||
$context->getEntityClass()->willReturn('DummyClass');
|
||||
$context = $context->reveal();
|
||||
|
||||
$contextManagerInterface = $this->prophesize(ContextManagerInterface::class);
|
||||
$contextManagerInterface->getContextByDocGeneratorTemplate($template)
|
||||
->willReturn($context);
|
||||
|
||||
$driver = $this->prophesize(DriverInterface::class);
|
||||
$driver->generateFromString('template', 'application/test', $data, Argument::any())
|
||||
->willReturn('generated');
|
||||
|
||||
$entityManager = $this->prophesize(EntityManagerInterface::class);
|
||||
$entityManager->find(Argument::type('string'), Argument::type('int'))
|
||||
->willReturn($entity);
|
||||
$entityManager->flush()->shouldBeCalled();
|
||||
|
||||
$storedObjectManager = $this->prophesize(StoredObjectManagerInterface::class);
|
||||
$storedObjectManager->read($templateStoredObject)->willReturn('template');
|
||||
$storedObjectManager->write($destinationStoredObject, 'generated')->shouldBeCalled();
|
||||
|
||||
|
||||
$generator = new Generator(
|
||||
$contextManagerInterface->reveal(),
|
||||
$driver->reveal(),
|
||||
$entityManager->reveal(),
|
||||
new NullLogger(),
|
||||
$storedObjectManager->reveal()
|
||||
);
|
||||
|
||||
$generator->generateDocFromTemplate(
|
||||
$template,
|
||||
'DummyEntity',
|
||||
1,
|
||||
$destinationStoredObject
|
||||
);
|
||||
}
|
||||
|
||||
public function testPreventRegenerateDocument(): void
|
||||
{
|
||||
$this->expectException(ObjectReadyException::class);
|
||||
@ -131,4 +94,54 @@ class GeneratorTest extends TestCase
|
||||
$destinationStoredObject
|
||||
);
|
||||
}
|
||||
|
||||
public function testSuccessfulGeneration(): void
|
||||
{
|
||||
$template = (new DocGeneratorTemplate())->setFile($templateStoredObject = (new StoredObject())
|
||||
->setType('application/test'));
|
||||
$destinationStoredObject = (new StoredObject())->setStatus(StoredObject::STATUS_PENDING);
|
||||
$entity = new class() {
|
||||
};
|
||||
$data = [];
|
||||
|
||||
$context = $this->prophesize(DocGeneratorContextInterface::class);
|
||||
$context->getData($template, $entity, Argument::type('array'))->willReturn($data);
|
||||
$context->storeGenerated($template, $destinationStoredObject, $entity, Argument::type('array'))
|
||||
->shouldBeCalled();
|
||||
$context->getName()->willReturn('dummy_context');
|
||||
$context->getEntityClass()->willReturn('DummyClass');
|
||||
$context = $context->reveal();
|
||||
|
||||
$contextManagerInterface = $this->prophesize(ContextManagerInterface::class);
|
||||
$contextManagerInterface->getContextByDocGeneratorTemplate($template)
|
||||
->willReturn($context);
|
||||
|
||||
$driver = $this->prophesize(DriverInterface::class);
|
||||
$driver->generateFromString('template', 'application/test', $data, Argument::any())
|
||||
->willReturn('generated');
|
||||
|
||||
$entityManager = $this->prophesize(EntityManagerInterface::class);
|
||||
$entityManager->find(Argument::type('string'), Argument::type('int'))
|
||||
->willReturn($entity);
|
||||
$entityManager->flush()->shouldBeCalled();
|
||||
|
||||
$storedObjectManager = $this->prophesize(StoredObjectManagerInterface::class);
|
||||
$storedObjectManager->read($templateStoredObject)->willReturn('template');
|
||||
$storedObjectManager->write($destinationStoredObject, 'generated')->shouldBeCalled();
|
||||
|
||||
$generator = new Generator(
|
||||
$contextManagerInterface->reveal(),
|
||||
$driver->reveal(),
|
||||
$entityManager->reveal(),
|
||||
new NullLogger(),
|
||||
$storedObjectManager->reveal()
|
||||
);
|
||||
|
||||
$generator->generateDocFromTemplate(
|
||||
$template,
|
||||
'DummyEntity',
|
||||
1,
|
||||
$destinationStoredObject
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
|
||||
use Chill\MainBundle\Doctrine\Model\TrackCreationTrait;
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
@ -35,12 +36,14 @@ use Symfony\Component\Serializer\Annotation as Serializer;
|
||||
*/
|
||||
class StoredObject implements AsyncFileInterface, Document, TrackCreationInterface
|
||||
{
|
||||
public const STATUS_READY = "ready";
|
||||
public const STATUS_PENDING = "pending";
|
||||
public const STATUS_FAILURE = "failure";
|
||||
|
||||
use TrackCreationTrait;
|
||||
|
||||
public const STATUS_FAILURE = 'failure';
|
||||
|
||||
public const STATUS_PENDING = 'pending';
|
||||
|
||||
public const STATUS_READY = 'ready';
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime", name="creation_date")
|
||||
* @Serializer\Groups({"read", "write"})
|
||||
@ -80,6 +83,16 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa
|
||||
*/
|
||||
private array $keyInfos = [];
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text", options={"default": "ready"})
|
||||
*/
|
||||
private string $status;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=DocGeneratorTemplate::class)
|
||||
*/
|
||||
private ?DocGeneratorTemplate $template;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text", name="title")
|
||||
* @Serializer\Groups({"read", "write"})
|
||||
@ -98,20 +111,10 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa
|
||||
*/
|
||||
private UuidInterface $uuid;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=DocGeneratorTemplate::class)
|
||||
*/
|
||||
private ?DocGeneratorTemplate $template;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text", options={"default": "ready"})
|
||||
*/
|
||||
private string $status;
|
||||
|
||||
/**
|
||||
* @param StoredObject::STATUS_* $status
|
||||
*/
|
||||
public function __construct(string $status = "ready")
|
||||
public function __construct(string $status = 'ready')
|
||||
{
|
||||
$this->uuid = Uuid::uuid4();
|
||||
$this->status = $status;
|
||||
@ -188,7 +191,7 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa
|
||||
*/
|
||||
public function setCreationDate(DateTime $creationDate): self
|
||||
{
|
||||
$this->createdAt = \DateTimeImmutable::createFromMutable($creationDate);
|
||||
$this->createdAt = DateTimeImmutable::createFromMutable($creationDate);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Export;
|
||||
|
||||
use Closure;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
|
||||
/**
|
||||
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace Chill\MainBundle\Export\Helper;
|
||||
|
||||
use DateTime;
|
||||
use DateTimeInterface;
|
||||
use Exception;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
@ -35,7 +36,7 @@ class DateTimeHelper
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($value instanceof \DateTimeInterface) {
|
||||
if ($value instanceof DateTimeInterface) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Entity\UserJob;
|
||||
use Chill\MainBundle\Export\FilterInterface;
|
||||
use Chill\MainBundle\Form\Type\PickRollingDateType;
|
||||
|
@ -24,10 +24,36 @@ use Prophecy\Argument;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
|
||||
|
||||
class ParticipationOverlapValidatorTest extends ConstraintValidatorTestCase
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class ParticipationOverlapValidatorTest extends ConstraintValidatorTestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getConstraint()
|
||||
{
|
||||
return new ParticipationOverlap();
|
||||
}
|
||||
|
||||
public function testOneParticipation()
|
||||
{
|
||||
$period = new AccompanyingPeriod();
|
||||
$person = new Person();
|
||||
|
||||
$collection = new ArrayCollection([
|
||||
new AccompanyingPeriodParticipation($period, $person),
|
||||
]);
|
||||
|
||||
$this->validator->validate($collection, $this->getConstraint());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
protected function createValidator()
|
||||
{
|
||||
$personRender = $this->prophesize(PersonRenderInterface::class);
|
||||
@ -37,26 +63,4 @@ class ParticipationOverlapValidatorTest extends ConstraintValidatorTestCase
|
||||
|
||||
return new ParticipationOverlapValidator($personRender->reveal(), $thirdPartyRender->reveal());
|
||||
}
|
||||
|
||||
public function testOneParticipation()
|
||||
{
|
||||
$period = new AccompanyingPeriod();
|
||||
$person = new Person();
|
||||
|
||||
$collection = new ArrayCollection([
|
||||
new AccompanyingPeriodParticipation($period, $person)
|
||||
]);
|
||||
|
||||
$this->validator->validate($collection, $this->getConstraint());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getConstraint()
|
||||
{
|
||||
return new ParticipationOverlap();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user