Skip to content

Commit

Permalink
phcs tests/Feature/Pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
TomHAnderson committed Oct 28, 2024
1 parent 74fc9be commit 427255e
Showing 1 changed file with 31 additions and 26 deletions.
57 changes: 31 additions & 26 deletions tests/Feature/Pagination/PaginatorAdapterTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php

declare(strict_types=1);

namespace LaravelDoctrineTest\ORM\Feature\Pagination;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Result;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManagerInterface;
Expand All @@ -16,11 +19,16 @@
use LaravelDoctrine\ORM\Pagination\PaginatorAdapter;
use LaravelDoctrineTest\ORM\TestCase;
use Mockery;
use Mockery\Mock;
use stdClass;

use function assert;

use const PHP_INT_MAX;

class PaginatorAdapterTest extends TestCase
{
public function testMakesLaravelsPaginatorFromParams()
public function testMakesLaravelsPaginatorFromParams(): void
{
$em = $this->mockEntityManager();
$query = (new Query($em))->setDQL('SELECT f FROM LaravelDoctrineTest\ORM\Assets\Entity\Foo f');
Expand All @@ -32,9 +40,9 @@ public function testMakesLaravelsPaginatorFromParams()
$this->assertEquals(2, $paginator->currentPage());
}

public function testMakesLaravelsPaginatorFromRequest()
public function testMakesLaravelsPaginatorFromRequest(): void
{
AbstractPaginator::currentPageResolver(function () {
AbstractPaginator::currentPageResolver(static function () {
return 13;
});

Expand All @@ -48,7 +56,7 @@ public function testMakesLaravelsPaginatorFromRequest()
$this->assertEquals(13, $paginator->currentPage());
}

public function testQueryParametersAreProducedInUrlFromParams()
public function testQueryParametersAreProducedInUrlFromParams(): void
{
$em = $this->mockEntityManager();
$query = (new Query($em))->setDQL('SELECT f FROM LaravelDoctrineTest\ORM\Assets\Entity\Foo f');
Expand All @@ -62,7 +70,7 @@ public function testQueryParametersAreProducedInUrlFromParams()
$this->assertStringContainsString('foo=bar', $paginator->url(1));
}

public function testQueryParametersAreProducedInUrlFromRequest()
public function testQueryParametersAreProducedInUrlFromRequest(): void
{
$em = $this->mockEntityManager();
$query = (new Query($em))->setDQL('SELECT f FROM LaravelDoctrineTest\ORM\Assets\Entity\Foo f');
Expand All @@ -74,13 +82,10 @@ public function testQueryParametersAreProducedInUrlFromRequest()
$this->assertStringContainsString('foo=bar', $paginator->url(1));
}

/**
* @return EntityManagerInterface|\Mockery\Mock
*/
private function mockEntityManager()
private function mockEntityManager(): EntityManagerInterface
{
/** @var EntityManagerInterface|\Mockery\Mock $em */
$em = Mockery::mock(EntityManagerInterface::class);
$em = Mockery::mock(EntityManagerInterface::class);
assert($em instanceof EntityManagerInterface || $em instanceof Mock);
$config = Mockery::mock(Configuration::class);
$metadata = Mockery::mock(ClassMetadata::class);
$connection = Mockery::mock(Connection::class);
Expand All @@ -91,19 +96,19 @@ private function mockEntityManager()
$config->shouldReceive('isSecondLevelCacheEnabled')->andReturn(false);
$config->shouldReceive('getQueryCacheImpl')->andReturn(null);
$config->shouldReceive('getQueryCache')->andReturn(null);
$config->shouldReceive('getQuoteStrategy')->andReturn(new DefaultQuoteStrategy);
$config->shouldReceive('getQuoteStrategy')->andReturn(new DefaultQuoteStrategy());

$id = new stdClass();
$id->fieldName = 'id';
$id = new stdClass();
$id->fieldName = 'id';
$id->columnName = 'id';
$id->type = Types::INTEGER;
$id->id = true;
$id->options = ['unsigned' => true];
$id->type = Types::INTEGER;
$id->id = true;
$id->options = ['unsigned' => true];

$name = new stdClass();
$name->fieldName = 'name';
$name = new stdClass();
$name->fieldName = 'name';
$name->columnName = 'name';
$name->type = Types::STRING;
$name->type = Types::STRING;

$metadata->fieldMappings = [
'id' => $id,
Expand All @@ -119,7 +124,7 @@ private function mockEntityManager()
'name' => 'foos',
'schema' => '',
'indexes' => [],
'uniqueConstraints' => []
'uniqueConstraints' => [],
];

$metadata->shouldReceive('isInheritanceTypeSingleTable')->andReturn(false);
Expand All @@ -128,19 +133,19 @@ private function mockEntityManager()
$metadata->shouldReceive('getTypeOfField')->andReturn(Types::INTEGER);

$connection->shouldReceive('getDatabasePlatform')->andReturn($platform);
$connection->shouldReceive('executeQuery')->andReturn($this->createMock(\Doctrine\DBAL\Result::class));
$connection->shouldReceive('executeQuery')->andReturn($this->createMock(Result::class));
$connection->shouldReceive('getParams')->andReturn([]);

$platform->shouldReceive('appendLockHint')->andReturnUsing(function ($a) {
$platform->shouldReceive('appendLockHint')->andReturnUsing(static function ($a) {
return $a;
});
$platform->shouldReceive('getMaxIdentifierLength')->andReturn(PHP_INT_MAX);
$platform->shouldReceive('getSQLResultCasing')->andReturnUsing(function ($a) {
$platform->shouldReceive('getSQLResultCasing')->andReturnUsing(static function ($a) {
return $a;
});
$platform->shouldReceive('getName')->andReturn('You shouldnt care');
$platform->shouldReceive('getCountExpression')->andReturnUsing(function ($col) {
return "COUNT($col)";
$platform->shouldReceive('getCountExpression')->andReturnUsing(static function ($col) {
return 'COUNT(' . $col . ')';
});
$platform->shouldReceive('supportsLimitOffset')->andReturn(true);

Expand Down

0 comments on commit 427255e

Please sign in to comment.