Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Sep 30, 2022
1 parent 91dc9b3 commit 14ec546
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
7 changes: 4 additions & 3 deletions tests/Adapter/ORM/EntityManagerTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\ObjectManager;
use Nucleos\Doctrine\Tests\Fixtures\DemoEntityManager;
use Nucleos\Doctrine\Tests\Fixtures\EmptyClass;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;

Expand All @@ -33,16 +34,16 @@ public function testCreateQueryBuilder(): void
;

$objectManager = $this->prophesize(ObjectManager::class);
$objectManager->getRepository('foo')
$objectManager->getRepository(EmptyClass::class)
->willReturn($repository)
;

$registry = $this->prophesize(ManagerRegistry::class);
$registry->getManagerForClass('foo')
$registry->getManagerForClass(EmptyClass::class)
->willReturn($objectManager)
;

$manager = new DemoEntityManager('foo', $registry->reveal());
$manager = new DemoEntityManager(EmptyClass::class, $registry->reveal());

static::assertSame($queryBuilder->reveal(), $manager->getQueryBuilder('alias', 'someindex'));
}
Expand Down
5 changes: 4 additions & 1 deletion tests/Fixtures/DemoEntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ final class DemoEntityManager
private $registry;

/**
* @var string
* @var class-string
*/
private $class;

/**
* @param class-string $class
*/
public function __construct(string $class, ManagerRegistry $registry)
{
$this->registry = $registry;
Expand Down
11 changes: 6 additions & 5 deletions tests/Manager/ORM/BaseQueryTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\ObjectManager;
use Nucleos\Doctrine\Tests\Fixtures\DemoEntityManager;
use Nucleos\Doctrine\Tests\Fixtures\EmptyClass;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;

Expand All @@ -33,16 +34,16 @@ protected function setUp(): void
$repository = $this->prophesize(EntityRepository::class);

$objectManager = $this->prophesize(ObjectManager::class);
$objectManager->getRepository('foo')
$objectManager->getRepository(EmptyClass::class)
->willReturn($repository)
;

$registry = $this->prophesize(ManagerRegistry::class);
$registry->getManagerForClass('foo')
$registry->getManagerForClass(EmptyClass::class)
->willReturn($objectManager)
;

$this->manager = new DemoEntityManager('foo', $registry->reveal());
$this->manager = new DemoEntityManager(EmptyClass::class, $registry->reveal());
}

public function testAddOrder(): void
Expand Down Expand Up @@ -116,7 +117,7 @@ public function testAddOrderWithMultpleSortAndOrders(): void
[
'position',
'otherfield' => 'asc',
'foo' => 'desc',
EmptyClass::class => 'desc',
],
'myalias',
[],
Expand Down Expand Up @@ -153,7 +154,7 @@ public function testAddOrderWithAliasChildOrder(): void
$builder->reveal(),
['f.position'],
'myalias',
['f' => 'foo'],
['f' => EmptyClass::class],
'desc'
));
}
Expand Down
19 changes: 10 additions & 9 deletions tests/Manager/ORM/SearchQueryTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\ObjectManager;
use Nucleos\Doctrine\Tests\Fixtures\DemoEntityManager;
use Nucleos\Doctrine\Tests\Fixtures\EmptyClass;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
Expand All @@ -36,24 +37,24 @@ protected function setUp(): void
$repository = $this->prophesize(EntityRepository::class);

$objectManager = $this->prophesize(ObjectManager::class);
$objectManager->getRepository('foo')
$objectManager->getRepository(EmptyClass::class)
->willReturn($repository)
;

$registry = $this->prophesize(ManagerRegistry::class);
$registry->getManagerForClass('foo')
$registry->getManagerForClass(EmptyClass::class)
->willReturn($objectManager)
;

$this->manager = new DemoEntityManager('foo', $registry->reveal());
$this->manager = new DemoEntityManager(EmptyClass::class, $registry->reveal());
}

public function testSearchWhere(): void
{
$builder = $this->prophesize(QueryBuilder::class);
$orx = $this->prepareOrx($builder);

$builder->setParameter('name0', 'foo')
$builder->setParameter('name0', EmptyClass::class)
->shouldBeCalled()
;
$builder->setParameter('name0_any', '% foo %')
Expand Down Expand Up @@ -82,7 +83,7 @@ public function testSearchWhere(): void
static::assertSame($orx->reveal(), $this->manager->searchWhereQueryBuilder(
$builder->reveal(),
'field',
['foo']
[EmptyClass::class]
));
}

Expand All @@ -91,7 +92,7 @@ public function testStrictSearchWhere(): void
$builder = $this->prophesize(QueryBuilder::class);
$orx = $this->prepareOrx($builder);

$builder->setParameter('name0', 'foo')
$builder->setParameter('name0', EmptyClass::class)
->shouldBeCalled()
;
$orx->add('field = :name0')
Expand All @@ -101,7 +102,7 @@ public function testStrictSearchWhere(): void
static::assertSame($orx->reveal(), $this->manager->searchWhereQueryBuilder(
$builder->reveal(),
'field',
['foo'],
[EmptyClass::class],
true
));
}
Expand All @@ -111,7 +112,7 @@ public function testSearchWhereMultipleValues(): void
$builder = $this->prophesize(QueryBuilder::class);
$orx = $this->prepareOrx($builder);

$builder->setParameter('name0', 'foo')
$builder->setParameter('name0', EmptyClass::class)
->shouldBeCalled()
;
$builder->setParameter('name1', 'bar')
Expand All @@ -133,7 +134,7 @@ public function testSearchWhereMultipleValues(): void
static::assertSame($orx->reveal(), $this->manager->searchWhereQueryBuilder(
$builder->reveal(),
'field',
['foo', 'bar', 'baz'],
[EmptyClass::class, 'bar', 'baz'],
true
));
}
Expand Down

0 comments on commit 14ec546

Please sign in to comment.