mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-02 13:03:50 +00:00
Add and update test handlers for suggested users retrieval
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.
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
<?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\PersonBundle\Tests\Workflow;
|
||||
|
||||
use Chill\DocStoreBundle\Workflow\WorkflowWithPublicViewDocumentHelper;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
|
||||
use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocumentRepository;
|
||||
use Chill\PersonBundle\Workflow\AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Twig\Environment;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
class AccompanyingPeriodWorkEvaluationDocumentWorkflowHandlerTest extends TestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
public function testGetSuggestedUsers()
|
||||
{
|
||||
$accompanyingCourse = new AccompanyingPeriod();
|
||||
$accompanyingCourse->setUser($referrer = new User());
|
||||
$accompanyingCourse->addWork($work = new AccompanyingPeriod\AccompanyingPeriodWork());
|
||||
$work->addReferrer($workReferrer1 = new User());
|
||||
$work->addReferrer($workReferrer2 = new User());
|
||||
$work->addReferrer($referrer);
|
||||
$work->addAccompanyingPeriodWorkEvaluation($eval = new AccompanyingPeriod\AccompanyingPeriodWorkEvaluation());
|
||||
$eval->addDocument($doc = new AccompanyingPeriodWorkEvaluationDocument());
|
||||
$entityWorkflow = new EntityWorkflow();
|
||||
|
||||
// Prophesize each dependency
|
||||
$workflowRepositoryProphecy = $this->prophesize(EntityWorkflowRepository::class);
|
||||
$translatableStringHelperProphecy = $this->prophesize(TranslatableStringHelperInterface::class);
|
||||
$translatorProphecy = $this->prophesize(TranslatorInterface::class);
|
||||
$twig = $this->prophesize(Environment::class);
|
||||
|
||||
// Create an instance of the class under test using revealed prophecies directly
|
||||
$handler = new AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler(
|
||||
$this->buildRepository($doc, 1),
|
||||
$workflowRepositoryProphecy->reveal(),
|
||||
$translatableStringHelperProphecy->reveal(),
|
||||
$translatorProphecy->reveal(),
|
||||
new WorkflowWithPublicViewDocumentHelper($twig->reveal()),
|
||||
);
|
||||
|
||||
$entityWorkflow->setRelatedEntityId(1);
|
||||
$entityWorkflow->setRelatedEntityClass(AccompanyingPeriodWorkEvaluationDocument::class);
|
||||
|
||||
$users = $handler->getSuggestedUsers($entityWorkflow);
|
||||
|
||||
self::assertContains($referrer, $users);
|
||||
self::assertContains($workReferrer1, $users);
|
||||
self::assertContains($workReferrer2, $users);
|
||||
}
|
||||
|
||||
private function buildRepository(AccompanyingPeriodWorkEvaluationDocument $document, int $id): AccompanyingPeriodWorkEvaluationDocumentRepository
|
||||
{
|
||||
$repository = $this->prophesize(AccompanyingPeriodWorkEvaluationDocumentRepository::class);
|
||||
|
||||
$repository->find($id)->willReturn($document);
|
||||
|
||||
return $repository->reveal();
|
||||
}
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
<?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\PersonBundle\Tests\Workflow;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
|
||||
use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationRepository;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
class AccompanyingPeriodWorkEvaluationWorkflowHandlerTest extends TestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
public function testGetSuggestedUsers()
|
||||
{
|
||||
$accompanyingCourse = new AccompanyingPeriod();
|
||||
$accompanyingCourse->setUser($referrer = new User());
|
||||
$accompanyingCourse->addWork($work = new AccompanyingPeriod\AccompanyingPeriodWork());
|
||||
$work->addReferrer($workReferrer1 = new User());
|
||||
$work->addReferrer($workReferrer2 = new User());
|
||||
$work->addReferrer($referrer);
|
||||
$work->addAccompanyingPeriodWorkEvaluation($eval = new AccompanyingPeriod\AccompanyingPeriodWorkEvaluation());
|
||||
$entityWorkflow = new EntityWorkflow();
|
||||
$entityWorkflow->setRelatedEntityId(1);
|
||||
|
||||
// Prophesize each dependency
|
||||
$workflowRepositoryProphecy = $this->prophesize(EntityWorkflowRepository::class);
|
||||
$translatableStringHelperProphecy = $this->prophesize(TranslatableStringHelperInterface::class);
|
||||
$translatorProphecy = $this->prophesize(TranslatorInterface::class);
|
||||
|
||||
// Create an instance of the class under test using revealed prophecies directly
|
||||
$handler = new AccompanyingPeriodWorkEvaluationWorkflowHandler(
|
||||
$this->buildRepository($eval, 1),
|
||||
$workflowRepositoryProphecy->reveal(),
|
||||
$translatableStringHelperProphecy->reveal(),
|
||||
$translatorProphecy->reveal(),
|
||||
);
|
||||
|
||||
$users = $handler->getSuggestedUsers($entityWorkflow);
|
||||
|
||||
self::assertContains($referrer, $users);
|
||||
self::assertContains($workReferrer1, $users);
|
||||
self::assertContains($workReferrer2, $users);
|
||||
}
|
||||
|
||||
private function buildRepository(AccompanyingPeriod\AccompanyingPeriodWorkEvaluation $evaluation, int $id): AccompanyingPeriodWorkEvaluationRepository
|
||||
{
|
||||
$evaluationRepositoryProphecy = $this->prophesize(AccompanyingPeriodWorkEvaluationRepository::class);
|
||||
$evaluationRepositoryProphecy->find($id)->willReturn($evaluation);
|
||||
|
||||
return $evaluationRepositoryProphecy->reveal();
|
||||
}
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
<?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\PersonBundle\Tests\Workflow;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
|
||||
use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
class AccompanyingPeriodWorkWorkflowHandlerTest extends TestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
public function testGetSuggestedUsers()
|
||||
{
|
||||
$accompanyingCourse = new AccompanyingPeriod();
|
||||
$accompanyingCourse->setUser($referrer = new User());
|
||||
$accompanyingCourse->addWork($work = new AccompanyingPeriod\AccompanyingPeriodWork());
|
||||
$work->addReferrer($workReferrer1 = new User());
|
||||
$work->addReferrer($workReferrer2 = new User());
|
||||
$work->addReferrer($referrer);
|
||||
$entityWorkflow = new EntityWorkflow();
|
||||
$entityWorkflow->setRelatedEntityId(1);
|
||||
|
||||
// Prophesize each dependency
|
||||
$workflowRepositoryProphecy = $this->prophesize(EntityWorkflowRepository::class);
|
||||
$translatableStringHelperProphecy = $this->prophesize(TranslatableStringHelperInterface::class);
|
||||
$translatorProphecy = $this->prophesize(TranslatorInterface::class);
|
||||
|
||||
// Create an instance of the class under test using revealed prophecies directly
|
||||
$handler = new AccompanyingPeriodWorkWorkflowHandler(
|
||||
$this->buildRepository($work, 1),
|
||||
$workflowRepositoryProphecy->reveal(),
|
||||
$translatableStringHelperProphecy->reveal(),
|
||||
$translatorProphecy->reveal(),
|
||||
);
|
||||
|
||||
$users = $handler->getSuggestedUsers($entityWorkflow);
|
||||
|
||||
self::assertContains($referrer, $users);
|
||||
self::assertContains($workReferrer1, $users);
|
||||
self::assertContains($workReferrer2, $users);
|
||||
}
|
||||
|
||||
private function buildRepository(AccompanyingPeriod\AccompanyingPeriodWork $work, int $int): AccompanyingPeriodWorkRepository
|
||||
{
|
||||
$accompanyingPeriodWorkRepositoryProphecy = $this->prophesize(AccompanyingPeriodWorkRepository::class);
|
||||
$accompanyingPeriodWorkRepositoryProphecy
|
||||
->find($int)
|
||||
->willReturn($work);
|
||||
|
||||
return $accompanyingPeriodWorkRepositoryProphecy->reveal();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user