mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Introduced new test files for workflow handlers and adjusted existing `getSuggestedUsers` methods to handle related entity checks and duplicates removal. Also, modified repos to align with test dependencies.
87 lines
3.0 KiB
PHP
87 lines
3.0 KiB
PHP
<?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\DocStoreBundle\Tests\Workflow;
|
|
|
|
use Chill\DocStoreBundle\Entity\AccompanyingCourseDocument;
|
|
use Chill\DocStoreBundle\Repository\AccompanyingCourseDocumentRepository;
|
|
use Chill\MainBundle\Entity\User;
|
|
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
|
|
use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository;
|
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Prophecy\PhpUnit\ProphecyTrait;
|
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
|
use Twig\Environment;
|
|
|
|
/**
|
|
* @internal
|
|
*
|
|
* @coversNothing
|
|
*/
|
|
class AccompanyingCourseDocumentWorkflowHandlerTest extends TestCase
|
|
{
|
|
use ProphecyTrait;
|
|
|
|
public function testGetSuggestedUsers()
|
|
{
|
|
$accompanyingPeriod = new AccompanyingPeriod();
|
|
$document = new AccompanyingCourseDocument();
|
|
$document->setCourse($accompanyingPeriod)->setUser($user1 = new User());
|
|
$accompanyingPeriod->setUser($user = new User());
|
|
$entityWorkflow = new EntityWorkflow();
|
|
$entityWorkflow->setRelatedEntityId(1);
|
|
|
|
$handler = new AccompanyingCourseDocumentWorkflowHandler(
|
|
$this->prophesize(TranslatorInterface::class)->reveal(),
|
|
$this->prophesize(EntityWorkflowRepository::class)->reveal(),
|
|
$this->buildRepository($document, 1),
|
|
new WorkflowWithPublicViewDocumentHelper($this->prophesize(Environment::class)->reveal()),
|
|
);
|
|
|
|
$users = $handler->getSuggestedUsers($entityWorkflow);
|
|
|
|
self::assertCount(2, $users);
|
|
self::assertContains($user, $users);
|
|
self::assertContains($user1, $users);
|
|
}
|
|
|
|
public function testGetSuggestedUsersWithDuplicates()
|
|
{
|
|
$accompanyingPeriod = new AccompanyingPeriod();
|
|
$document = new AccompanyingCourseDocument();
|
|
$document->setCourse($accompanyingPeriod)->setUser($user1 = new User());
|
|
$accompanyingPeriod->setUser($user1);
|
|
$entityWorkflow = new EntityWorkflow();
|
|
$entityWorkflow->setRelatedEntityId(1);
|
|
|
|
$handler = new AccompanyingCourseDocumentWorkflowHandler(
|
|
$this->prophesize(TranslatorInterface::class)->reveal(),
|
|
$this->prophesize(EntityWorkflowRepository::class)->reveal(),
|
|
$this->buildRepository($document, 1),
|
|
new WorkflowWithPublicViewDocumentHelper($this->prophesize(Environment::class)->reveal()),
|
|
);
|
|
|
|
$users = $handler->getSuggestedUsers($entityWorkflow);
|
|
|
|
self::assertCount(1, $users);
|
|
self::assertContains($user1, $users);
|
|
}
|
|
|
|
private function buildRepository(AccompanyingCourseDocument $document, int $id): AccompanyingCourseDocumentRepository
|
|
{
|
|
$repository = $this->prophesize(AccompanyingCourseDocumentRepository::class);
|
|
$repository->find($id)->willReturn($document);
|
|
|
|
return $repository->reveal();
|
|
}
|
|
}
|