From d8663cd9ee9bb017fa6bf07fb4a65ae821b37190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 31 May 2017 14:05:43 +0200 Subject: [PATCH] Use a more appropriate assertion on some tests --- .../Functional/ClassTableInheritanceTest.php | 36 ++++++++++--------- .../Tests/ORM/Functional/QueryTest.php | 10 +++--- .../Tests/ORM/Functional/TypeTest.php | 15 ++++---- .../ORM/Hydration/ScalarHydratorTest.php | 4 +-- 4 files changed, 34 insertions(+), 31 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php index c94d3d73d..4ece24fa7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php @@ -51,7 +51,7 @@ class ClassTableInheritanceTest extends OrmFunctionalTestCase $entities = $query->getResult(); - $this->assertEquals(2, count($entities)); + $this->assertCount(2, $entities); $this->assertInstanceOf(CompanyPerson::class, $entities[0]); $this->assertInstanceOf(CompanyEmployee::class, $entities[1]); $this->assertTrue(is_numeric($entities[0]->getId())); @@ -66,7 +66,7 @@ class ClassTableInheritanceTest extends OrmFunctionalTestCase $entities = $query->getResult(); - $this->assertEquals(1, count($entities)); + $this->assertCount(1, $entities); $this->assertInstanceOf(CompanyEmployee::class, $entities[0]); $this->assertTrue(is_numeric($entities[0]->getId())); $this->assertEquals('Guilherme Blanco', $entities[0]->getName()); @@ -164,7 +164,7 @@ class ClassTableInheritanceTest extends OrmFunctionalTestCase $query = $this->_em->createQuery('select p, s from ' . CompanyPerson::class . ' p join p.spouse s where p.name=\'Mary Smith\''); $result = $query->getResult(); - $this->assertEquals(1, count($result)); + $this->assertCount(1, $result); $this->assertInstanceOf(CompanyPerson::class, $result[0]); $this->assertEquals('Mary Smith', $result[0]->getName()); $this->assertInstanceOf(CompanyEmployee::class, $result[0]->getSpouse()); @@ -182,8 +182,8 @@ class ClassTableInheritanceTest extends OrmFunctionalTestCase $person1->addFriend($person2); - $this->assertEquals(1, count($person1->getFriends())); - $this->assertEquals(1, count($person2->getFriends())); + $this->assertCount(1, $person1->getFriends()); + $this->assertCount(1, $person2->getFriends()); $this->_em->persist($person1); @@ -197,8 +197,8 @@ class ClassTableInheritanceTest extends OrmFunctionalTestCase $query->setParameter(1, 'Roman'); $result = $query->getResult(); - $this->assertEquals(1, count($result)); - $this->assertEquals(1, count($result[0]->getFriends())); + $this->assertCount(1, $result); + $this->assertCount(1, $result[0]->getFriends()); $this->assertEquals('Roman', $result[0]->getName()); $friends = $result[0]->getFriends(); @@ -226,7 +226,7 @@ class ClassTableInheritanceTest extends OrmFunctionalTestCase $result = $q->getResult(); - $this->assertEquals(1, count($result)); + $this->assertCount(1, $result); $this->assertInstanceOf(CompanyOrganization::class, $result[0]); $this->assertNull($result[0]->getMainEvent()); @@ -235,7 +235,7 @@ class ClassTableInheritanceTest extends OrmFunctionalTestCase $this->assertInstanceOf(PersistentCollection::class, $events); $this->assertFalse($events->isInitialized()); - $this->assertEquals(2, count($events)); + $this->assertCount(2, $events); if ($events[0] instanceof CompanyAuction) { $this->assertInstanceOf(CompanyRaffle::class, $events[1]); } else { @@ -259,7 +259,7 @@ class ClassTableInheritanceTest extends OrmFunctionalTestCase $q->setParameter(1, $event1->getId()); $result = $q->getResult(); - $this->assertEquals(1, count($result)); + $this->assertCount(1, $result); $this->assertInstanceOf(CompanyAuction::class, $result[0], sprintf("Is of class %s", get_class($result[0]))); $this->_em->clear(); @@ -269,7 +269,7 @@ class ClassTableInheritanceTest extends OrmFunctionalTestCase $result = $q->getResult(); - $this->assertEquals(1, count($result)); + $this->assertCount(1, $result); $this->assertInstanceOf(CompanyOrganization::class, $result[0]); $mainEvent = $result[0]->getMainEvent(); @@ -286,9 +286,10 @@ class ClassTableInheritanceTest extends OrmFunctionalTestCase $this->_em->createQuery('UPDATE ' . CompanyEmployee::class . ' AS p SET p.salary = 1') ->execute(); - $this->assertTrue(count($this->_em->createQuery( - 'SELECT count(p.id) FROM Doctrine\Tests\Models\Company\CompanyEmployee p WHERE p.salary = 1') - ->getResult()) > 0); + $result = $this->_em->createQuery('SELECT count(p.id) FROM ' . CompanyEmployee::class . ' p WHERE p.salary = 1') + ->getResult(); + + $this->assertGreaterThan(0, count($result)); } /** @@ -441,7 +442,8 @@ class ClassTableInheritanceTest extends OrmFunctionalTestCase $this->_em->clear(); $manager = $this->_em->find(CompanyManager::class, $manager->getId()); - $this->assertEquals(1, count($manager->getFriends())); + + $this->assertCount(1, $manager->getFriends()); } /** @@ -481,12 +483,12 @@ class ClassTableInheritanceTest extends OrmFunctionalTestCase $users = $repository->matching(new Criteria( Criteria::expr()->eq('department', 'IT') )); - $this->assertEquals(1, count($users)); + $this->assertCount(1, $users); $repository = $this->_em->getRepository(CompanyManager::class); $users = $repository->matching(new Criteria( Criteria::expr()->eq('department', 'IT') )); - $this->assertEquals(1, count($users)); + $this->assertCount(1, $users); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php index 127f06d18..af4656960 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php @@ -208,7 +208,7 @@ class QueryTest extends OrmFunctionalTestCase } $this->assertEquals(1, count($found)); - $this->assertEquals( + $this->assertSame( [ [ [ @@ -256,8 +256,8 @@ class QueryTest extends OrmFunctionalTestCase $iteratedCount++; } - $this->assertEquals(["Doctrine 2", "Symfony 2"], $topics); - $this->assertEquals(2, $iteratedCount); + $this->assertSame(["Doctrine 2", "Symfony 2"], $topics); + $this->assertSame(2, $iteratedCount); $this->_em->flush(); $this->_em->clear(); @@ -293,8 +293,8 @@ class QueryTest extends OrmFunctionalTestCase $iteratedCount++; } - $this->assertEquals(["Doctrine 2", "Symfony 2"], $topics); - $this->assertEquals(2, $iteratedCount); + $this->assertSame(["Doctrine 2", "Symfony 2"], $topics); + $this->assertSame(2, $iteratedCount); $this->_em->flush(); } diff --git a/tests/Doctrine/Tests/ORM/Functional/TypeTest.php b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php index 9276d74ee..0f5c7e223 100644 --- a/tests/Doctrine/Tests/ORM/Functional/TypeTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php @@ -32,8 +32,8 @@ class TypeTest extends OrmFunctionalTestCase $dql = 'SELECT d FROM ' . DecimalModel::class . ' d'; $decimal = $this->_em->createQuery($dql)->getSingleResult(); - $this->assertEquals(0.15, $decimal->decimal); - $this->assertEquals(0.1515, $decimal->highScale); + $this->assertSame('0.15', $decimal->decimal); + $this->assertSame('0.1515', $decimal->highScale); } /** @@ -78,7 +78,7 @@ class TypeTest extends OrmFunctionalTestCase $dql = 'SELECT s FROM ' . SerializationModel::class . ' s'; $serialize = $this->_em->createQuery($dql)->getSingleResult(); - $this->assertEquals(["foo" => "bar", "bar" => "baz"], $serialize->array); + $this->assertSame(["foo" => "bar", "bar" => "baz"], $serialize->array); } public function testObject() @@ -108,7 +108,7 @@ class TypeTest extends OrmFunctionalTestCase $dateTimeDb = $this->_em->find(DateTimeModel::class, $dateTime->id); $this->assertInstanceOf(\DateTime::class, $dateTimeDb->date); - $this->assertEquals('2009-10-01', $dateTimeDb->date->format('Y-m-d')); + $this->assertSame('2009-10-01', $dateTimeDb->date->format('Y-m-d')); } public function testDateTime() @@ -123,11 +123,12 @@ class TypeTest extends OrmFunctionalTestCase $dateTimeDb = $this->_em->find(DateTimeModel::class, $dateTime->id); $this->assertInstanceOf(\DateTime::class, $dateTimeDb->datetime); - $this->assertEquals('2009-10-02 20:10:52', $dateTimeDb->datetime->format('Y-m-d H:i:s')); + $this->assertSame('2009-10-02 20:10:52', $dateTimeDb->datetime->format('Y-m-d H:i:s')); $articles = $this->_em->getRepository(DateTimeModel::class) ->findBy(['datetime' => new \DateTime()]); - $this->assertEquals(0, count($articles)); + + $this->assertEmpty($articles); } public function testDqlQueryBindDateTimeInstance() @@ -177,6 +178,6 @@ class TypeTest extends OrmFunctionalTestCase $dateTimeDb = $this->_em->find(DateTimeModel::class, $dateTime->id); $this->assertInstanceOf(\DateTime::class, $dateTimeDb->time); - $this->assertEquals('19:27:20', $dateTimeDb->time->format('H:i:s')); + $this->assertSame('19:27:20', $dateTimeDb->time->format('H:i:s')); } } diff --git a/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php index 2c51929bc..85a197cba 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php @@ -37,8 +37,8 @@ class ScalarHydratorTest extends HydrationTestCase $result = $hydrator->hydrateAll($stmt, $rsm); - $this->assertTrue(is_array($result)); - $this->assertEquals(2, count($result)); + $this->assertInternalType('array', $result); + $this->assertCount(2, $result); $this->assertEquals('romanb', $result[0]['u_name']); $this->assertEquals(1, $result[0]['u_id']); $this->assertEquals('jwage', $result[1]['u_name']);