From 1bf884970f2e4c75e817dd4db5532e8bb44a5f2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 31 May 2017 08:05:01 +0200 Subject: [PATCH] Increment assertion count manually Which is needed to test void methods that shouldn't raise any exception on a certain condition. If the interpreter gets to the point where the assertion count is incremented it means that no exceptions have been thrown and our test is successful. Important to note that some tests were slighly refactored to simplify things a bit. --- .../Doctrine/Tests/ORM/ConfigurationTest.php | 2 + .../Functional/ClassTableInheritanceTest.php | 1 + .../Tests/ORM/Functional/Locking/LockTest.php | 2 + .../ORM/Functional/Locking/OptimisticTest.php | 2 + .../ORM/Functional/PersistentObjectTest.php | 2 + .../ORM/Functional/Ticket/DDC3170Test.php | 30 +++----- .../ORM/Functional/Ticket/DDC588Test.php | 2 + .../ORM/Functional/Ticket/DDC742Test.php | 1 + .../Tests/ORM/Tools/SchemaValidatorTest.php | 70 +++++-------------- 9 files changed, 39 insertions(+), 73 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/ConfigurationTest.php b/tests/Doctrine/Tests/ORM/ConfigurationTest.php index df74c6df2..ab657c5fd 100644 --- a/tests/Doctrine/Tests/ORM/ConfigurationTest.php +++ b/tests/Doctrine/Tests/ORM/ConfigurationTest.php @@ -179,6 +179,8 @@ class ConfigurationTest extends TestCase { $this->setProductionSettings(); $this->configuration->ensureProductionSettings(); + + $this->addToAssertionCount(1); } public function testEnsureProductionSettingsQueryCache() diff --git a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php index 02ed0a356..c94d3d73d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php @@ -301,6 +301,7 @@ class ClassTableInheritanceTest extends OrmFunctionalTestCase ->setParameter(1, 'IT') ->execute(); + $this->addToAssertionCount(1); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php index dc27d45be..d515e95bf 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php @@ -37,6 +37,8 @@ class LockTest extends OrmFunctionalTestCase $this->_em->flush(); $this->_em->lock($article, LockMode::OPTIMISTIC, $article->version); + + $this->addToAssertionCount(1); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php index 3681ed95e..8b8113b6a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php @@ -178,6 +178,8 @@ class OptimisticTest extends OrmFunctionalTestCase $proxy = $this->_em->getReference(OptimisticStandard::class, $test->id); $this->_em->lock($proxy, LockMode::OPTIMISTIC, 1); + + $this->addToAssertionCount(1); } public function testOptimisticTimestampSetsDefaultValue() diff --git a/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php b/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php index b611c7125..0fd2b4745 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php @@ -36,6 +36,8 @@ class PersistentObjectTest extends OrmFunctionalTestCase $this->_em->persist($entity); $this->_em->flush(); + + $this->addToAssertionCount(1); } public function testFind() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php index 88e3727d2..0ef1caee8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php @@ -46,27 +46,17 @@ class DDC3170Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->flush(); $this->_em->clear(); - try { - $this->_em->createQueryBuilder() - ->select('p') - ->from(DDC3170ProductJoined::class, 'p') - ->getQuery() - ->getResult(AbstractQuery::HYDRATE_SIMPLEOBJECT); - } catch (HydrationException $e) // Thrown by SimpleObjectHydrator - { - $this->fail('Failed correct mapping of discriminator column when using simple object hydration and class table inheritance'); - } + $this->_em->createQueryBuilder() + ->select('p') + ->from(DDC3170ProductJoined::class, 'p') + ->getQuery() + ->getResult(AbstractQuery::HYDRATE_SIMPLEOBJECT); - try { - $this->_em->createQueryBuilder() - ->select('p') - ->from(DDC3170ProductSingleTable::class, 'p') - ->getQuery() - ->getResult(AbstractQuery::HYDRATE_SIMPLEOBJECT); - } catch (HydrationException $e) // Thrown by SimpleObjectHydrator - { - $this->fail('Failed correct mapping of discriminator column when using simple object hydration and single table inheritance'); - } + $this->_em->createQueryBuilder() + ->select('p') + ->from(DDC3170ProductSingleTable::class, 'p') + ->getQuery() + ->getResult(AbstractQuery::HYDRATE_SIMPLEOBJECT); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC588Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC588Test.php index aa50f2cdb..7361bc4f4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC588Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC588Test.php @@ -23,6 +23,8 @@ class DDC588Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->flush(); // Following should not result in exception $this->_em->refresh($site); + + $this->addToAssertionCount(1); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC742Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC742Test.php index bc465db92..8adcb0879 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC742Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC742Test.php @@ -68,6 +68,7 @@ class DDC742Test extends \Doctrine\Tests\OrmFunctionalTestCase $user->favoriteComments->add($this->_em->find(DDC742Comment::class, $comment3->id)); $this->_em->flush(); + $this->addToAssertionCount(1); } } diff --git a/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php b/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php index ea2826309..955a5f43d 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php @@ -24,64 +24,28 @@ class SchemaValidatorTest extends OrmTestCase $this->validator = new SchemaValidator($this->em); } - public function testCmsModelSet() + /** + * @dataProvider modelSetProvider + */ + public function testCmsModelSet(string $path) { - $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths( - [ - __DIR__ . "/../../Models/CMS" - ] - ); + $this->em->getConfiguration() + ->getMetadataDriverImpl() + ->addPaths([$path]); + $this->validator->validateMapping(); } - public function testCompanyModelSet() + public function modelSetProvider(): array { - $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths( - [ - __DIR__ . "/../../Models/Company" - ] - ); - $this->validator->validateMapping(); - } - - public function testECommerceModelSet() - { - $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths( - [ - __DIR__ . "/../../Models/ECommerce" - ] - ); - $this->validator->validateMapping(); - } - - public function testForumModelSet() - { - $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths( - [ - __DIR__ . "/../../Models/Forum" - ] - ); - $this->validator->validateMapping(); - } - - public function testNavigationModelSet() - { - $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths( - [ - __DIR__ . "/../../Models/Navigation" - ] - ); - $this->validator->validateMapping(); - } - - public function testRoutingModelSet() - { - $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths( - [ - __DIR__ . "/../../Models/Routing" - ] - ); - $this->validator->validateMapping(); + return [ + 'cms' => [__DIR__ . '/../../Models/CMS'], + 'company' => [__DIR__ . '/../../Models/Company'], + 'ecommerce' => [__DIR__ . '/../../Models/ECommerce'], + 'forum' => [__DIR__ . '/../../Models/Forum'], + 'navigation' => [__DIR__ . '/../../Models/Navigation'], + 'routing' => [__DIR__ . '/../../Models/Routing'], + ]; } /**