|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Hackzilla\Bundle\TicketBundle\Tests\User; |
| 4 | + |
| 5 | +use Doctrine\Common\Persistence\ObjectManager; |
| 6 | +use Doctrine\ORM\EntityRepository; |
| 7 | +use Doctrine\ORM\QueryBuilder; |
| 8 | +use Hackzilla\Bundle\TicketBundle\Manager\TicketManager; |
| 9 | +use Hackzilla\Bundle\TicketBundle\Manager\UserManagerInterface; |
| 10 | +use Hackzilla\Bundle\TicketBundle\Model\TicketMessageInterface; |
| 11 | +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
| 12 | + |
| 13 | +/** |
| 14 | + * @author Javier Spagnoletti <phansys@gmail.com> |
| 15 | + */ |
| 16 | +final class TicketManagerTest extends WebTestCase |
| 17 | +{ |
| 18 | + /** |
| 19 | + * @var UserManagerInterface |
| 20 | + */ |
| 21 | + private $userManager; |
| 22 | + |
| 23 | + protected function setUp() |
| 24 | + { |
| 25 | + $this->userManager = $this->createMock(UserManagerInterface::class); |
| 26 | + $this->userManager |
| 27 | + ->method('getCurrentUser') |
| 28 | + ->willReturn('ANONYMOUS'); |
| 29 | + } |
| 30 | + |
| 31 | + protected function tearDown() |
| 32 | + { |
| 33 | + unset($this->userManager); |
| 34 | + } |
| 35 | + |
| 36 | + public function testGetTicketListQuery() |
| 37 | + { |
| 38 | + $ticketClass = 'App\Ticket'; |
| 39 | + $ticketMessageClass = 'App\TicketMessage'; |
| 40 | + |
| 41 | + $qb = $this->createMock(QueryBuilder::class); |
| 42 | + $qb |
| 43 | + ->method('orderBy') |
| 44 | + ->willReturn($qb); |
| 45 | + $qb |
| 46 | + ->method('andWhere') |
| 47 | + ->willReturn($qb); |
| 48 | + $entityRepository = $this->createMock(EntityRepository::class); |
| 49 | + $entityRepository |
| 50 | + ->method('createQueryBuilder') |
| 51 | + ->willReturn($qb); |
| 52 | + |
| 53 | + $om = $this->createMock(ObjectManager::class); |
| 54 | + $om |
| 55 | + ->method('getRepository') |
| 56 | + ->willReturn($entityRepository); |
| 57 | + |
| 58 | + $ticketManager = new TicketManager($ticketClass, $ticketMessageClass); |
| 59 | + $ticketManager->setEntityManager($om); |
| 60 | + |
| 61 | + $this->assertInstanceOf(QueryBuilder::class, $ticketManager->getTicketListQuery($this->userManager, TicketMessageInterface::STATUS_OPEN)); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * NEXT_MAJOR: Remove this method. |
| 66 | + * |
| 67 | + * @group legacy |
| 68 | + * |
| 69 | + * @expectedDeprecation Method `Hackzilla\Bundle\TicketBundle\Manager\TicketManager::getTicketList()` is deprecated since hackzilla/ticket-bundle 3.3 and will be removed in version 4.0. Use `Hackzilla\Bundle\TicketBundle\Manager\TicketManager::getTicketListQuery()` instead. |
| 70 | + */ |
| 71 | + public function testGetTicketList() |
| 72 | + { |
| 73 | + $ticketClass = 'App\Ticket'; |
| 74 | + $ticketMessageClass = 'App\TicketMessage'; |
| 75 | + |
| 76 | + $qb = $this->createMock(QueryBuilder::class); |
| 77 | + $qb |
| 78 | + ->method('orderBy') |
| 79 | + ->willReturn($qb); |
| 80 | + $qb |
| 81 | + ->method('andWhere') |
| 82 | + ->willReturn($qb); |
| 83 | + $entityRepository = $this->createMock(EntityRepository::class); |
| 84 | + $entityRepository |
| 85 | + ->method('createQueryBuilder') |
| 86 | + ->willReturn($qb); |
| 87 | + |
| 88 | + $om = $this->createMock(ObjectManager::class); |
| 89 | + $om |
| 90 | + ->method('getRepository') |
| 91 | + ->willReturn($entityRepository); |
| 92 | + |
| 93 | + $ticketManager = new TicketManager($ticketClass, $ticketMessageClass); |
| 94 | + $ticketManager->setEntityManager($om); |
| 95 | + |
| 96 | + $this->assertInstanceOf(QueryBuilder::class, $ticketManager->getTicketList($this->userManager, TicketMessageInterface::STATUS_OPEN)); |
| 97 | + } |
| 98 | +} |
0 commit comments