mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-02 14:07:43 +00:00
[Ticket] add filter by addressee on ticket list api
This commit is contained in:
parent
c8baf0a8aa
commit
445a2c9358
@ -135,6 +135,25 @@ paths:
|
|||||||
**Warning**: This silently remove the filters "byCurrentState" and "byCreatedBefore".
|
**Warning**: This silently remove the filters "byCurrentState" and "byCreatedBefore".
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
|
- name: byAddressee
|
||||||
|
in: query
|
||||||
|
description: the id of the addressee to search for. The search is also performed against user groups.
|
||||||
|
required: false
|
||||||
|
style: form
|
||||||
|
explode: false
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: integer
|
||||||
|
format: integer
|
||||||
|
minimum: 1
|
||||||
|
- name: byAddresseeToMe
|
||||||
|
in: query
|
||||||
|
description: filter tickets assigned to the current authenticated users
|
||||||
|
required: false
|
||||||
|
allowEmptyValue: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: OK
|
description: OK
|
||||||
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
|||||||
namespace Chill\TicketBundle\Controller;
|
namespace Chill\TicketBundle\Controller;
|
||||||
|
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||||
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
use Chill\MainBundle\Serializer\Model\Collection;
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
use Chill\PersonBundle\Repository\PersonRepository;
|
use Chill\PersonBundle\Repository\PersonRepository;
|
||||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||||
@ -42,6 +43,7 @@ final readonly class TicketListApiController
|
|||||||
private MotiveRepository $motiveRepository,
|
private MotiveRepository $motiveRepository,
|
||||||
private ClockInterface $clock,
|
private ClockInterface $clock,
|
||||||
ParameterBagInterface $parameterBag,
|
ParameterBagInterface $parameterBag,
|
||||||
|
private UserRepositoryInterface $userRepository,
|
||||||
) {
|
) {
|
||||||
$this->expectedTimeResponseDelay = new \DateInterval($parameterBag->get('chill_ticket')['ticket']['response_time_exceeded_delay']);
|
$this->expectedTimeResponseDelay = new \DateInterval($parameterBag->get('chill_ticket')['ticket']['response_time_exceeded_delay']);
|
||||||
}
|
}
|
||||||
@ -56,8 +58,8 @@ final readonly class TicketListApiController
|
|||||||
$params = [];
|
$params = [];
|
||||||
|
|
||||||
if ($request->query->has('byPerson')) {
|
if ($request->query->has('byPerson')) {
|
||||||
$params = explode(',', $request->query->get('byPerson'));
|
$personIds = explode(',', $request->query->get('byPerson'));
|
||||||
foreach ($params as $id) {
|
foreach ($personIds as $id) {
|
||||||
$params['byPerson'][] = $person = $this->personRepository->find($id);
|
$params['byPerson'][] = $person = $this->personRepository->find($id);
|
||||||
|
|
||||||
if (!$this->security->isGranted(PersonVoter::SEE, $person)) {
|
if (!$this->security->isGranted(PersonVoter::SEE, $person)) {
|
||||||
@ -89,8 +91,8 @@ final readonly class TicketListApiController
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($request->query->has('byMotives')) {
|
if ($request->query->has('byMotives')) {
|
||||||
$params = explode(',', $request->query->get('byMotives'));
|
$motivesIds = explode(',', $request->query->get('byMotives'));
|
||||||
foreach ($params as $id) {
|
foreach ($motivesIds as $id) {
|
||||||
if (!is_numeric($id) || 0 === ((int) $id)) {
|
if (!is_numeric($id) || 0 === ((int) $id)) {
|
||||||
throw new BadRequestHttpException('Only numbers are allowed in by motives parameter');
|
throw new BadRequestHttpException('Only numbers are allowed in by motives parameter');
|
||||||
}
|
}
|
||||||
@ -132,6 +134,24 @@ final readonly class TicketListApiController
|
|||||||
unset($params['byCreatedAfter']);
|
unset($params['byCreatedAfter']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($request->query->has('byAddresseeToMe')) {
|
||||||
|
$params['byAddressee'][] = $this->security->getUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->query->has('byAddressee')) {
|
||||||
|
$userIds = explode(',', $request->query->get('byAddressee'));
|
||||||
|
foreach ($userIds as $id) {
|
||||||
|
if (!is_numeric($id) || 0 === ((int) $id)) {
|
||||||
|
throw new BadRequestHttpException('Only numbers are allowed in by addressee parameter');
|
||||||
|
}
|
||||||
|
|
||||||
|
$params['byAddressee'][] = $user = $this->userRepository->find($id);
|
||||||
|
if (null === $user) {
|
||||||
|
throw new BadRequestHttpException('User not found');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$nb = $this->ticketRepository->countTickets($params);
|
$nb = $this->ticketRepository->countTickets($params);
|
||||||
$paginator = $this->paginatorFactory->create($nb);
|
$paginator = $this->paginatorFactory->create($nb);
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\TicketBundle\Repository;
|
namespace Chill\TicketBundle\Repository;
|
||||||
|
|
||||||
|
use Chill\TicketBundle\Entity\AddresseeHistory;
|
||||||
use Chill\TicketBundle\Entity\EmergencyStatusHistory;
|
use Chill\TicketBundle\Entity\EmergencyStatusHistory;
|
||||||
use Chill\TicketBundle\Entity\MotiveHistory;
|
use Chill\TicketBundle\Entity\MotiveHistory;
|
||||||
use Chill\TicketBundle\Entity\PersonHistory;
|
use Chill\TicketBundle\Entity\PersonHistory;
|
||||||
@ -131,6 +132,40 @@ final readonly class TicketACLAwareRepository implements TicketACLAwareRepositor
|
|||||||
$qb->setParameter('opening_after', $params['byCreatedBefore']);
|
$qb->setParameter('opening_after', $params['byCreatedBefore']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (array_key_exists('byAddressee', $params)) {
|
||||||
|
$orx = $qb->expr()->orX();
|
||||||
|
foreach ($params['byAddressee'] as $addressee) {
|
||||||
|
$orx->add(
|
||||||
|
$qb->expr()->exists(sprintf(
|
||||||
|
'SELECT 1 FROM %s tp_addressee_%d WHERE tp_addressee_%d.ticket = t
|
||||||
|
AND tp_addressee_%d.endDate IS NULL AND tp_addressee_%d.addresseeUser = :addressee_%d',
|
||||||
|
AddresseeHistory::class,
|
||||||
|
++$i,
|
||||||
|
$i,
|
||||||
|
$i,
|
||||||
|
$i,
|
||||||
|
$addresseeParam = $i,
|
||||||
|
))
|
||||||
|
);
|
||||||
|
$orx->add(
|
||||||
|
$qb->expr()->exists(sprintf(
|
||||||
|
'SELECT 1 FROM %s tp_addressee_%d JOIN tp_addressee_%d.addresseeGroup group_%d WHERE tp_addressee_%d.ticket = t
|
||||||
|
AND tp_addressee_%d.endDate IS NULL AND :addressee_%d MEMBER OF group_%d.users',
|
||||||
|
AddresseeHistory::class,
|
||||||
|
++$i,
|
||||||
|
$i,
|
||||||
|
$i,
|
||||||
|
$i,
|
||||||
|
$i,
|
||||||
|
$addresseeParam,
|
||||||
|
$i,
|
||||||
|
))
|
||||||
|
);
|
||||||
|
$qb->setParameter(sprintf('addressee_%d', $addresseeParam), $addressee);
|
||||||
|
}
|
||||||
|
$qb->andWhere($orx);
|
||||||
|
}
|
||||||
|
|
||||||
return $qb;
|
return $qb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\TicketBundle\Repository;
|
namespace Chill\TicketBundle\Repository;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\TicketBundle\Entity\EmergencyStatusEnum;
|
use Chill\TicketBundle\Entity\EmergencyStatusEnum;
|
||||||
use Chill\TicketBundle\Entity\Motive;
|
use Chill\TicketBundle\Entity\Motive;
|
||||||
@ -20,7 +21,7 @@ use Chill\TicketBundle\Entity\Ticket;
|
|||||||
/**
|
/**
|
||||||
* Repository to find tickets, taking care of permissions.
|
* Repository to find tickets, taking care of permissions.
|
||||||
*
|
*
|
||||||
* @phpstan-type TicketACLAwareRepositoryParam array{byPerson?: list<Person>, byCurrentState?: list<StateEnum>, byCurrentStateEmergency?: list<EmergencyStatusEnum>, byMotives?: list<Motive>, byCreatedBefore?: \DateTimeImmutable, byCreatedAfter?: \DateTimeImmutable}
|
* @phpstan-type TicketACLAwareRepositoryParam array{byPerson?: list<Person>, byCurrentState?: list<StateEnum>, byCurrentStateEmergency?: list<EmergencyStatusEnum>, byMotives?: list<Motive>, byCreatedBefore?: \DateTimeImmutable, byCreatedAfter?: \DateTimeImmutable, byAddressee?: list<User>}
|
||||||
*/
|
*/
|
||||||
interface TicketACLAwareRepositoryInterface
|
interface TicketACLAwareRepositoryInterface
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,302 @@
|
|||||||
|
<?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\TicketBundle\Tests\Controller;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||||
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
|
use Chill\PersonBundle\Repository\PersonRepository;
|
||||||
|
use Chill\TicketBundle\Controller\TicketListApiController;
|
||||||
|
use Chill\TicketBundle\Entity\Ticket;
|
||||||
|
use Chill\TicketBundle\Repository\MotiveRepository;
|
||||||
|
use Chill\TicketBundle\Repository\TicketACLAwareRepositoryInterface;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Prophecy\Argument;
|
||||||
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||||
|
use Symfony\Component\Security\Core\Security;
|
||||||
|
use Symfony\Component\Serializer\SerializerInterface;
|
||||||
|
use Symfony\Component\Clock\MockClock;
|
||||||
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*
|
||||||
|
* @covers \Chill\TicketBundle\Controller\TicketListApiController
|
||||||
|
*/
|
||||||
|
final class TicketListApiControllerByAddresseeTest extends TestCase
|
||||||
|
{
|
||||||
|
use ProphecyTrait;
|
||||||
|
|
||||||
|
public function testListTicketWithSingleByAddresseeFilter(): void
|
||||||
|
{
|
||||||
|
// Mock dependencies
|
||||||
|
$security = $this->prophesize(Security::class);
|
||||||
|
$security->isGranted('ROLE_USER')->willReturn(true);
|
||||||
|
|
||||||
|
$user = new User();
|
||||||
|
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
$userRepository->find(1)->willReturn($user);
|
||||||
|
|
||||||
|
$ticketRepository = $this->prophesize(TicketACLAwareRepositoryInterface::class);
|
||||||
|
$tickets = [new Ticket(), new Ticket()];
|
||||||
|
$ticketRepository->countTickets(
|
||||||
|
Argument::that(fn ($params) => isset($params['byAddressee']) && in_array($user, $params['byAddressee']))
|
||||||
|
)
|
||||||
|
->shouldBeCalled()
|
||||||
|
->willReturn(2);
|
||||||
|
$ticketRepository->findTickets(
|
||||||
|
Argument::that(fn ($params) => isset($params['byAddressee']) && in_array($user, $params['byAddressee'])),
|
||||||
|
0,
|
||||||
|
10
|
||||||
|
)->shouldBeCalled()->willReturn($tickets);
|
||||||
|
|
||||||
|
$paginator = $this->prophesize(PaginatorInterface::class);
|
||||||
|
$paginator->getCurrentPageFirstItemNumber()->willReturn(0);
|
||||||
|
$paginator->getItemsPerPage()->willReturn(10);
|
||||||
|
|
||||||
|
$paginatorFactory = $this->prophesize(PaginatorFactoryInterface::class);
|
||||||
|
$paginatorFactory->create(2)->willReturn($paginator->reveal());
|
||||||
|
|
||||||
|
$serializer = $this->prophesize(SerializerInterface::class);
|
||||||
|
$serializer->serialize(
|
||||||
|
Argument::that(fn (Collection $collection) => $collection->getItems() === $tickets),
|
||||||
|
'json',
|
||||||
|
['groups' => 'read:simple']
|
||||||
|
)->willReturn('{"items":[{},{}],"pagination":{}}');
|
||||||
|
|
||||||
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
|
||||||
|
// Create controller
|
||||||
|
$controller = new TicketListApiController(
|
||||||
|
$security->reveal(),
|
||||||
|
$ticketRepository->reveal(),
|
||||||
|
$paginatorFactory->reveal(),
|
||||||
|
$serializer->reveal(),
|
||||||
|
$personRepository->reveal(),
|
||||||
|
$motiveRepository->reveal(),
|
||||||
|
new MockClock(),
|
||||||
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create request with byAddressee filter
|
||||||
|
$request = new Request(
|
||||||
|
query: ['byAddressee' => '1']
|
||||||
|
);
|
||||||
|
|
||||||
|
// Call controller method
|
||||||
|
$response = $controller->listTicket($request);
|
||||||
|
|
||||||
|
// Assert response
|
||||||
|
$this->assertInstanceOf(JsonResponse::class, $response);
|
||||||
|
$this->assertEquals('{"items":[{},{}],"pagination":{}}', $response->getContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testListTicketWithMultipleByAddresseeFilter(): void
|
||||||
|
{
|
||||||
|
// Mock dependencies
|
||||||
|
$security = $this->prophesize(Security::class);
|
||||||
|
$security->isGranted('ROLE_USER')->willReturn(true);
|
||||||
|
|
||||||
|
$user1 = new User();
|
||||||
|
$user2 = new User();
|
||||||
|
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
$userRepository->find(1)->willReturn($user1);
|
||||||
|
$userRepository->find(2)->willReturn($user2);
|
||||||
|
|
||||||
|
$ticketRepository = $this->prophesize(TicketACLAwareRepositoryInterface::class);
|
||||||
|
$tickets = [new Ticket(), new Ticket()];
|
||||||
|
$ticketRepository->countTickets(
|
||||||
|
Argument::that(fn ($params) => isset($params['byAddressee'])
|
||||||
|
&& in_array($user1, $params['byAddressee'])
|
||||||
|
&& in_array($user2, $params['byAddressee']))
|
||||||
|
)
|
||||||
|
->shouldBeCalled()
|
||||||
|
->willReturn(2);
|
||||||
|
$ticketRepository->findTickets(
|
||||||
|
Argument::that(fn ($params) => isset($params['byAddressee'])
|
||||||
|
&& in_array($user1, $params['byAddressee'])
|
||||||
|
&& in_array($user2, $params['byAddressee'])),
|
||||||
|
0,
|
||||||
|
10
|
||||||
|
)->shouldBeCalled()->willReturn($tickets);
|
||||||
|
|
||||||
|
$paginator = $this->prophesize(PaginatorInterface::class);
|
||||||
|
$paginator->getCurrentPageFirstItemNumber()->willReturn(0);
|
||||||
|
$paginator->getItemsPerPage()->willReturn(10);
|
||||||
|
|
||||||
|
$paginatorFactory = $this->prophesize(PaginatorFactoryInterface::class);
|
||||||
|
$paginatorFactory->create(2)->willReturn($paginator->reveal());
|
||||||
|
|
||||||
|
$serializer = $this->prophesize(SerializerInterface::class);
|
||||||
|
$serializer->serialize(
|
||||||
|
Argument::that(fn (Collection $collection) => $collection->getItems() === $tickets),
|
||||||
|
'json',
|
||||||
|
['groups' => 'read:simple']
|
||||||
|
)->willReturn('{"items":[{},{}],"pagination":{}}');
|
||||||
|
|
||||||
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
|
||||||
|
// Create controller
|
||||||
|
$controller = new TicketListApiController(
|
||||||
|
$security->reveal(),
|
||||||
|
$ticketRepository->reveal(),
|
||||||
|
$paginatorFactory->reveal(),
|
||||||
|
$serializer->reveal(),
|
||||||
|
$personRepository->reveal(),
|
||||||
|
$motiveRepository->reveal(),
|
||||||
|
new MockClock(),
|
||||||
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create request with multiple byAddressee filter
|
||||||
|
$request = new Request(
|
||||||
|
query: ['byAddressee' => '1,2']
|
||||||
|
);
|
||||||
|
|
||||||
|
// Call controller method
|
||||||
|
$response = $controller->listTicket($request);
|
||||||
|
|
||||||
|
// Assert response
|
||||||
|
$this->assertInstanceOf(JsonResponse::class, $response);
|
||||||
|
$this->assertEquals('{"items":[{},{}],"pagination":{}}', $response->getContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testListTicketWithByAddresseeFilterUserNotFound(): void
|
||||||
|
{
|
||||||
|
self::expectException(BadRequestHttpException::class);
|
||||||
|
self::expectExceptionMessage('User not found');
|
||||||
|
|
||||||
|
// Mock dependencies
|
||||||
|
$security = $this->prophesize(Security::class);
|
||||||
|
$security->isGranted('ROLE_USER')->willReturn(true);
|
||||||
|
|
||||||
|
$user1 = new User();
|
||||||
|
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
$userRepository->find(1)->willReturn($user1);
|
||||||
|
$userRepository->find(2)->willReturn(null); // User not found
|
||||||
|
|
||||||
|
$ticketRepository = $this->prophesize(TicketACLAwareRepositoryInterface::class);
|
||||||
|
$paginatorFactory = $this->prophesize(PaginatorFactoryInterface::class);
|
||||||
|
$serializer = $this->prophesize(SerializerInterface::class);
|
||||||
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
|
||||||
|
// Create controller
|
||||||
|
$controller = new TicketListApiController(
|
||||||
|
$security->reveal(),
|
||||||
|
$ticketRepository->reveal(),
|
||||||
|
$paginatorFactory->reveal(),
|
||||||
|
$serializer->reveal(),
|
||||||
|
$personRepository->reveal(),
|
||||||
|
$motiveRepository->reveal(),
|
||||||
|
new MockClock(),
|
||||||
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create request with byAddressee filter with non-existent user
|
||||||
|
$request = new Request(
|
||||||
|
query: ['byAddressee' => '1,2']
|
||||||
|
);
|
||||||
|
|
||||||
|
// Call controller method - should throw exception
|
||||||
|
$controller->listTicket($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testListTicketWithByAddresseeAndByAddresseeToMeFilters(): void
|
||||||
|
{
|
||||||
|
// Mock dependencies
|
||||||
|
$currentUser = new User();
|
||||||
|
$user1 = new User();
|
||||||
|
|
||||||
|
$security = $this->prophesize(Security::class);
|
||||||
|
$security->isGranted('ROLE_USER')->willReturn(true);
|
||||||
|
$security->getUser()->willReturn($currentUser);
|
||||||
|
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
$userRepository->find(1)->willReturn($user1);
|
||||||
|
|
||||||
|
$ticketRepository = $this->prophesize(TicketACLAwareRepositoryInterface::class);
|
||||||
|
$tickets = [new Ticket(), new Ticket()];
|
||||||
|
$ticketRepository->countTickets(
|
||||||
|
Argument::that(fn ($params) => isset($params['byAddressee'])
|
||||||
|
&& in_array($currentUser, $params['byAddressee'])
|
||||||
|
&& in_array($user1, $params['byAddressee']))
|
||||||
|
)
|
||||||
|
->shouldBeCalled()
|
||||||
|
->willReturn(2);
|
||||||
|
$ticketRepository->findTickets(
|
||||||
|
Argument::that(fn ($params) => isset($params['byAddressee'])
|
||||||
|
&& in_array($currentUser, $params['byAddressee'])
|
||||||
|
&& in_array($user1, $params['byAddressee'])),
|
||||||
|
0,
|
||||||
|
10
|
||||||
|
)->shouldBeCalled()->willReturn($tickets);
|
||||||
|
|
||||||
|
$paginator = $this->prophesize(PaginatorInterface::class);
|
||||||
|
$paginator->getCurrentPageFirstItemNumber()->willReturn(0);
|
||||||
|
$paginator->getItemsPerPage()->willReturn(10);
|
||||||
|
|
||||||
|
$paginatorFactory = $this->prophesize(PaginatorFactoryInterface::class);
|
||||||
|
$paginatorFactory->create(2)->willReturn($paginator->reveal());
|
||||||
|
|
||||||
|
$serializer = $this->prophesize(SerializerInterface::class);
|
||||||
|
$serializer->serialize(
|
||||||
|
Argument::that(fn (Collection $collection) => $collection->getItems() === $tickets),
|
||||||
|
'json',
|
||||||
|
['groups' => 'read:simple']
|
||||||
|
)->willReturn('{"items":[{},{}],"pagination":{}}');
|
||||||
|
|
||||||
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
|
||||||
|
// Create controller
|
||||||
|
$controller = new TicketListApiController(
|
||||||
|
$security->reveal(),
|
||||||
|
$ticketRepository->reveal(),
|
||||||
|
$paginatorFactory->reveal(),
|
||||||
|
$serializer->reveal(),
|
||||||
|
$personRepository->reveal(),
|
||||||
|
$motiveRepository->reveal(),
|
||||||
|
new MockClock(),
|
||||||
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create request with both byAddressee and byAddresseeToMe filters
|
||||||
|
$request = new Request(
|
||||||
|
query: [
|
||||||
|
'byAddressee' => '1',
|
||||||
|
'byAddresseeToMe' => '',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Call controller method
|
||||||
|
$response = $controller->listTicket($request);
|
||||||
|
|
||||||
|
// Assert response
|
||||||
|
$this->assertInstanceOf(JsonResponse::class, $response);
|
||||||
|
$this->assertEquals('{"items":[{},{}],"pagination":{}}', $response->getContent());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,108 @@
|
|||||||
|
<?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\TicketBundle\Tests\Controller;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||||
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
|
use Chill\PersonBundle\Repository\PersonRepository;
|
||||||
|
use Chill\TicketBundle\Controller\TicketListApiController;
|
||||||
|
use Chill\TicketBundle\Entity\Ticket;
|
||||||
|
use Chill\TicketBundle\Repository\MotiveRepository;
|
||||||
|
use Chill\TicketBundle\Repository\TicketACLAwareRepositoryInterface;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Prophecy\Argument;
|
||||||
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\Security\Core\Security;
|
||||||
|
use Symfony\Component\Serializer\SerializerInterface;
|
||||||
|
use Symfony\Component\Clock\MockClock;
|
||||||
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*
|
||||||
|
* @covers \Chill\TicketBundle\Controller\TicketListApiController
|
||||||
|
*/
|
||||||
|
final class TicketListApiControllerByAddresseeToMeTest extends TestCase
|
||||||
|
{
|
||||||
|
use ProphecyTrait;
|
||||||
|
|
||||||
|
public function testListTicketWithByAddresseeToMeFilter(): void
|
||||||
|
{
|
||||||
|
// Mock dependencies
|
||||||
|
$user = new User();
|
||||||
|
|
||||||
|
$security = $this->prophesize(Security::class);
|
||||||
|
$security->isGranted('ROLE_USER')->willReturn(true);
|
||||||
|
$security->getUser()->willReturn($user);
|
||||||
|
|
||||||
|
$ticketRepository = $this->prophesize(TicketACLAwareRepositoryInterface::class);
|
||||||
|
$tickets = [new Ticket(), new Ticket()];
|
||||||
|
$ticketRepository->countTickets(
|
||||||
|
Argument::that(fn ($params) => isset($params['byAddressee']) && in_array($user, $params['byAddressee']))
|
||||||
|
)
|
||||||
|
->shouldBeCalled()
|
||||||
|
->willReturn(2);
|
||||||
|
$ticketRepository->findTickets(
|
||||||
|
Argument::that(fn ($params) => isset($params['byAddressee']) && in_array($user, $params['byAddressee'])),
|
||||||
|
0,
|
||||||
|
10
|
||||||
|
)->shouldBeCalled()->willReturn($tickets);
|
||||||
|
|
||||||
|
$paginator = $this->prophesize(PaginatorInterface::class);
|
||||||
|
$paginator->getCurrentPageFirstItemNumber()->willReturn(0);
|
||||||
|
$paginator->getItemsPerPage()->willReturn(10);
|
||||||
|
|
||||||
|
$paginatorFactory = $this->prophesize(PaginatorFactoryInterface::class);
|
||||||
|
$paginatorFactory->create(2)->willReturn($paginator->reveal());
|
||||||
|
|
||||||
|
$serializer = $this->prophesize(SerializerInterface::class);
|
||||||
|
$serializer->serialize(
|
||||||
|
Argument::that(fn (Collection $collection) => $collection->getItems() === $tickets),
|
||||||
|
'json',
|
||||||
|
['groups' => 'read:simple']
|
||||||
|
)->willReturn('{"items":[{},{}],"pagination":{}}');
|
||||||
|
|
||||||
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
|
||||||
|
// Create controller
|
||||||
|
$controller = new TicketListApiController(
|
||||||
|
$security->reveal(),
|
||||||
|
$ticketRepository->reveal(),
|
||||||
|
$paginatorFactory->reveal(),
|
||||||
|
$serializer->reveal(),
|
||||||
|
$personRepository->reveal(),
|
||||||
|
$motiveRepository->reveal(),
|
||||||
|
new MockClock(),
|
||||||
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create request with byAddresseeToMe filter
|
||||||
|
$request = new Request(
|
||||||
|
query: ['byAddresseeToMe' => '']
|
||||||
|
);
|
||||||
|
|
||||||
|
// Call controller method
|
||||||
|
$response = $controller->listTicket($request);
|
||||||
|
|
||||||
|
// Assert response
|
||||||
|
$this->assertInstanceOf(JsonResponse::class, $response);
|
||||||
|
$this->assertEquals('{"items":[{},{}],"pagination":{}}', $response->getContent());
|
||||||
|
}
|
||||||
|
}
|
@ -13,6 +13,7 @@ namespace Chill\TicketBundle\Tests\Controller;
|
|||||||
|
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
use Chill\MainBundle\Serializer\Model\Collection;
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
use Chill\PersonBundle\Repository\PersonRepository;
|
use Chill\PersonBundle\Repository\PersonRepository;
|
||||||
use Chill\TicketBundle\Controller\TicketListApiController;
|
use Chill\TicketBundle\Controller\TicketListApiController;
|
||||||
@ -84,6 +85,7 @@ final class TicketListApiControllerByCreatedAfterTest extends TestCase
|
|||||||
|
|
||||||
$personRepository = $this->prophesize(PersonRepository::class);
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
|
||||||
// Create controller
|
// Create controller
|
||||||
$controller = new TicketListApiController(
|
$controller = new TicketListApiController(
|
||||||
@ -94,7 +96,8 @@ final class TicketListApiControllerByCreatedAfterTest extends TestCase
|
|||||||
$personRepository->reveal(),
|
$personRepository->reveal(),
|
||||||
$motiveRepository->reveal(),
|
$motiveRepository->reveal(),
|
||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]])
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with byCreatedAfter filter in RFC3339 format
|
// Create request with byCreatedAfter filter in RFC3339 format
|
||||||
@ -155,6 +158,7 @@ final class TicketListApiControllerByCreatedAfterTest extends TestCase
|
|||||||
|
|
||||||
$personRepository = $this->prophesize(PersonRepository::class);
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
|
||||||
// Create controller
|
// Create controller
|
||||||
$controller = new TicketListApiController(
|
$controller = new TicketListApiController(
|
||||||
@ -165,7 +169,8 @@ final class TicketListApiControllerByCreatedAfterTest extends TestCase
|
|||||||
$personRepository->reveal(),
|
$personRepository->reveal(),
|
||||||
$motiveRepository->reveal(),
|
$motiveRepository->reveal(),
|
||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]])
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with byCreatedAfter filter in RFC3339_EXTENDED format
|
// Create request with byCreatedAfter filter in RFC3339_EXTENDED format
|
||||||
@ -195,6 +200,7 @@ final class TicketListApiControllerByCreatedAfterTest extends TestCase
|
|||||||
$serializer = $this->prophesize(SerializerInterface::class);
|
$serializer = $this->prophesize(SerializerInterface::class);
|
||||||
$personRepository = $this->prophesize(PersonRepository::class);
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
|
||||||
// Create controller
|
// Create controller
|
||||||
$controller = new TicketListApiController(
|
$controller = new TicketListApiController(
|
||||||
@ -205,7 +211,8 @@ final class TicketListApiControllerByCreatedAfterTest extends TestCase
|
|||||||
$personRepository->reveal(),
|
$personRepository->reveal(),
|
||||||
$motiveRepository->reveal(),
|
$motiveRepository->reveal(),
|
||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]])
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with byCreatedAfter filter in invalid format
|
// Create request with byCreatedAfter filter in invalid format
|
||||||
|
@ -13,6 +13,7 @@ namespace Chill\TicketBundle\Tests\Controller;
|
|||||||
|
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
use Chill\MainBundle\Serializer\Model\Collection;
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
use Chill\PersonBundle\Repository\PersonRepository;
|
use Chill\PersonBundle\Repository\PersonRepository;
|
||||||
use Chill\TicketBundle\Controller\TicketListApiController;
|
use Chill\TicketBundle\Controller\TicketListApiController;
|
||||||
@ -84,6 +85,7 @@ final class TicketListApiControllerByCreatedBeforeTest extends TestCase
|
|||||||
|
|
||||||
$personRepository = $this->prophesize(PersonRepository::class);
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
|
||||||
// Create controller
|
// Create controller
|
||||||
$controller = new TicketListApiController(
|
$controller = new TicketListApiController(
|
||||||
@ -94,7 +96,8 @@ final class TicketListApiControllerByCreatedBeforeTest extends TestCase
|
|||||||
$personRepository->reveal(),
|
$personRepository->reveal(),
|
||||||
$motiveRepository->reveal(),
|
$motiveRepository->reveal(),
|
||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]])
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with byCreatedAfter filter in RFC3339 format
|
// Create request with byCreatedAfter filter in RFC3339 format
|
||||||
@ -155,6 +158,7 @@ final class TicketListApiControllerByCreatedBeforeTest extends TestCase
|
|||||||
|
|
||||||
$personRepository = $this->prophesize(PersonRepository::class);
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
|
||||||
// Create controller
|
// Create controller
|
||||||
$controller = new TicketListApiController(
|
$controller = new TicketListApiController(
|
||||||
@ -165,7 +169,8 @@ final class TicketListApiControllerByCreatedBeforeTest extends TestCase
|
|||||||
$personRepository->reveal(),
|
$personRepository->reveal(),
|
||||||
$motiveRepository->reveal(),
|
$motiveRepository->reveal(),
|
||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]])
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with byCreatedAfter filter in RFC3339_EXTENDED format
|
// Create request with byCreatedAfter filter in RFC3339_EXTENDED format
|
||||||
@ -195,6 +200,7 @@ final class TicketListApiControllerByCreatedBeforeTest extends TestCase
|
|||||||
$serializer = $this->prophesize(SerializerInterface::class);
|
$serializer = $this->prophesize(SerializerInterface::class);
|
||||||
$personRepository = $this->prophesize(PersonRepository::class);
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
|
||||||
// Create controller
|
// Create controller
|
||||||
$controller = new TicketListApiController(
|
$controller = new TicketListApiController(
|
||||||
@ -205,7 +211,8 @@ final class TicketListApiControllerByCreatedBeforeTest extends TestCase
|
|||||||
$personRepository->reveal(),
|
$personRepository->reveal(),
|
||||||
$motiveRepository->reveal(),
|
$motiveRepository->reveal(),
|
||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]])
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with byCreatedAfter filter in invalid format
|
// Create request with byCreatedAfter filter in invalid format
|
||||||
|
@ -13,6 +13,7 @@ namespace Chill\TicketBundle\Tests\Controller;
|
|||||||
|
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
use Chill\MainBundle\Serializer\Model\Collection;
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
use Chill\PersonBundle\Repository\PersonRepository;
|
use Chill\PersonBundle\Repository\PersonRepository;
|
||||||
use Chill\TicketBundle\Controller\TicketListApiController;
|
use Chill\TicketBundle\Controller\TicketListApiController;
|
||||||
@ -94,6 +95,7 @@ final class TicketListApiControllerByResponseTimeExceededTest extends TestCase
|
|||||||
|
|
||||||
$personRepository = $this->prophesize(PersonRepository::class);
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
|
||||||
// Create controller
|
// Create controller
|
||||||
$controller = new TicketListApiController(
|
$controller = new TicketListApiController(
|
||||||
@ -104,7 +106,8 @@ final class TicketListApiControllerByResponseTimeExceededTest extends TestCase
|
|||||||
$personRepository->reveal(),
|
$personRepository->reveal(),
|
||||||
$motiveRepository->reveal(),
|
$motiveRepository->reveal(),
|
||||||
$mockClock,
|
$mockClock,
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]])
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with byResponseTimeExceeded parameter only
|
// Create request with byResponseTimeExceeded parameter only
|
||||||
@ -176,6 +179,7 @@ final class TicketListApiControllerByResponseTimeExceededTest extends TestCase
|
|||||||
|
|
||||||
$personRepository = $this->prophesize(PersonRepository::class);
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
|
||||||
// Create controller
|
// Create controller
|
||||||
$controller = new TicketListApiController(
|
$controller = new TicketListApiController(
|
||||||
@ -186,7 +190,8 @@ final class TicketListApiControllerByResponseTimeExceededTest extends TestCase
|
|||||||
$personRepository->reveal(),
|
$personRepository->reveal(),
|
||||||
$motiveRepository->reveal(),
|
$motiveRepository->reveal(),
|
||||||
$mockClock,
|
$mockClock,
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]])
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with both byCreatedAfter and byResponseTimeExceeded parameters
|
// Create request with both byCreatedAfter and byResponseTimeExceeded parameters
|
||||||
|
@ -13,6 +13,7 @@ namespace Chill\TicketBundle\Tests\Controller;
|
|||||||
|
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
use Chill\MainBundle\Serializer\Model\Collection;
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
use Chill\PersonBundle\Repository\PersonRepository;
|
use Chill\PersonBundle\Repository\PersonRepository;
|
||||||
use Chill\TicketBundle\Controller\TicketListApiController;
|
use Chill\TicketBundle\Controller\TicketListApiController;
|
||||||
@ -74,6 +75,7 @@ final class TicketListApiControllerCurrentStateEmergencyTest extends TestCase
|
|||||||
|
|
||||||
$personRepository = $this->prophesize(PersonRepository::class);
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
|
||||||
// Create controller
|
// Create controller
|
||||||
$controller = new TicketListApiController(
|
$controller = new TicketListApiController(
|
||||||
@ -84,7 +86,8 @@ final class TicketListApiControllerCurrentStateEmergencyTest extends TestCase
|
|||||||
$personRepository->reveal(),
|
$personRepository->reveal(),
|
||||||
$motiveRepository->reveal(),
|
$motiveRepository->reveal(),
|
||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]])
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with emergency filter
|
// Create request with emergency filter
|
||||||
@ -113,6 +116,7 @@ final class TicketListApiControllerCurrentStateEmergencyTest extends TestCase
|
|||||||
$serializer = $this->prophesize(SerializerInterface::class);
|
$serializer = $this->prophesize(SerializerInterface::class);
|
||||||
$personRepository = $this->prophesize(PersonRepository::class);
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
|
||||||
// Create controller
|
// Create controller
|
||||||
$controller = new TicketListApiController(
|
$controller = new TicketListApiController(
|
||||||
@ -123,7 +127,8 @@ final class TicketListApiControllerCurrentStateEmergencyTest extends TestCase
|
|||||||
$personRepository->reveal(),
|
$personRepository->reveal(),
|
||||||
$motiveRepository->reveal(),
|
$motiveRepository->reveal(),
|
||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]])
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with invalid emergency filter
|
// Create request with invalid emergency filter
|
||||||
|
@ -13,6 +13,7 @@ namespace Chill\TicketBundle\Tests\Controller;
|
|||||||
|
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
use Chill\MainBundle\Serializer\Model\Collection;
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
use Chill\PersonBundle\Repository\PersonRepository;
|
use Chill\PersonBundle\Repository\PersonRepository;
|
||||||
use Chill\TicketBundle\Controller\TicketListApiController;
|
use Chill\TicketBundle\Controller\TicketListApiController;
|
||||||
@ -74,6 +75,7 @@ final class TicketListApiControllerCurrentStateTest extends TestCase
|
|||||||
|
|
||||||
$personRepository = $this->prophesize(PersonRepository::class);
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
|
||||||
// Create controller
|
// Create controller
|
||||||
$controller = new TicketListApiController(
|
$controller = new TicketListApiController(
|
||||||
@ -84,7 +86,8 @@ final class TicketListApiControllerCurrentStateTest extends TestCase
|
|||||||
$personRepository->reveal(),
|
$personRepository->reveal(),
|
||||||
$motiveRepository->reveal(),
|
$motiveRepository->reveal(),
|
||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]])
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with person filter
|
// Create request with person filter
|
||||||
@ -113,6 +116,7 @@ final class TicketListApiControllerCurrentStateTest extends TestCase
|
|||||||
$serializer = $this->prophesize(SerializerInterface::class);
|
$serializer = $this->prophesize(SerializerInterface::class);
|
||||||
$personRepository = $this->prophesize(PersonRepository::class);
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
|
||||||
// Create controller
|
// Create controller
|
||||||
$controller = new TicketListApiController(
|
$controller = new TicketListApiController(
|
||||||
@ -123,7 +127,8 @@ final class TicketListApiControllerCurrentStateTest extends TestCase
|
|||||||
$personRepository->reveal(),
|
$personRepository->reveal(),
|
||||||
$motiveRepository->reveal(),
|
$motiveRepository->reveal(),
|
||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]])
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with person filter
|
// Create request with person filter
|
||||||
|
@ -13,6 +13,7 @@ namespace Chill\TicketBundle\Tests\Controller;
|
|||||||
|
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
use Chill\MainBundle\Serializer\Model\Collection;
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
use Chill\PersonBundle\Repository\PersonRepository;
|
use Chill\PersonBundle\Repository\PersonRepository;
|
||||||
use Chill\TicketBundle\Controller\TicketListApiController;
|
use Chill\TicketBundle\Controller\TicketListApiController;
|
||||||
@ -79,6 +80,7 @@ final class TicketListApiControllerMotivesTest extends TestCase
|
|||||||
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
$motiveRepository->find(1)->willReturn($motive1);
|
$motiveRepository->find(1)->willReturn($motive1);
|
||||||
$motiveRepository->find(2)->willReturn($motive2);
|
$motiveRepository->find(2)->willReturn($motive2);
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
|
||||||
// Create controller
|
// Create controller
|
||||||
$controller = new TicketListApiController(
|
$controller = new TicketListApiController(
|
||||||
@ -89,7 +91,8 @@ final class TicketListApiControllerMotivesTest extends TestCase
|
|||||||
$personRepository->reveal(),
|
$personRepository->reveal(),
|
||||||
$motiveRepository->reveal(),
|
$motiveRepository->reveal(),
|
||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]])
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with multiple motives filter
|
// Create request with multiple motives filter
|
||||||
@ -142,6 +145,7 @@ final class TicketListApiControllerMotivesTest extends TestCase
|
|||||||
$personRepository = $this->prophesize(PersonRepository::class);
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
$motiveRepository->find(1)->willReturn($motive);
|
$motiveRepository->find(1)->willReturn($motive);
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
|
||||||
// Create controller
|
// Create controller
|
||||||
$controller = new TicketListApiController(
|
$controller = new TicketListApiController(
|
||||||
@ -152,7 +156,8 @@ final class TicketListApiControllerMotivesTest extends TestCase
|
|||||||
$personRepository->reveal(),
|
$personRepository->reveal(),
|
||||||
$motiveRepository->reveal(),
|
$motiveRepository->reveal(),
|
||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]])
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with single motive filter
|
// Create request with single motive filter
|
||||||
@ -183,6 +188,7 @@ final class TicketListApiControllerMotivesTest extends TestCase
|
|||||||
$personRepository = $this->prophesize(PersonRepository::class);
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
$motiveRepository->find(999)->willReturn(null);
|
$motiveRepository->find(999)->willReturn(null);
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
|
||||||
// Create controller
|
// Create controller
|
||||||
$controller = new TicketListApiController(
|
$controller = new TicketListApiController(
|
||||||
@ -193,7 +199,8 @@ final class TicketListApiControllerMotivesTest extends TestCase
|
|||||||
$personRepository->reveal(),
|
$personRepository->reveal(),
|
||||||
$motiveRepository->reveal(),
|
$motiveRepository->reveal(),
|
||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]])
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with non-existent motive
|
// Create request with non-existent motive
|
||||||
@ -219,6 +226,7 @@ final class TicketListApiControllerMotivesTest extends TestCase
|
|||||||
$serializer = $this->prophesize(SerializerInterface::class);
|
$serializer = $this->prophesize(SerializerInterface::class);
|
||||||
$personRepository = $this->prophesize(PersonRepository::class);
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
|
||||||
// Create controller
|
// Create controller
|
||||||
$controller = new TicketListApiController(
|
$controller = new TicketListApiController(
|
||||||
@ -229,7 +237,8 @@ final class TicketListApiControllerMotivesTest extends TestCase
|
|||||||
$personRepository->reveal(),
|
$personRepository->reveal(),
|
||||||
$motiveRepository->reveal(),
|
$motiveRepository->reveal(),
|
||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]])
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with non-integer motive parameter
|
// Create request with non-integer motive parameter
|
||||||
|
@ -13,6 +13,7 @@ namespace Chill\TicketBundle\Tests\Controller;
|
|||||||
|
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
use Chill\MainBundle\Serializer\Model\Collection;
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\PersonBundle\Repository\PersonRepository;
|
use Chill\PersonBundle\Repository\PersonRepository;
|
||||||
@ -68,6 +69,7 @@ final class TicketListApiControllerTest extends TestCase
|
|||||||
|
|
||||||
$personRepository = $this->prophesize(PersonRepository::class);
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
|
||||||
// Create controller
|
// Create controller
|
||||||
$controller = new TicketListApiController(
|
$controller = new TicketListApiController(
|
||||||
@ -78,7 +80,8 @@ final class TicketListApiControllerTest extends TestCase
|
|||||||
$personRepository->reveal(),
|
$personRepository->reveal(),
|
||||||
$motiveRepository->reveal(),
|
$motiveRepository->reveal(),
|
||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]])
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request
|
// Create request
|
||||||
@ -127,6 +130,7 @@ final class TicketListApiControllerTest extends TestCase
|
|||||||
$personRepository = $this->prophesize(PersonRepository::class);
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
$personRepository->find(123)->willReturn($person);
|
$personRepository->find(123)->willReturn($person);
|
||||||
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
|
||||||
// Create controller
|
// Create controller
|
||||||
$controller = new TicketListApiController(
|
$controller = new TicketListApiController(
|
||||||
@ -137,7 +141,8 @@ final class TicketListApiControllerTest extends TestCase
|
|||||||
$personRepository->reveal(),
|
$personRepository->reveal(),
|
||||||
$motiveRepository->reveal(),
|
$motiveRepository->reveal(),
|
||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]])
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with person filter
|
// Create request with person filter
|
||||||
@ -164,6 +169,7 @@ final class TicketListApiControllerTest extends TestCase
|
|||||||
$serializer = $this->prophesize(SerializerInterface::class);
|
$serializer = $this->prophesize(SerializerInterface::class);
|
||||||
$personRepository = $this->prophesize(PersonRepository::class);
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
|
||||||
// Create controller
|
// Create controller
|
||||||
$controller = new TicketListApiController(
|
$controller = new TicketListApiController(
|
||||||
@ -174,7 +180,8 @@ final class TicketListApiControllerTest extends TestCase
|
|||||||
$personRepository->reveal(),
|
$personRepository->reveal(),
|
||||||
$motiveRepository->reveal(),
|
$motiveRepository->reveal(),
|
||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]])
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request
|
// Create request
|
||||||
@ -204,6 +211,7 @@ final class TicketListApiControllerTest extends TestCase
|
|||||||
$personRepository = $this->prophesize(PersonRepository::class);
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
$personRepository->find(123)->willReturn($person);
|
$personRepository->find(123)->willReturn($person);
|
||||||
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
|
||||||
// Create controller
|
// Create controller
|
||||||
$controller = new TicketListApiController(
|
$controller = new TicketListApiController(
|
||||||
@ -214,7 +222,8 @@ final class TicketListApiControllerTest extends TestCase
|
|||||||
$personRepository->reveal(),
|
$personRepository->reveal(),
|
||||||
$motiveRepository->reveal(),
|
$motiveRepository->reveal(),
|
||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]])
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with person filter
|
// Create request with person filter
|
||||||
|
@ -11,6 +11,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\TicketBundle\Tests\Repository;
|
namespace Chill\TicketBundle\Tests\Repository;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
use Chill\PersonBundle\DataFixtures\Helper\RandomPersonHelperTrait;
|
use Chill\PersonBundle\DataFixtures\Helper\RandomPersonHelperTrait;
|
||||||
use Chill\TicketBundle\Entity\EmergencyStatusEnum;
|
use Chill\TicketBundle\Entity\EmergencyStatusEnum;
|
||||||
use Chill\TicketBundle\Entity\Motive;
|
use Chill\TicketBundle\Entity\Motive;
|
||||||
@ -123,4 +124,19 @@ class TicketACLAwareRepositoryTest extends KernelTestCase
|
|||||||
|
|
||||||
self::assertIsArray($actual);
|
self::assertIsArray($actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFindByAddressee(): void
|
||||||
|
{
|
||||||
|
$users = $this->entityManager->createQuery('SELECT u FROM '.User::class.' u')
|
||||||
|
->setMaxResults(2)
|
||||||
|
->getResult();
|
||||||
|
|
||||||
|
if ([] === $users) {
|
||||||
|
throw new \UnexpectedValueException('No users found');
|
||||||
|
}
|
||||||
|
|
||||||
|
$actual = $this->repository->findTickets(['byAddressee' => $users]);
|
||||||
|
|
||||||
|
self::assertIsArray($actual);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user