Skip to content

Commit

Permalink
Refactoring more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carusogabriel authored and carnage committed Aug 9, 2021
1 parent c4456a2 commit 7714be1
Show file tree
Hide file tree
Showing 92 changed files with 605 additions and 618 deletions.
26 changes: 13 additions & 13 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,13 +179,13 @@ 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));
self::assertTrue($this->region->evict($key));
self::assertFalse($this->region->contains($key));
self::assertFileDoesNotExist($file);
self::assertFileNotExists($file);
}

public function testLockedEvictAll(): void
Expand All @@ -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
23 changes: 12 additions & 11 deletions tests/Doctrine/Tests/ORM/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Doctrine\ORM\Mapping as AnnotationNamespace;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\ORM\Mapping\DefaultEntityListenerResolver;
use Doctrine\ORM\Mapping\Driver\MappingDriver;
use Doctrine\ORM\Mapping\EntityListenerResolver;
use Doctrine\ORM\Mapping\NamingStrategy;
use Doctrine\ORM\Mapping\PrePersist;
Expand Down Expand Up @@ -53,7 +54,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 +76,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 +128,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 +308,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 +317,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 +326,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 +360,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
26 changes: 7 additions & 19 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,15 +103,15 @@ 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());

$this->_em->clear();

// test3 - lazy-loading one-to-many after find()
$phrase3 = $this->_em->find(Phrase::class, $phrase->getId());
$phrase3 = $this->em->find(Phrase::class, $phrase->getId());
$definitions = $phrase3->getDefinitions();
self::assertInstanceOf(PersistentCollection::class, $definitions);
self::assertInstanceOf(Definition::class, $definitions[0]);
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
19 changes: 10 additions & 9 deletions tests/Doctrine/Tests/ORM/Functional/AdvancedDqlQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Doctrine\Tests\Models\Company\CompanyCar;
use Doctrine\Tests\Models\Company\CompanyEmployee;
use Doctrine\Tests\Models\Company\CompanyManager;
use Doctrine\Tests\Models\Company\CompanyCar;
use Doctrine\Tests\OrmFunctionalTestCase;

use function count;
Expand Down Expand Up @@ -51,7 +52,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 +67,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 +81,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 +149,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 +168,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 +183,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 +198,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 7714be1

Please sign in to comment.