Skip to content

Commit

Permalink
Normalize assert calls in tests
Browse files Browse the repository at this point in the history
Some unusual calls were forgotten in the preview PR
  • Loading branch information
Hugo FOUGERES committed Oct 10, 2022
1 parent 5fcca6c commit 3104344
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 26 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/mongodb-odm.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

110 changes: 110 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 5 additions & 13 deletions tests/Doctrine/ODM/MongoDB/Tests/Events/LifecycleListenersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Doctrine\ODM\MongoDB\PersistentCollection\PersistentCollectionInterface;
use Doctrine\ODM\MongoDB\Tests\BaseTest;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Assert;

use function get_class;

Expand Down Expand Up @@ -196,7 +196,7 @@ public function testChangeToReferenceFieldTriggersEvents(): void
public function testPostCollectionLoad(): void
{
$evm = $this->dm->getEventManager();
$evm->addEventListener([Events::postCollectionLoad], new PostCollectionLoadEventListener($this));
$evm->addEventListener([Events::postCollectionLoad], new PostCollectionLoadEventListener());

$document = new TestDocument();
$document->name = 'Maciej';
Expand Down Expand Up @@ -242,26 +242,18 @@ class PostCollectionLoadEventListener
/** @var int */
private $at = 0;

/** @var TestCase */
private $phpunit;

public function __construct(TestCase $phpunit)
{
$this->phpunit = $phpunit;
}

/**
* @param PostCollectionLoadEventArgs<int, TestEmbeddedDocument> $e
*/
public function postCollectionLoad(PostCollectionLoadEventArgs $e): void
{
switch ($this->at++) {
case 0:
$this->phpunit->assertCount(0, $e->getCollection());
Assert::assertCount(0, $e->getCollection());
break;
case 1:
$this->phpunit->assertCount(1, $e->getCollection());
$this->phpunit->assertEquals(new TestEmbeddedDocument('For mock at 1'), $e->getCollection()[0]);
Assert::assertCount(1, $e->getCollection());
Assert::assertEquals(new TestEmbeddedDocument('For mock at 1'), $e->getCollection()[0]);
break;
default:
throw new BadMethodCallException('This was not expected');
Expand Down
18 changes: 5 additions & 13 deletions tests/Doctrine/ODM/MongoDB/Tests/Events/PreUpdateEventArgsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Documents\Book;
use Documents\Chapter;
use Documents\Page;
use PHPUnit\Framework\Assert;

use function get_class;
use function in_array;
Expand All @@ -34,7 +35,7 @@ public function testChangeSetIsUpdated(): void

public function testCollectionsAreInChangeSet(): void
{
$listener = new CollectionsAreInChangeSetListener($this);
$listener = new CollectionsAreInChangeSetListener();
$this->dm->getEventManager()->addEventListener(Events::preUpdate, $listener);

$book = new Book();
Expand Down Expand Up @@ -74,16 +75,7 @@ public function preUpdate(PreUpdateEventArgs $e): void
class CollectionsAreInChangeSetListener
{
/** @var list<class-string> */
private $allowed;

/** @var PreUpdateEventArgsTest */
private $phpunit;

public function __construct(PreUpdateEventArgsTest $phpunit)
{
$this->allowed = [Book::class, Chapter::class];
$this->phpunit = $phpunit;
}
private $allowed = [Book::class, Chapter::class];

public function checkOnly(array $allowed): void
{
Expand All @@ -95,13 +87,13 @@ public function preUpdate(PreUpdateEventArgs $e): void
switch (get_class($e->getDocument())) {
case Book::class:
if (in_array(Book::class, $this->allowed)) {
$this->phpunit->assertTrue($e->hasChangedField('chapters'));
Assert::assertTrue($e->hasChangedField('chapters'));
}

break;
case Chapter::class:
if (in_array(Chapter::class, $this->allowed)) {
$this->phpunit->assertTrue($e->hasChangedField('pages'));
Assert::assertTrue($e->hasChangedField('pages'));
}

break;
Expand Down

0 comments on commit 3104344

Please sign in to comment.