Skip to content

Commit

Permalink
Added namespace to Pagination tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TomHAnderson committed Oct 27, 2024
1 parent 00f192f commit a824ad0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
10 changes: 10 additions & 0 deletions tests/Assets/Entity/Foo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace LaravelDoctrineTest\ORM\Assets\Entity;

class Foo
{
private $id;

private $name;
}
33 changes: 15 additions & 18 deletions tests/Feature/Pagination/PaginatorAdapterTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace LaravelDoctrineTest\ORM\Feature\Pagination;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Types;
Expand All @@ -12,14 +14,16 @@
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\AbstractPaginator;
use LaravelDoctrine\ORM\Pagination\PaginatorAdapter;
use Mockery;
use PHPUnit\Framework\TestCase;
use stdClass;

class PaginatorAdapterTest extends TestCase
{
public function testMakesLaravelsPaginatorFromParams()
{
$em = $this->mockEntityManager();
$query = (new Query($em))->setDQL('SELECT f FROM Foo f');
$query = (new Query($em))->setDQL('SELECT f FROM LaravelDoctrineTest\ORM\Assets\Entity\Foo f');
$adapter = PaginatorAdapter::fromParams($query, 15, 2);

$paginator = $adapter->make();
Expand All @@ -35,7 +39,7 @@ public function testMakesLaravelsPaginatorFromRequest()
});

$em = $this->mockEntityManager();
$query = (new Query($em))->setDQL('SELECT f FROM Foo f');
$query = (new Query($em))->setDQL('SELECT f FROM LaravelDoctrineTest\ORM\Assets\Entity\Foo f');
$adapter = PaginatorAdapter::fromRequest($query);

$paginator = $adapter->make();
Expand All @@ -47,7 +51,7 @@ public function testMakesLaravelsPaginatorFromRequest()
public function testQueryParametersAreProducedInUrlFromParams()
{
$em = $this->mockEntityManager();
$query = (new Query($em))->setDQL('SELECT f FROM Foo f');
$query = (new Query($em))->setDQL('SELECT f FROM LaravelDoctrineTest\ORM\Assets\Entity\Foo f');
$adapter = PaginatorAdapter::fromParams($query, 15, 2, false)
->queryParams(['foo' => 'bar']);

Expand All @@ -61,7 +65,7 @@ public function testQueryParametersAreProducedInUrlFromParams()
public function testQueryParametersAreProducedInUrlFromRequest()
{
$em = $this->mockEntityManager();
$query = (new Query($em))->setDQL('SELECT f FROM Foo f');
$query = (new Query($em))->setDQL('SELECT f FROM LaravelDoctrineTest\ORM\Assets\Entity\Foo f');
$adapter = PaginatorAdapter::fromRequest($query)
->queryParams(['foo' => 'bar']);

Expand All @@ -76,12 +80,12 @@ public function testQueryParametersAreProducedInUrlFromRequest()
private function mockEntityManager()
{
/** @var EntityManagerInterface|\Mockery\Mock $em */
$em = \Mockery::mock(EntityManagerInterface::class);
$config = \Mockery::mock(Configuration::class);
$metadata = \Mockery::mock(ClassMetadata::class);
$connection = \Mockery::mock(Connection::class);
$platform = \Mockery::mock(AbstractPlatform::class);
$hydrator = \Mockery::mock(AbstractHydrator::class);
$em = Mockery::mock(EntityManagerInterface::class);
$config = Mockery::mock(Configuration::class);
$metadata = Mockery::mock(ClassMetadata::class);
$connection = Mockery::mock(Connection::class);
$platform = Mockery::mock(AbstractPlatform::class);
$hydrator = Mockery::mock(AbstractHydrator::class);

$config->shouldReceive('getDefaultQueryHints')->andReturn([]);
$config->shouldReceive('isSecondLevelCacheEnabled')->andReturn(false);
Expand Down Expand Up @@ -143,18 +147,11 @@ private function mockEntityManager()
$hydrator->shouldReceive('hydrateAll')->andReturn([]);

$em->shouldReceive('getConfiguration')->andReturn($config);
$em->shouldReceive('getClassMetadata')->with('Foo')->andReturn($metadata);
$em->shouldReceive('getClassMetadata')->with('LaravelDoctrineTest\ORM\Assets\Entity\Foo')->andReturn($metadata);
$em->shouldReceive('getConnection')->andReturn($connection);
$em->shouldReceive('hasFilters')->andReturn(false);
$em->shouldReceive('newHydrator')->andReturn($hydrator);

return $em;
}
}

class Foo
{
private $id;

private $name;
}

0 comments on commit a824ad0

Please sign in to comment.