1
0
mirror of synced 2024-12-05 03:06:05 +03:00

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

This commit is contained in:
Benjamin Eberlei 2011-06-18 22:47:21 +02:00
parent 1aa90dc872
commit 32b146ea8a
12 changed files with 96 additions and 12 deletions

View File

@ -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);

59
phpunit.xml.dist Normal file
View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Use this configuration file as a template to run the tests against any dbms.
Procedure:
1) Save a copy of this file with a name of your chosing. It doesn't matter
where you place it as long as you know where it is.
i.e. "mysqlconf.xml" (It needs the ending .xml).
2) Edit the file and fill in your settings (database name, type, username, etc.)
Just change the "value"s, not the names of the var elements.
3) To run the tests against the database type the following from within the
tests/ folder: phpunit -c <filename> ...
Example: phpunit -c mysqlconf.xml AllTests
-->
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/Doctrine/Tests/TestInit.php"
>
<testsuites>
<testsuite name="Doctrine ORM Test Suite">
<directory>./tests/Doctrine/Tests/ORM</directory>
</testsuite>
</testsuites>
<groups>
<exclude>
<group>performance</group>
<group>locking_functional</group>
</exclude>
</groups>
<php>
<!-- "Real" test database -->
<!-- uncomment, otherwise sqlite memory runs
<var name="db_type" value="pdo_mysql"/>
<var name="db_host" value="localhost" />
<var name="db_username" value="root" />
<var name="db_password" value="" />
<var name="db_name" value="doctrine_tests" />
<var name="db_port" value="3306"/>-->
<!--<var name="db_event_subscribers" value="Doctrine\DBAL\Event\Listeners\OracleSessionInit">-->
<!-- Database for temporary connections (i.e. to drop/create the main database) -->
<var name="tmpdb_type" value="pdo_mysql"/>
<var name="tmpdb_host" value="localhost" />
<var name="tmpdb_username" value="root" />
<var name="tmpdb_password" value="" />
<var name="tmpdb_name" value="doctrine_tests_tmp" />
<var name="tmpdb_port" value="3306"/>
</php>
</phpunit>

View File

@ -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;

View File

@ -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));
}
}

View File

@ -14,6 +14,7 @@ class DDC758Test extends \Doctrine\Tests\OrmFunctionalTestCase
public function setUp()
{
$this->markTestSkipped('Destroys testsuite');
$this->useModelSet("cms");
parent::setUp();

View File

@ -15,6 +15,7 @@ use Doctrine\Tests\Mocks\HydratorMockStatement,
* seriously degrade performance.
*
* @author robo
* @group performance
*/
class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase
{

View File

@ -7,6 +7,9 @@ use Doctrine\ORM\Query;
require_once __DIR__ . '/../../TestInit.php';
/**
* @group performance
*/
class InheritancePersisterPerformanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp()

View File

@ -10,6 +10,7 @@ use Doctrine\Tests\Models\CMS\CmsUser;
* Description of InsertPerformanceTest
*
* @author robo
* @group performance
*/
class InsertPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase
{

View File

@ -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()

View File

@ -10,6 +10,7 @@ use Doctrine\Tests\Models\CMS\CmsUser;
* Description of InsertPerformanceTest
*
* @author robo
* @group performance
*/
class UnitOfWorkPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase
{

View File

@ -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);
}

View File

@ -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()
);