Skip to content

Commit

Permalink
Merge pull request #8904 from carnage/refactoring-tests-backport
Browse files Browse the repository at this point in the history
Refactoring more tests
  • Loading branch information
greg0ire authored Aug 14, 2021
2 parents 163aef1 + 38c0f2b commit aee197f
Show file tree
Hide file tree
Showing 92 changed files with 604 additions and 618 deletions.
24 changes: 12 additions & 12 deletions tests/Doctrine/Tests/ORM/Cache/FileLockRegionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function testLockAndUnlock(): void

self::assertFileExists($file);
self::assertInstanceOf(Lock::class, $lock);
self::assertEquals($lock->value, file_get_contents($file));
self::assertStringEqualsFile($file, $lock->value);

// should be not available after lock
self::assertFalse($this->region->contains($key));
Expand All @@ -105,10 +105,10 @@ public function testLockWithExistingLock(): void

file_put_contents($file, 'foo');
self::assertFileExists($file);
self::assertEquals('foo', file_get_contents($file));
self::assertStringEqualsFile($file, 'foo');

self::assertNull($this->region->lock($key));
self::assertEquals('foo', file_get_contents($file));
self::assertStringEqualsFile($file, 'foo');
self::assertFileExists($file);

// should be not available
Expand All @@ -127,17 +127,17 @@ public function testUnlockWithExistingLock(): void
self::assertTrue($this->region->contains($key));

self::assertInstanceOf(Lock::class, $lock = $this->region->lock($key));
self::assertEquals($lock->value, file_get_contents($file));
self::assertStringEqualsFile($file, $lock->value);
self::assertFileExists($file);

// change the lock
file_put_contents($file, 'foo');
self::assertFileExists($file);
self::assertEquals('foo', file_get_contents($file));
self::assertStringEqualsFile($file, 'foo');

//try to unlock
self::assertFalse($this->region->unlock($key, $lock));
self::assertEquals('foo', file_get_contents($file));
self::assertStringEqualsFile($file, 'foo');
self::assertFileExists($file);

// should be not available
Expand All @@ -158,14 +158,14 @@ public function testPutWithExistingLock(): void
// create lock
file_put_contents($file, 'foo');
self::assertFileExists($file);
self::assertEquals('foo', file_get_contents($file));
self::assertStringEqualsFile($file, 'foo');

self::assertFalse($this->region->contains($key));
self::assertFalse($this->region->put($key, $entry));
self::assertFalse($this->region->contains($key));

self::assertFileExists($file);
self::assertEquals('foo', file_get_contents($file));
self::assertStringEqualsFile($file, 'foo');
}

public function testLockedEvict(): void
Expand All @@ -179,7 +179,7 @@ public function testLockedEvict(): void
self::assertTrue($this->region->contains($key));

self::assertInstanceOf(Lock::class, $lock = $this->region->lock($key));
self::assertEquals($lock->value, file_get_contents($file));
self::assertStringEqualsFile($file, $lock->value);
self::assertFileExists($file);

self::assertFalse($this->region->contains($key));
Expand Down Expand Up @@ -209,8 +209,8 @@ public function testLockedEvictAll(): void
self::assertInstanceOf(Lock::class, $lock1 = $this->region->lock($key1));
self::assertInstanceOf(Lock::class, $lock2 = $this->region->lock($key2));

self::assertEquals($lock2->value, file_get_contents($file2));
self::assertEquals($lock1->value, file_get_contents($file1));
self::assertStringEqualsFile($file2, $lock2->value);
self::assertStringEqualsFile($file1, $lock1->value);

self::assertFileExists($file1);
self::assertFileExists($file2);
Expand Down Expand Up @@ -239,7 +239,7 @@ public function testLockLifetime(): void
self::assertTrue($this->region->contains($key));

self::assertInstanceOf(Lock::class, $lock = $this->region->lock($key));
self::assertEquals($lock->value, file_get_contents($file));
self::assertStringEqualsFile($file, $lock->value);
self::assertFileExists($file);

// outdated lock should be removed
Expand Down
22 changes: 11 additions & 11 deletions tests/Doctrine/Tests/ORM/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function setUp(): void

public function testSetGetProxyDir(): void
{
self::assertSame(null, $this->configuration->getProxyDir()); // defaults
self::assertNull($this->configuration->getProxyDir()); // defaults

$this->configuration->setProxyDir(__DIR__);
self::assertSame(__DIR__, $this->configuration->getProxyDir());
Expand All @@ -75,15 +75,15 @@ public function testSetGetAutoGenerateProxyClasses(): void

public function testSetGetProxyNamespace(): void
{
self::assertSame(null, $this->configuration->getProxyNamespace()); // defaults
self::assertNull($this->configuration->getProxyNamespace()); // defaults

$this->configuration->setProxyNamespace(__NAMESPACE__);
self::assertSame(__NAMESPACE__, $this->configuration->getProxyNamespace());
}

public function testSetGetMetadataDriverImpl(): void
{
self::assertSame(null, $this->configuration->getMetadataDriverImpl()); // defaults
self::assertNull($this->configuration->getMetadataDriverImpl()); // defaults

$metadataDriver = $this->createMock(MappingDriver::class);
$this->configuration->setMetadataDriverImpl($metadataDriver);
Expand Down Expand Up @@ -127,23 +127,23 @@ public function testSetGetEntityNamespace(): void

public function testSetGetQueryCacheImpl(): void
{
self::assertSame(null, $this->configuration->getQueryCacheImpl()); // defaults
self::assertNull($this->configuration->getQueryCacheImpl()); // defaults
$queryCacheImpl = $this->createMock(Cache::class);
$this->configuration->setQueryCacheImpl($queryCacheImpl);
self::assertSame($queryCacheImpl, $this->configuration->getQueryCacheImpl());
}

public function testSetGetHydrationCacheImpl(): void
{
self::assertSame(null, $this->configuration->getHydrationCacheImpl()); // defaults
self::assertNull($this->configuration->getHydrationCacheImpl()); // defaults
$queryCacheImpl = $this->createMock(Cache::class);
$this->configuration->setHydrationCacheImpl($queryCacheImpl);
self::assertSame($queryCacheImpl, $this->configuration->getHydrationCacheImpl());
}

public function testSetGetMetadataCacheImpl(): void
{
self::assertSame(null, $this->configuration->getMetadataCacheImpl()); // defaults
self::assertNull($this->configuration->getMetadataCacheImpl()); // defaults
$queryCacheImpl = $this->createMock(Cache::class);
$this->configuration->setMetadataCacheImpl($queryCacheImpl);
self::assertSame($queryCacheImpl, $this->configuration->getMetadataCacheImpl());
Expand Down Expand Up @@ -307,7 +307,7 @@ public function testAddGetCustomStringFunction(): void
{
$this->configuration->addCustomStringFunction('FunctionName', self::class);
self::assertSame(self::class, $this->configuration->getCustomStringFunction('FunctionName'));
self::assertSame(null, $this->configuration->getCustomStringFunction('NonExistingFunction'));
self::assertNull($this->configuration->getCustomStringFunction('NonExistingFunction'));
$this->configuration->setCustomStringFunctions(['OtherFunctionName' => self::class]);
self::assertSame(self::class, $this->configuration->getCustomStringFunction('OtherFunctionName'));
}
Expand All @@ -316,7 +316,7 @@ public function testAddGetCustomNumericFunction(): void
{
$this->configuration->addCustomNumericFunction('FunctionName', self::class);
self::assertSame(self::class, $this->configuration->getCustomNumericFunction('FunctionName'));
self::assertSame(null, $this->configuration->getCustomNumericFunction('NonExistingFunction'));
self::assertNull($this->configuration->getCustomNumericFunction('NonExistingFunction'));
$this->configuration->setCustomNumericFunctions(['OtherFunctionName' => self::class]);
self::assertSame(self::class, $this->configuration->getCustomNumericFunction('OtherFunctionName'));
}
Expand All @@ -325,14 +325,14 @@ public function testAddGetCustomDatetimeFunction(): void
{
$this->configuration->addCustomDatetimeFunction('FunctionName', self::class);
self::assertSame(self::class, $this->configuration->getCustomDatetimeFunction('FunctionName'));
self::assertSame(null, $this->configuration->getCustomDatetimeFunction('NonExistingFunction'));
self::assertNull($this->configuration->getCustomDatetimeFunction('NonExistingFunction'));
$this->configuration->setCustomDatetimeFunctions(['OtherFunctionName' => self::class]);
self::assertSame(self::class, $this->configuration->getCustomDatetimeFunction('OtherFunctionName'));
}

public function testAddGetCustomHydrationMode(): void
{
self::assertSame(null, $this->configuration->getCustomHydrationMode('NonExisting'));
self::assertNull($this->configuration->getCustomHydrationMode('NonExisting'));
$this->configuration->addCustomHydrationMode('HydrationModeName', self::class);
self::assertSame(self::class, $this->configuration->getCustomHydrationMode('HydrationModeName'));
}
Expand All @@ -359,7 +359,7 @@ public function testSetGetClassMetadataFactoryName(): void

public function testAddGetFilters(): void
{
self::assertSame(null, $this->configuration->getFilterClassName('NonExistingFilter'));
self::assertNull($this->configuration->getFilterClassName('NonExistingFilter'));
$this->configuration->addFilter('FilterName', self::class);
self::assertSame(self::class, $this->configuration->getFilterClassName('FilterName'));
}
Expand Down
24 changes: 6 additions & 18 deletions tests/Doctrine/Tests/ORM/Functional/AdvancedAssociationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function testIssue(): void
// test2 - eager load in DQL query
$query = $this->_em->createQuery('SELECT p,t FROM Doctrine\Tests\ORM\Functional\Phrase p JOIN p.type t');
$res = $query->getResult();
self::assertEquals(1, count($res));
self::assertCount(1, $res);
self::assertInstanceOf(PhraseType::class, $res[0]->getType());
self::assertInstanceOf(PersistentCollection::class, $res[0]->getType()->getPhrases());
self::assertFalse($res[0]->getType()->getPhrases()->isInitialized());
Expand All @@ -103,7 +103,7 @@ public function testIssue(): void
// test2 - eager load in DQL query with double-join back and forth
$query = $this->_em->createQuery('SELECT p,t,pp FROM Doctrine\Tests\ORM\Functional\Phrase p JOIN p.type t JOIN t.phrases pp');
$res = $query->getResult();
self::assertEquals(1, count($res));
self::assertCount(1, $res);
self::assertInstanceOf(PhraseType::class, $res[0]->getType());
self::assertInstanceOf(PersistentCollection::class, $res[0]->getType()->getPhrases());
self::assertTrue($res[0]->getType()->getPhrases()->isInitialized());
Expand Down Expand Up @@ -184,7 +184,7 @@ class Lemma
private $lemma;

/**
* @var kateglo\application\utilities\collections\ArrayCollection
* @var Collection
* @ManyToMany(targetEntity="Type", mappedBy="lemmas", cascade={"persist"})
*/
private $types;
Expand All @@ -209,9 +209,6 @@ public function getLemma(): string
return $this->lemma;
}

/**
* @param kateglo\application\models\Type $type
*/
public function addType(Type $type): void
{
if (! $this->types->contains($type)) {
Expand All @@ -220,9 +217,6 @@ public function addType(Type $type): void
}
}

/**
* @param kateglo\application\models\Type $type
*/
public function removeType(Type $type): void
{
$removed = $this->sources->removeElement($type);
Expand Down Expand Up @@ -266,7 +260,7 @@ class Type
private $abbreviation;

/**
* @var kateglo\application\helpers\collections\ArrayCollection
* @var Collection
* @ManyToMany(targetEntity="Lemma")
* @JoinTable(name="lemma_type",
* joinColumns={@JoinColumn(name="type_id", referencedColumnName="type_id")},
Expand Down Expand Up @@ -305,9 +299,6 @@ public function getAbbreviation(): string
return $this->abbreviation;
}

/**
* @param kateglo\application\models\Lemma $lemma
*/
public function addLemma(Lemma $lemma): void
{
if (! $this->lemmas->contains($lemma)) {
Expand All @@ -316,9 +307,6 @@ public function addLemma(Lemma $lemma): void
}
}

/**
* @param kateglo\application\models\Lemma $lemma
*/
public function removeLEmma(Lemma $lemma): void
{
$removed = $this->lemmas->removeElement($lemma);
Expand All @@ -327,7 +315,7 @@ public function removeLEmma(Lemma $lemma): void
}
}

public function getCategories(): kateglo\application\helpers\collections\ArrayCollection
public function getCategories(): Collection
{
return $this->categories;
}
Expand Down Expand Up @@ -534,7 +522,7 @@ public function removePhrase(): void
{
if ($this->phrase !== null) {
$phrase = $this->phrase;
assert($phrase instanceof kateglo\application\models\Phrase);
assert($phrase instanceof Phrase);
$this->phrase = null;
$phrase->removeDefinition($this);
}
Expand Down
18 changes: 9 additions & 9 deletions tests/Doctrine/Tests/ORM/Functional/AdvancedDqlQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function testCommentsInDQL(): void

$result = $this->_em->createQuery($dql)->getScalarResult();

self::assertEquals(2, count($result));
self::assertCount(2, $result);
self::assertEquals('IT', $result[0]['department']);
self::assertEquals(150000, $result[0]['avgSalary']);
self::assertEquals('IT2', $result[1]['department']);
Expand All @@ -66,7 +66,7 @@ public function testUnnamedScalarResultsAreOneBased(): void

$result = $this->_em->createQuery($dql)->getScalarResult();

self::assertEquals(2, count($result));
self::assertCount(2, $result);
self::assertEquals(150000, $result[0][1]);
self::assertEquals(600000, $result[1][1]);
}
Expand All @@ -80,7 +80,7 @@ public function testOrderByResultVariableCollectionSize(): void

$result = $this->_em->createQuery($dql)->getScalarResult();

self::assertEquals(4, count($result));
self::assertCount(4, $result);

self::assertEquals('Jonathan W.', $result[0]['name']);
self::assertEquals(3, $result[0]['friends']);
Expand Down Expand Up @@ -148,11 +148,11 @@ public function testIsNullAssociation(): void
$query = $this->_em->createQuery($dql);
$result = $query->getResult();

self::assertEquals(2, count($result));
self::assertTrue($result[0]->getId() > 0);
self::assertCount(2, $result);
self::assertGreaterThan(0, $result[0]->getId());
self::assertNull($result[0]->getSpouse());

self::assertTrue($result[1]->getId() > 0);
self::assertGreaterThan(0, $result[1]->getId());
self::assertNull($result[1]->getSpouse());

$this->_em->clear();
Expand All @@ -167,7 +167,7 @@ public function testSelectSubselect(): void
$query = $this->_em->createQuery($dql);
$result = $query->getArrayResult();

self::assertEquals(1, count($result));
self::assertCount(1, $result);
self::assertEquals('Caramba', $result[0]['brandName']);

$this->_em->clear();
Expand All @@ -182,7 +182,7 @@ public function testInSubselect(): void
$query = $this->_em->createQuery($dql);
$result = $query->getScalarResult();

self::assertEquals(1, count($result));
self::assertCount(1, $result);
self::assertEquals('Roman B.', $result[0]['name']);

$this->_em->clear();
Expand All @@ -197,7 +197,7 @@ public function testGroupByMultipleFields(): void
$query = $this->_em->createQuery($dql);
$result = $query->getResult();

self::assertEquals(4, count($result));
self::assertCount(4, $result);

$this->_em->clear();

Expand Down
Loading

0 comments on commit aee197f

Please sign in to comment.