Skip to content

Commit

Permalink
bugfix #160 Fix bad call at TicketManager::getTicketList() (phansys)
Browse files Browse the repository at this point in the history
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()`
  • Loading branch information
phansys committed Jul 3, 2020
2 parents 33c3fca + e2e7343 commit 45472c9
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Manager/TicketManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public function getTicketList(UserManagerInterface $userManager, $ticketStatus,
__CLASS__
), E_USER_DEPRECATED);

return $query->getTicketListQuery($userManager, $ticketStatus, $ticketPriority);
return $this->getTicketListQuery($userManager, $ticketStatus, $ticketPriority);
}

/**
Expand Down
98 changes: 98 additions & 0 deletions Tests/Manager/TicketManagerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

namespace Hackzilla\Bundle\TicketBundle\Tests\User;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
use Hackzilla\Bundle\TicketBundle\Manager\TicketManager;
use Hackzilla\Bundle\TicketBundle\Manager\UserManagerInterface;
use Hackzilla\Bundle\TicketBundle\Model\TicketMessageInterface;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

/**
* @author Javier Spagnoletti <phansys@gmail.com>
*/
final class TicketManagerTest extends WebTestCase
{
/**
* @var UserManagerInterface
*/
private $userManager;

protected function setUp()
{
$this->userManager = $this->createMock(UserManagerInterface::class);
$this->userManager
->method('getCurrentUser')
->willReturn('ANONYMOUS');
}

protected function tearDown()
{
unset($this->userManager);
}

public function testGetTicketListQuery()
{
$ticketClass = 'App\Ticket';
$ticketMessageClass = 'App\TicketMessage';

$qb = $this->createMock(QueryBuilder::class);
$qb
->method('orderBy')
->willReturn($qb);
$qb
->method('andWhere')
->willReturn($qb);
$entityRepository = $this->createMock(EntityRepository::class);
$entityRepository
->method('createQueryBuilder')
->willReturn($qb);

$om = $this->createMock(ObjectManager::class);
$om
->method('getRepository')
->willReturn($entityRepository);

$ticketManager = new TicketManager($ticketClass, $ticketMessageClass);
$ticketManager->setEntityManager($om);

$this->assertInstanceOf(QueryBuilder::class, $ticketManager->getTicketListQuery($this->userManager, TicketMessageInterface::STATUS_OPEN));
}

/**
* NEXT_MAJOR: Remove this method.
*
* @group legacy
*
* @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.
*/
public function testGetTicketList()
{
$ticketClass = 'App\Ticket';
$ticketMessageClass = 'App\TicketMessage';

$qb = $this->createMock(QueryBuilder::class);
$qb
->method('orderBy')
->willReturn($qb);
$qb
->method('andWhere')
->willReturn($qb);
$entityRepository = $this->createMock(EntityRepository::class);
$entityRepository
->method('createQueryBuilder')
->willReturn($qb);

$om = $this->createMock(ObjectManager::class);
$om
->method('getRepository')
->willReturn($entityRepository);

$ticketManager = new TicketManager($ticketClass, $ticketMessageClass);
$ticketManager->setEntityManager($om);

$this->assertInstanceOf(QueryBuilder::class, $ticketManager->getTicketList($this->userManager, TicketMessageInterface::STATUS_OPEN));
}
}

0 comments on commit 45472c9

Please sign in to comment.