Skip to content

Commit 45472c9

Browse files
committed
bugfix #160 Fix bad call at TicketManager::getTicketList() (phansys)
This PR was merged into the 3.x branch. Discussion ---------- |Q |A | |--- |---| |Branch |3.x| |Bug fix? |yes| |New feature? |no | |BC breaks? |no | |Deprecations?|no | |Tests pass? |yes| |Fixed tickets|n/a| |License |MIT| |Doc PR |n/a| Issue introduced at be8f77a. Commits ------- e2e7343 Fix bad call at `TicketManager::getTicketList()`
2 parents 33c3fca + e2e7343 commit 45472c9

2 files changed

Lines changed: 99 additions & 1 deletion

File tree

Manager/TicketManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public function getTicketList(UserManagerInterface $userManager, $ticketStatus,
215215
__CLASS__
216216
), E_USER_DEPRECATED);
217217

218-
return $query->getTicketListQuery($userManager, $ticketStatus, $ticketPriority);
218+
return $this->getTicketListQuery($userManager, $ticketStatus, $ticketPriority);
219219
}
220220

221221
/**
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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

Comments
 (0)