From 32b146ea8ad9484bfbb522b3d7ead8f01803a628 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 18 Jun 2011 22:47:21 +0200 Subject: [PATCH] Switch testsuite to run with phpunit.ini.dist from main folder, not using AllTests approach. Fixed global state problem in tests that was caused by EventManager being reused. Significantly enhanced error message about cascade persist --- lib/Doctrine/ORM/UnitOfWork.php | 8 ++- phpunit.xml.dist | 59 +++++++++++++++++++ .../Functional/Locking/GearmanLockTest.php | 3 + .../ORM/Functional/SchemaTool/DDC214Test.php | 9 ++- .../ORM/Functional/Ticket/DDC758Test.php | 1 + .../Performance/HydrationPerformanceTest.php | 1 + .../InheritancePersisterPerformanceTest.php | 3 + .../ORM/Performance/InsertPerformanceTest.php | 1 + .../Performance/PersisterPerformanceTest.php | 3 + .../Performance/UnitOfWorkPerformanceTest.php | 1 + .../Doctrine/Tests/OrmFunctionalTestCase.php | 8 +++ tests/Doctrine/Tests/TestInit.php | 11 ++-- 12 files changed, 96 insertions(+), 12 deletions(-) create mode 100644 phpunit.xml.dist diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index e53f38c52..8279c8554 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -573,10 +573,12 @@ class UnitOfWork implements PropertyChangedListener $oid = spl_object_hash($entry); if ($state == self::STATE_NEW) { if ( ! $assoc['isCascadePersist']) { - throw new InvalidArgumentException("A new entity was found through a relationship that was not" - . " configured to cascade persist operations: " . self::objToStr($entry) . "." + throw new InvalidArgumentException("A new entity was found through the relationship '" + . $assoc['sourceEntity'] . "#" . $assoc['fieldName'] . "' that was not" + . " configured to cascade persist operations for entity: " . self::objToStr($entry) . "." . " Explicitly persist the new entity or configure cascading persist operations" - . " on the relationship."); + . " on the relationship. If you cannot find out which entity casues the problem" + . " implement '" . $assoc['targetEntity'] . "#__toString()' to get a clue."); } $this->persistNew($targetClass, $entry); $this->computeChangeSet($targetClass, $entry); diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 000000000..3ab5edbae --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,59 @@ + + + + + + + ./tests/Doctrine/Tests/ORM + + + + + + performance + locking_functional + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php index c1d4037d3..a597cc207 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php @@ -9,6 +9,9 @@ use Doctrine\Tests\Models\CMS\CmsArticle, require_once __DIR__ . '/../../../TestInit.php'; +/** + * @group locking_functional + */ class GearmanLockTest extends \Doctrine\Tests\OrmFunctionalTestCase { private $gearman = null; diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php index e4e5e69a0..fb58bf07f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php @@ -68,8 +68,11 @@ class DDC214Test extends \Doctrine\Tests\OrmFunctionalTestCase $classMetadata[] = $this->_em->getClassMetadata($class); } - $this->schemaTool->dropDatabase(); - $this->schemaTool->createSchema($classMetadata); + try { + $this->schemaTool->createSchema($classMetadata); + } catch(\Exception $e) { + // was already created + } $sm = $this->_em->getConnection()->getSchemaManager(); @@ -80,6 +83,8 @@ class DDC214Test extends \Doctrine\Tests\OrmFunctionalTestCase $schemaDiff = $comparator->compare($fromSchema, $toSchema); $sql = $schemaDiff->toSql($this->_em->getConnection()->getDatabasePlatform()); + $sql = array_filter($sql, function($sql) { return strpos($sql, 'DROP') === false; }); + $this->assertEquals(0, count($sql), "SQL: " . implode(PHP_EOL, $sql)); } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC758Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC758Test.php index 60a0ff89c..76bb3bba8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC758Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC758Test.php @@ -14,6 +14,7 @@ class DDC758Test extends \Doctrine\Tests\OrmFunctionalTestCase public function setUp() { + $this->markTestSkipped('Destroys testsuite'); $this->useModelSet("cms"); parent::setUp(); diff --git a/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php index a8a16e428..01f02c0d9 100644 --- a/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php @@ -15,6 +15,7 @@ use Doctrine\Tests\Mocks\HydratorMockStatement, * seriously degrade performance. * * @author robo + * @group performance */ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase { diff --git a/tests/Doctrine/Tests/ORM/Performance/InheritancePersisterPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/InheritancePersisterPerformanceTest.php index 01113f21b..1c192648a 100644 --- a/tests/Doctrine/Tests/ORM/Performance/InheritancePersisterPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/InheritancePersisterPerformanceTest.php @@ -7,6 +7,9 @@ use Doctrine\ORM\Query; require_once __DIR__ . '/../../TestInit.php'; +/** +* @group performance + */ class InheritancePersisterPerformanceTest extends \Doctrine\Tests\OrmFunctionalTestCase { protected function setUp() diff --git a/tests/Doctrine/Tests/ORM/Performance/InsertPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/InsertPerformanceTest.php index 97466e69f..cccc480a2 100644 --- a/tests/Doctrine/Tests/ORM/Performance/InsertPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/InsertPerformanceTest.php @@ -10,6 +10,7 @@ use Doctrine\Tests\Models\CMS\CmsUser; * Description of InsertPerformanceTest * * @author robo + * @group performance */ class InsertPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase { diff --git a/tests/Doctrine/Tests/ORM/Performance/PersisterPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/PersisterPerformanceTest.php index bbd4f445f..ec432689d 100644 --- a/tests/Doctrine/Tests/ORM/Performance/PersisterPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/PersisterPerformanceTest.php @@ -13,6 +13,9 @@ use Doctrine\Tests\Models\CMS\CmsComment; require_once __DIR__ . '/../../TestInit.php'; +/** + * @group performance + */ class PersisterPerformanceTest extends \Doctrine\Tests\OrmFunctionalTestCase { protected function setUp() diff --git a/tests/Doctrine/Tests/ORM/Performance/UnitOfWorkPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/UnitOfWorkPerformanceTest.php index 28d9ea6d3..650228ba4 100644 --- a/tests/Doctrine/Tests/ORM/Performance/UnitOfWorkPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/UnitOfWorkPerformanceTest.php @@ -10,6 +10,7 @@ use Doctrine\Tests\Models\CMS\CmsUser; * Description of InsertPerformanceTest * * @author robo + * @group performance */ class UnitOfWorkPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase { diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 166cdfb6a..516a72aa2 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -288,6 +288,14 @@ abstract class OrmFunctionalTestCase extends OrmTestCase $conn = static::$_sharedConn; $conn->getConfiguration()->setSQLLogger($this->_sqlLoggerStack); + + // get rid of more global state + $evm = $conn->getEventManager(); + foreach ($evm->getListeners() AS $event => $listeners) { + foreach ($listeners AS $listener) { + $evm->removeEventListener(array($event), $listener); + } + } return \Doctrine\ORM\EntityManager::create($conn, $config); } diff --git a/tests/Doctrine/Tests/TestInit.php b/tests/Doctrine/Tests/TestInit.php index 0445cf76b..3a35c2104 100644 --- a/tests/Doctrine/Tests/TestInit.php +++ b/tests/Doctrine/Tests/TestInit.php @@ -22,7 +22,10 @@ if (isset($GLOBALS['DOCTRINE_DBAL_PATH'])) { } $classLoader->register(); -$classLoader = new \Doctrine\Common\ClassLoader('Doctrine'); +$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\ORM', __DIR__ . '/../../../lib'); +$classLoader->register(); + +$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\Tests', __DIR__ . '/../../'); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('Symfony', __DIR__ . "/../../../lib/vendor"); @@ -38,9 +41,3 @@ if (!file_exists(__DIR__."/ORM/Proxy/generated")) { throw new Exception("Could not create " . __DIR__."/ORM/Proxy/generated Folder."); } } - -set_include_path( - __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'lib' - . PATH_SEPARATOR . - get_include_path() -); \ No newline at end of file