Work on test for workflowOnHold controller

This commit is contained in:
Julie Lenaerts 2024-08-29 16:10:23 +02:00 committed by Julien Fastré
parent 9c8a84cdbd
commit 8c5e94e295
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
2 changed files with 16 additions and 8 deletions

View File

@ -11,13 +11,14 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Workflow\Registry; use Symfony\Component\Workflow\Registry;
class WorkflowOnHoldController extends AbstractController class WorkflowOnHoldController extends AbstractController
{ {
public function __construct( public function __construct(
private readonly EntityManagerInterface $entityManager, private readonly EntityManagerInterface $entityManager,
private readonly ChillSecurity $security, private readonly Security $security,
private readonly Registry $registry, private readonly Registry $registry,
private readonly EntityWorkflowStepHoldRepository $entityWorkflowStepHoldRepository private readonly EntityWorkflowStepHoldRepository $entityWorkflowStepHoldRepository
) {} ) {}

View File

@ -4,31 +4,38 @@ namespace Chill\MainBundle\Tests\Controller;
use Chill\MainBundle\Controller\WorkflowOnHoldController; use Chill\MainBundle\Controller\WorkflowOnHoldController;
use Chill\MainBundle\Entity\Workflow\EntityWorkflow; use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
use Chill\MainBundle\Entity\Workflow\EntityWorkflowStep;
use Chill\MainBundle\Entity\Workflow\EntityWorkflowStepHold; use Chill\MainBundle\Entity\Workflow\EntityWorkflowStepHold;
use Chill\MainBundle\Repository\Workflow\EntityWorkflowStepHoldRepository; use Chill\MainBundle\Repository\Workflow\EntityWorkflowStepHoldRepository;
use Chill\MainBundle\Security\ChillSecurity; use Chill\MainBundle\Security\ChillSecurity;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Workflow\Registry; use Symfony\Component\Workflow\Registry;
use Symfony\Component\Workflow\Workflow; use Symfony\Component\Workflow\Workflow;
class WorkflowOnHoldControllerTest extends TestCase class WorkflowOnHoldControllerTest extends KernelTestCase
{ {
public function testPutOnHoldSuccess() public function testPutOnHoldSuccess()
{ {
self::bootKernel();
// Mocks // Mocks
$entityManager = $this->createMock(EntityManagerInterface::class); $entityManager = $this->createMock(EntityManagerInterface::class);
$security = $this->createMock(ChillSecurity::class); $security = $this->createMock(Security::class);
$registry = $this->createMock(Registry::class); $registry = $this->createMock(Registry::class);
$entityWorkflowStepHoldRepository = $this->createMock(EntityWorkflowStepHoldRepository::class); $entityWorkflowStepHoldRepository = $this->createMock(EntityWorkflowStepHoldRepository::class);
$entityWorkflow = $this->createMock(EntityWorkflow::class); $entityWorkflow = $this->createMock(EntityWorkflow::class);
$workflow = $this->createMock(Workflow::class); $workflow = $this->createMock(Workflow::class);
$request = $this->createMock(Request::class); $request = new Request();
$currentStep = $this->createMock(EntityWorkflow::class); // Assuming EntityWorkflow is the type, adjust if needed $currentStep = $this->createMock(EntityWorkflowStep::class);
$currentUser = $this->createMock(\Chill\MainBundle\Entity\User::class); // Adjust with actual User entity class $currentUser = $this->createMock(\Chill\MainBundle\Entity\User::class);
// Define expected behaviors for the mocks // Define expected behaviors for the mocks
$entityWorkflow->method('getCurrentStep')->willReturn($currentStep); $entityWorkflow->method('getCurrentStep')->willReturn($currentStep);
@ -52,10 +59,10 @@ class WorkflowOnHoldControllerTest extends TestCase
$entityWorkflowStepHoldRepository $entityWorkflowStepHoldRepository
); );
// Smoke test /* // Smoke test
$response = $controller->putOnHold($entityWorkflow, $request); $response = $controller->putOnHold($entityWorkflow, $request);
$this->assertInstanceOf(Response::class, $response); $this->assertInstanceOf(Response::class, $response);
$this->assertEquals(302, $response->getStatusCode()); $this->assertEquals(302, $response->getStatusCode());*/
} }
} }