chill-bundles/src/Bundle/ChillTicketBundle/tests/Service/Ticket/SuggestPersonForTicketTest.php

71 lines
1.9 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 Service\Ticket;
use Chill\PersonBundle\Entity\Person;
use Chill\TicketBundle\Entity\CallerHistory;
use Chill\TicketBundle\Entity\Ticket;
use Chill\TicketBundle\Repository\PersonTicketACLAwareRepositoryInterface;
use Chill\TicketBundle\Service\Ticket\SuggestPersonForTicket;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
/**
* @internal
*
* @coversNothing
*/
class SuggestPersonForTicketTest extends TestCase
{
use ProphecyTrait;
private \Prophecy\Prophecy\ObjectProphecy $repository;
protected function setUp(): void
{
$this->repository = $this->prophesize(PersonTicketACLAwareRepositoryInterface::class);
}
private function buildSuggestPersonForTicket(): SuggestPersonForTicket
{
return new SuggestPersonForTicket($this->repository->reveal());
}
public function testSuggestPersonNoCaller()
{
$ticket = new Ticket();
assert(null === $ticket->getCaller());
$this->repository->findPersonPreviouslyAssociatedWithCaller(Argument::any())->shouldNotBeCalled();
$suggester = $this->buildSuggestPersonForTicket();
self::assertEquals([], $suggester->suggestPerson($ticket));
}
public function testSuggestPersonCaller()
{
$ticket = new Ticket();
new CallerHistory($person = new Person(), $ticket);
assert($person === $ticket->getCaller());
$this->repository->findPersonPreviouslyAssociatedWithCaller($person, 0, 20)
->willReturn($result = [new Person(), new Person()])
->shouldBeCalledOnce();
$suggester = $this->buildSuggestPersonForTicket();
self::assertEquals($result, $suggester->suggestPerson($ticket, 0, 20));
}
}