1
0
mirror of synced 2025-03-06 12:56:10 +03:00

Use a more appropriate assertion on some tests

This commit is contained in:
Luís Cobucci 2017-05-31 14:05:43 +02:00
parent 8796e2d938
commit d8663cd9ee
No known key found for this signature in database
GPG Key ID: EC61C5F01750ED3C
4 changed files with 34 additions and 31 deletions

View File

@ -51,7 +51,7 @@ class ClassTableInheritanceTest extends OrmFunctionalTestCase
$entities = $query->getResult(); $entities = $query->getResult();
$this->assertEquals(2, count($entities)); $this->assertCount(2, $entities);
$this->assertInstanceOf(CompanyPerson::class, $entities[0]); $this->assertInstanceOf(CompanyPerson::class, $entities[0]);
$this->assertInstanceOf(CompanyEmployee::class, $entities[1]); $this->assertInstanceOf(CompanyEmployee::class, $entities[1]);
$this->assertTrue(is_numeric($entities[0]->getId())); $this->assertTrue(is_numeric($entities[0]->getId()));
@ -66,7 +66,7 @@ class ClassTableInheritanceTest extends OrmFunctionalTestCase
$entities = $query->getResult(); $entities = $query->getResult();
$this->assertEquals(1, count($entities)); $this->assertCount(1, $entities);
$this->assertInstanceOf(CompanyEmployee::class, $entities[0]); $this->assertInstanceOf(CompanyEmployee::class, $entities[0]);
$this->assertTrue(is_numeric($entities[0]->getId())); $this->assertTrue(is_numeric($entities[0]->getId()));
$this->assertEquals('Guilherme Blanco', $entities[0]->getName()); $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\''); $query = $this->_em->createQuery('select p, s from ' . CompanyPerson::class . ' p join p.spouse s where p.name=\'Mary Smith\'');
$result = $query->getResult(); $result = $query->getResult();
$this->assertEquals(1, count($result)); $this->assertCount(1, $result);
$this->assertInstanceOf(CompanyPerson::class, $result[0]); $this->assertInstanceOf(CompanyPerson::class, $result[0]);
$this->assertEquals('Mary Smith', $result[0]->getName()); $this->assertEquals('Mary Smith', $result[0]->getName());
$this->assertInstanceOf(CompanyEmployee::class, $result[0]->getSpouse()); $this->assertInstanceOf(CompanyEmployee::class, $result[0]->getSpouse());
@ -182,8 +182,8 @@ class ClassTableInheritanceTest extends OrmFunctionalTestCase
$person1->addFriend($person2); $person1->addFriend($person2);
$this->assertEquals(1, count($person1->getFriends())); $this->assertCount(1, $person1->getFriends());
$this->assertEquals(1, count($person2->getFriends())); $this->assertCount(1, $person2->getFriends());
$this->_em->persist($person1); $this->_em->persist($person1);
@ -197,8 +197,8 @@ class ClassTableInheritanceTest extends OrmFunctionalTestCase
$query->setParameter(1, 'Roman'); $query->setParameter(1, 'Roman');
$result = $query->getResult(); $result = $query->getResult();
$this->assertEquals(1, count($result)); $this->assertCount(1, $result);
$this->assertEquals(1, count($result[0]->getFriends())); $this->assertCount(1, $result[0]->getFriends());
$this->assertEquals('Roman', $result[0]->getName()); $this->assertEquals('Roman', $result[0]->getName());
$friends = $result[0]->getFriends(); $friends = $result[0]->getFriends();
@ -226,7 +226,7 @@ class ClassTableInheritanceTest extends OrmFunctionalTestCase
$result = $q->getResult(); $result = $q->getResult();
$this->assertEquals(1, count($result)); $this->assertCount(1, $result);
$this->assertInstanceOf(CompanyOrganization::class, $result[0]); $this->assertInstanceOf(CompanyOrganization::class, $result[0]);
$this->assertNull($result[0]->getMainEvent()); $this->assertNull($result[0]->getMainEvent());
@ -235,7 +235,7 @@ class ClassTableInheritanceTest extends OrmFunctionalTestCase
$this->assertInstanceOf(PersistentCollection::class, $events); $this->assertInstanceOf(PersistentCollection::class, $events);
$this->assertFalse($events->isInitialized()); $this->assertFalse($events->isInitialized());
$this->assertEquals(2, count($events)); $this->assertCount(2, $events);
if ($events[0] instanceof CompanyAuction) { if ($events[0] instanceof CompanyAuction) {
$this->assertInstanceOf(CompanyRaffle::class, $events[1]); $this->assertInstanceOf(CompanyRaffle::class, $events[1]);
} else { } else {
@ -259,7 +259,7 @@ class ClassTableInheritanceTest extends OrmFunctionalTestCase
$q->setParameter(1, $event1->getId()); $q->setParameter(1, $event1->getId());
$result = $q->getResult(); $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->assertInstanceOf(CompanyAuction::class, $result[0], sprintf("Is of class %s", get_class($result[0])));
$this->_em->clear(); $this->_em->clear();
@ -269,7 +269,7 @@ class ClassTableInheritanceTest extends OrmFunctionalTestCase
$result = $q->getResult(); $result = $q->getResult();
$this->assertEquals(1, count($result)); $this->assertCount(1, $result);
$this->assertInstanceOf(CompanyOrganization::class, $result[0]); $this->assertInstanceOf(CompanyOrganization::class, $result[0]);
$mainEvent = $result[0]->getMainEvent(); $mainEvent = $result[0]->getMainEvent();
@ -286,9 +286,10 @@ class ClassTableInheritanceTest extends OrmFunctionalTestCase
$this->_em->createQuery('UPDATE ' . CompanyEmployee::class . ' AS p SET p.salary = 1') $this->_em->createQuery('UPDATE ' . CompanyEmployee::class . ' AS p SET p.salary = 1')
->execute(); ->execute();
$this->assertTrue(count($this->_em->createQuery( $result = $this->_em->createQuery('SELECT count(p.id) FROM ' . CompanyEmployee::class . ' p WHERE p.salary = 1')
'SELECT count(p.id) FROM Doctrine\Tests\Models\Company\CompanyEmployee p WHERE p.salary = 1') ->getResult();
->getResult()) > 0);
$this->assertGreaterThan(0, count($result));
} }
/** /**
@ -441,7 +442,8 @@ class ClassTableInheritanceTest extends OrmFunctionalTestCase
$this->_em->clear(); $this->_em->clear();
$manager = $this->_em->find(CompanyManager::class, $manager->getId()); $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( $users = $repository->matching(new Criteria(
Criteria::expr()->eq('department', 'IT') Criteria::expr()->eq('department', 'IT')
)); ));
$this->assertEquals(1, count($users)); $this->assertCount(1, $users);
$repository = $this->_em->getRepository(CompanyManager::class); $repository = $this->_em->getRepository(CompanyManager::class);
$users = $repository->matching(new Criteria( $users = $repository->matching(new Criteria(
Criteria::expr()->eq('department', 'IT') Criteria::expr()->eq('department', 'IT')
)); ));
$this->assertEquals(1, count($users)); $this->assertCount(1, $users);
} }
} }

View File

@ -208,7 +208,7 @@ class QueryTest extends OrmFunctionalTestCase
} }
$this->assertEquals(1, count($found)); $this->assertEquals(1, count($found));
$this->assertEquals( $this->assertSame(
[ [
[ [
[ [
@ -256,8 +256,8 @@ class QueryTest extends OrmFunctionalTestCase
$iteratedCount++; $iteratedCount++;
} }
$this->assertEquals(["Doctrine 2", "Symfony 2"], $topics); $this->assertSame(["Doctrine 2", "Symfony 2"], $topics);
$this->assertEquals(2, $iteratedCount); $this->assertSame(2, $iteratedCount);
$this->_em->flush(); $this->_em->flush();
$this->_em->clear(); $this->_em->clear();
@ -293,8 +293,8 @@ class QueryTest extends OrmFunctionalTestCase
$iteratedCount++; $iteratedCount++;
} }
$this->assertEquals(["Doctrine 2", "Symfony 2"], $topics); $this->assertSame(["Doctrine 2", "Symfony 2"], $topics);
$this->assertEquals(2, $iteratedCount); $this->assertSame(2, $iteratedCount);
$this->_em->flush(); $this->_em->flush();
} }

View File

@ -32,8 +32,8 @@ class TypeTest extends OrmFunctionalTestCase
$dql = 'SELECT d FROM ' . DecimalModel::class . ' d'; $dql = 'SELECT d FROM ' . DecimalModel::class . ' d';
$decimal = $this->_em->createQuery($dql)->getSingleResult(); $decimal = $this->_em->createQuery($dql)->getSingleResult();
$this->assertEquals(0.15, $decimal->decimal); $this->assertSame('0.15', $decimal->decimal);
$this->assertEquals(0.1515, $decimal->highScale); $this->assertSame('0.1515', $decimal->highScale);
} }
/** /**
@ -78,7 +78,7 @@ class TypeTest extends OrmFunctionalTestCase
$dql = 'SELECT s FROM ' . SerializationModel::class . ' s'; $dql = 'SELECT s FROM ' . SerializationModel::class . ' s';
$serialize = $this->_em->createQuery($dql)->getSingleResult(); $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() public function testObject()
@ -108,7 +108,7 @@ class TypeTest extends OrmFunctionalTestCase
$dateTimeDb = $this->_em->find(DateTimeModel::class, $dateTime->id); $dateTimeDb = $this->_em->find(DateTimeModel::class, $dateTime->id);
$this->assertInstanceOf(\DateTime::class, $dateTimeDb->date); $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() public function testDateTime()
@ -123,11 +123,12 @@ class TypeTest extends OrmFunctionalTestCase
$dateTimeDb = $this->_em->find(DateTimeModel::class, $dateTime->id); $dateTimeDb = $this->_em->find(DateTimeModel::class, $dateTime->id);
$this->assertInstanceOf(\DateTime::class, $dateTimeDb->datetime); $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) $articles = $this->_em->getRepository(DateTimeModel::class)
->findBy(['datetime' => new \DateTime()]); ->findBy(['datetime' => new \DateTime()]);
$this->assertEquals(0, count($articles));
$this->assertEmpty($articles);
} }
public function testDqlQueryBindDateTimeInstance() public function testDqlQueryBindDateTimeInstance()
@ -177,6 +178,6 @@ class TypeTest extends OrmFunctionalTestCase
$dateTimeDb = $this->_em->find(DateTimeModel::class, $dateTime->id); $dateTimeDb = $this->_em->find(DateTimeModel::class, $dateTime->id);
$this->assertInstanceOf(\DateTime::class, $dateTimeDb->time); $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'));
} }
} }

View File

@ -37,8 +37,8 @@ class ScalarHydratorTest extends HydrationTestCase
$result = $hydrator->hydrateAll($stmt, $rsm); $result = $hydrator->hydrateAll($stmt, $rsm);
$this->assertTrue(is_array($result)); $this->assertInternalType('array', $result);
$this->assertEquals(2, count($result)); $this->assertCount(2, $result);
$this->assertEquals('romanb', $result[0]['u_name']); $this->assertEquals('romanb', $result[0]['u_name']);
$this->assertEquals(1, $result[0]['u_id']); $this->assertEquals(1, $result[0]['u_id']);
$this->assertEquals('jwage', $result[1]['u_name']); $this->assertEquals('jwage', $result[1]['u_name']);