Skip to content

Commit

Permalink
Merge pull request #3412 from acrobat/improve-tests
Browse files Browse the repository at this point in the history
[AllBundles] Improve tests
  • Loading branch information
acrobat committed Apr 20, 2024
2 parents b4ec0c5 + 95434e1 commit cb6ecb4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testListener($uri, $shouldPerformCheck, $tokenStorageCallCount)

$storage->expects($this->exactly($tokenStorageCallCount))->method('getToken')->willReturn($token);
$user->expects($this->exactly($shouldPerformCheck ? 1 : 0))->method('getAdminLocale')->willReturn(null);
$trans->expects($this->exactly($shouldPerformCheck ? 1 : 0))->method('setLocale')->willReturn(null);
$trans->expects($this->exactly($shouldPerformCheck ? 1 : 0))->method('setLocale');
$adminRouteHelper->method('isAdminRoute')->willReturn($shouldPerformCheck);

$listener = new AdminLocaleListener($storage, $trans, $adminRouteHelper, 'en');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testListener($uri, $shouldPerformCheck, $tokenStorageCallCount)
$user = $this->createMock(User::class);
$router = $this->createMock(RouterInterface::class);
$session = $this->createMock(Session::class);
$flash = $this->createMock(FlashBag::class);
$flash = new FlashBag();
$trans = $this->createMock(Translator::class);
$adminRouteHelper = $this->createMock(AdminRouteHelper::class);
$kernel = $this->createMock(KernelInterface::class);
Expand All @@ -48,7 +48,6 @@ public function testListener($uri, $shouldPerformCheck, $tokenStorageCallCount)
$user->expects($this->exactly($shouldPerformCheck ? 1 : 0))->method('isPasswordChanged')->willReturn(false);
$router->expects($this->exactly($shouldPerformCheck ? 1 : 0))->method('generate')->willReturn('/url');
$session->expects($this->exactly($shouldPerformCheck ? 1 : 0))->method('getFlashBag')->willReturn($flash);
$flash->expects($this->exactly($shouldPerformCheck ? 1 : 0))->method('add')->willReturn(true);
$trans->expects($this->exactly($shouldPerformCheck ? 1 : 0))->method('trans')->willReturn('translated-text');
$adminRouteHelper->method('isAdminRoute')->willReturn($shouldPerformCheck);
$requestStack = new RequestStack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

namespace Kunstmaan\AdminListBundle\Tests\AdminList\Configurator;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Internal\Hydration\ArrayHydrator;
use Doctrine\ORM\Internal\Hydration\IterableResult;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper;
use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission\PermissionDefinition;
Expand All @@ -28,11 +33,16 @@ class AbstractDoctrineORMAdminListConfiguratorTest extends TestCase

public function setUp(): void
{
$queryMock = $this->createMock(AbstractQuery::class);
$conn = $this->createMock(Connection::class);
$conn->method('getDatabasePlatform')->willReturn(new MySQLPlatform());
$emMock = $this->createMock(EntityManagerInterface::class);
$emMock->method('getConnection')->willReturn($conn);

$queryMock = $this->createMock(Query::class);
$queryMock
->expects($this->any())
->method('iterate')
->willReturn($this->createMock(\Iterator::class))
->willReturn(new IterableResult(new ArrayHydrator($emMock)))
;

$this->emMock = $this->createMock(EntityManagerInterface::class);
Expand Down
4 changes: 2 additions & 2 deletions src/Kunstmaan/NodeBundle/Tests/Helper/NodeHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\InputBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
Expand Down Expand Up @@ -711,7 +711,7 @@ private function createNodeEntities($title = 'Test page'): array
public function testPageShouldHaveTab()
{
$request = new Request();
$request->request = new ParameterBag();
$request->request = new InputBag();

$formFactory = $this->getMockBuilder(FormFactory::class)
->disableOriginalConstructor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ public function testUnknownSearcher()
$parameterBag = new ParameterBag();
$parameterBag->set('_entity', $entity);

$request = $this->createMock(Request::class);
$request = new Request();
$request->attributes = $parameterBag;
$request->query = $parameterBag;

$container = $this->createMock(ContainerInterface::class);
$container->method('get')->with('unknown_searcher')->willThrowException(new ServiceNotFoundException('unknown_searcher'));
Expand Down

0 comments on commit cb6ecb4

Please sign in to comment.