2008-05-24 21:37:26 +04:00
|
|
|
<?php
|
2009-01-04 19:15:32 +03:00
|
|
|
|
2009-01-22 22:38:10 +03:00
|
|
|
namespace Doctrine\Tests;
|
2009-01-04 19:15:32 +03:00
|
|
|
|
2008-05-24 21:37:26 +04:00
|
|
|
/**
|
2009-03-30 23:43:05 +04:00
|
|
|
* Base testcase class for all functional ORM testcases.
|
2008-05-24 21:37:26 +04:00
|
|
|
*
|
2009-02-04 21:03:05 +03:00
|
|
|
* @since 2.0
|
2008-05-24 21:37:26 +04:00
|
|
|
*/
|
2010-01-31 17:35:10 +03:00
|
|
|
abstract class OrmFunctionalTestCase extends OrmTestCase
|
2008-05-24 21:37:26 +04:00
|
|
|
{
|
2009-02-04 21:03:05 +03:00
|
|
|
/* The metadata cache shared between all functional tests. */
|
|
|
|
private static $_metadataCacheImpl = null;
|
2009-05-21 23:18:14 +04:00
|
|
|
/* The query cache shared between all functional tests. */
|
|
|
|
private static $_queryCacheImpl = null;
|
2009-02-04 21:03:05 +03:00
|
|
|
|
2009-05-30 14:30:05 +04:00
|
|
|
/* Shared connection when a TestCase is run alone (outside of it's functional suite) */
|
2010-04-14 22:20:44 +04:00
|
|
|
protected static $_sharedConn;
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2009-11-04 14:39:49 +03:00
|
|
|
/**
|
|
|
|
* @var \Doctrine\ORM\EntityManager
|
|
|
|
*/
|
2009-01-12 16:34:41 +03:00
|
|
|
protected $_em;
|
|
|
|
|
2009-11-04 14:39:49 +03:00
|
|
|
/**
|
|
|
|
* @var \Doctrine\ORM\Tools\SchemaTool
|
|
|
|
*/
|
2009-03-30 23:43:05 +04:00
|
|
|
protected $_schemaTool;
|
2009-03-28 23:59:07 +03:00
|
|
|
|
2009-11-04 14:39:49 +03:00
|
|
|
/**
|
|
|
|
* @var \Doctrine\DBAL\Logging\DebugStack
|
|
|
|
*/
|
|
|
|
protected $_sqlLoggerStack;
|
|
|
|
|
2009-03-30 23:43:05 +04:00
|
|
|
/** The names of the model sets used in this testcase. */
|
2010-04-14 22:20:44 +04:00
|
|
|
protected $_usedModelSets = array();
|
2009-03-30 23:43:05 +04:00
|
|
|
|
|
|
|
/** Whether the database schema has already been created. */
|
2010-04-14 22:20:44 +04:00
|
|
|
protected static $_tablesCreated = array();
|
2009-03-30 23:43:05 +04:00
|
|
|
|
2012-02-20 13:33:16 +04:00
|
|
|
/**
|
|
|
|
* Array of entity class name to their tables that were created.
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected static $_entityTablesCreated = array();
|
|
|
|
|
2009-03-30 23:43:05 +04:00
|
|
|
/** List of model sets and their classes. */
|
2010-04-14 22:20:44 +04:00
|
|
|
protected static $_modelSets = array(
|
2009-03-30 23:43:05 +04:00
|
|
|
'cms' => array(
|
|
|
|
'Doctrine\Tests\Models\CMS\CmsUser',
|
|
|
|
'Doctrine\Tests\Models\CMS\CmsPhonenumber',
|
|
|
|
'Doctrine\Tests\Models\CMS\CmsAddress',
|
2011-09-07 20:12:02 +04:00
|
|
|
'Doctrine\Tests\Models\CMS\CmsEmail',
|
2009-04-09 22:12:48 +04:00
|
|
|
'Doctrine\Tests\Models\CMS\CmsGroup',
|
2010-07-08 19:30:39 +04:00
|
|
|
'Doctrine\Tests\Models\CMS\CmsArticle',
|
|
|
|
'Doctrine\Tests\Models\CMS\CmsComment',
|
2009-03-30 23:43:05 +04:00
|
|
|
),
|
|
|
|
'forum' => array(),
|
2009-05-21 12:53:40 +04:00
|
|
|
'company' => array(
|
|
|
|
'Doctrine\Tests\Models\Company\CompanyPerson',
|
|
|
|
'Doctrine\Tests\Models\Company\CompanyEmployee',
|
2009-09-15 16:24:38 +04:00
|
|
|
'Doctrine\Tests\Models\Company\CompanyManager',
|
|
|
|
'Doctrine\Tests\Models\Company\CompanyOrganization',
|
|
|
|
'Doctrine\Tests\Models\Company\CompanyEvent',
|
|
|
|
'Doctrine\Tests\Models\Company\CompanyAuction',
|
2009-10-28 14:06:36 +03:00
|
|
|
'Doctrine\Tests\Models\Company\CompanyRaffle',
|
2010-07-04 14:17:15 +04:00
|
|
|
'Doctrine\Tests\Models\Company\CompanyCar',
|
|
|
|
'Doctrine\Tests\Models\Company\CompanyContract',
|
2009-05-21 12:53:40 +04:00
|
|
|
),
|
2009-07-01 13:18:08 +04:00
|
|
|
'ecommerce' => array(
|
|
|
|
'Doctrine\Tests\Models\ECommerce\ECommerceCart',
|
2009-07-01 16:03:41 +04:00
|
|
|
'Doctrine\Tests\Models\ECommerce\ECommerceCustomer',
|
|
|
|
'Doctrine\Tests\Models\ECommerce\ECommerceProduct',
|
2009-07-01 17:11:45 +04:00
|
|
|
'Doctrine\Tests\Models\ECommerce\ECommerceShipping',
|
2009-07-02 13:37:59 +04:00
|
|
|
'Doctrine\Tests\Models\ECommerce\ECommerceFeature',
|
|
|
|
'Doctrine\Tests\Models\ECommerce\ECommerceCategory'
|
2009-07-01 13:18:08 +04:00
|
|
|
),
|
2009-06-20 16:59:33 +04:00
|
|
|
'generic' => array(
|
2010-02-26 22:39:12 +03:00
|
|
|
'Doctrine\Tests\Models\Generic\BooleanModel',
|
|
|
|
'Doctrine\Tests\Models\Generic\DateTimeModel',
|
|
|
|
'Doctrine\Tests\Models\Generic\DecimalModel',
|
|
|
|
'Doctrine\Tests\Models\Generic\SerializationModel',
|
2010-01-31 17:35:10 +03:00
|
|
|
),
|
|
|
|
'routing' => array(
|
|
|
|
'Doctrine\Tests\Models\Routing\RoutingLeg',
|
|
|
|
'Doctrine\Tests\Models\Routing\RoutingLocation',
|
|
|
|
'Doctrine\Tests\Models\Routing\RoutingRoute',
|
2010-02-15 00:26:15 +03:00
|
|
|
'Doctrine\Tests\Models\Routing\RoutingRouteBooking',
|
2010-01-31 17:35:10 +03:00
|
|
|
),
|
2010-04-03 18:38:06 +04:00
|
|
|
'navigation' => array(
|
|
|
|
'Doctrine\Tests\Models\Navigation\NavCountry',
|
|
|
|
'Doctrine\Tests\Models\Navigation\NavPhotos',
|
|
|
|
'Doctrine\Tests\Models\Navigation\NavTour',
|
|
|
|
'Doctrine\Tests\Models\Navigation\NavPointOfInterest',
|
|
|
|
),
|
2010-09-22 02:15:45 +04:00
|
|
|
'directorytree' => array(
|
|
|
|
'Doctrine\Tests\Models\DirectoryTree\AbstractContentItem',
|
|
|
|
'Doctrine\Tests\Models\DirectoryTree\File',
|
|
|
|
'Doctrine\Tests\Models\DirectoryTree\Directory',
|
|
|
|
),
|
2011-01-01 20:17:19 +03:00
|
|
|
'ddc117' => array(
|
|
|
|
'Doctrine\Tests\Models\DDC117\DDC117Article',
|
|
|
|
'Doctrine\Tests\Models\DDC117\DDC117Reference',
|
|
|
|
'Doctrine\Tests\Models\DDC117\DDC117Translation',
|
|
|
|
'Doctrine\Tests\Models\DDC117\DDC117ArticleDetails',
|
|
|
|
'Doctrine\Tests\Models\DDC117\DDC117ApproveChanges',
|
|
|
|
'Doctrine\Tests\Models\DDC117\DDC117Editor',
|
2011-07-28 01:22:20 +04:00
|
|
|
'Doctrine\Tests\Models\DDC117\DDC117Link',
|
2011-01-01 20:17:19 +03:00
|
|
|
),
|
2011-02-05 13:42:10 +03:00
|
|
|
'stockexchange' => array(
|
|
|
|
'Doctrine\Tests\Models\StockExchange\Bond',
|
|
|
|
'Doctrine\Tests\Models\StockExchange\Stock',
|
|
|
|
'Doctrine\Tests\Models\StockExchange\Market',
|
|
|
|
),
|
2011-07-28 12:46:38 +04:00
|
|
|
'legacy' => array(
|
|
|
|
'Doctrine\Tests\Models\Legacy\LegacyUser',
|
|
|
|
'Doctrine\Tests\Models\Legacy\LegacyUserReference',
|
|
|
|
'Doctrine\Tests\Models\Legacy\LegacyArticle',
|
|
|
|
'Doctrine\Tests\Models\Legacy\LegacyCar',
|
|
|
|
),
|
2011-11-19 03:35:29 +04:00
|
|
|
'customtype' => array(
|
|
|
|
'Doctrine\Tests\Models\CustomType\CustomTypeChild',
|
|
|
|
'Doctrine\Tests\Models\CustomType\CustomTypeParent',
|
|
|
|
'Doctrine\Tests\Models\CustomType\CustomTypeUpperCase',
|
|
|
|
),
|
2009-03-30 23:43:05 +04:00
|
|
|
);
|
|
|
|
|
|
|
|
protected function useModelSet($setName)
|
2008-05-24 21:37:26 +04:00
|
|
|
{
|
2009-05-21 12:53:40 +04:00
|
|
|
$this->_usedModelSets[$setName] = true;
|
2008-05-24 21:37:26 +04:00
|
|
|
}
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2008-05-24 21:37:26 +04:00
|
|
|
/**
|
2009-03-30 23:43:05 +04:00
|
|
|
* Sweeps the database tables and clears the EntityManager.
|
2008-05-24 21:37:26 +04:00
|
|
|
*/
|
|
|
|
protected function tearDown()
|
|
|
|
{
|
2010-10-29 18:46:21 +04:00
|
|
|
$conn = static::$_sharedConn;
|
2009-11-04 14:39:49 +03:00
|
|
|
|
|
|
|
$this->_sqlLoggerStack->enabled = false;
|
2010-09-29 00:36:26 +04:00
|
|
|
|
2009-05-21 12:53:40 +04:00
|
|
|
if (isset($this->_usedModelSets['cms'])) {
|
2009-10-20 12:01:33 +04:00
|
|
|
$conn->executeUpdate('DELETE FROM cms_users_groups');
|
|
|
|
$conn->executeUpdate('DELETE FROM cms_groups');
|
|
|
|
$conn->executeUpdate('DELETE FROM cms_addresses');
|
|
|
|
$conn->executeUpdate('DELETE FROM cms_phonenumbers');
|
2010-07-08 19:30:39 +04:00
|
|
|
$conn->executeUpdate('DELETE FROM cms_comments');
|
2009-10-20 12:01:33 +04:00
|
|
|
$conn->executeUpdate('DELETE FROM cms_articles');
|
|
|
|
$conn->executeUpdate('DELETE FROM cms_users');
|
2012-02-28 04:16:35 +04:00
|
|
|
$conn->executeUpdate('DELETE FROM cms_emails');
|
2008-05-24 21:37:26 +04:00
|
|
|
}
|
2010-09-29 00:36:26 +04:00
|
|
|
|
2009-07-01 13:18:08 +04:00
|
|
|
if (isset($this->_usedModelSets['ecommerce'])) {
|
2009-10-20 12:01:33 +04:00
|
|
|
$conn->executeUpdate('DELETE FROM ecommerce_carts_products');
|
|
|
|
$conn->executeUpdate('DELETE FROM ecommerce_products_categories');
|
|
|
|
$conn->executeUpdate('DELETE FROM ecommerce_products_related');
|
|
|
|
$conn->executeUpdate('DELETE FROM ecommerce_carts');
|
|
|
|
$conn->executeUpdate('DELETE FROM ecommerce_customers');
|
|
|
|
$conn->executeUpdate('DELETE FROM ecommerce_features');
|
|
|
|
$conn->executeUpdate('DELETE FROM ecommerce_products');
|
|
|
|
$conn->executeUpdate('DELETE FROM ecommerce_shippings');
|
2009-08-13 14:13:06 +04:00
|
|
|
$conn->executeUpdate('UPDATE ecommerce_categories SET parent_id = NULL');
|
2009-10-20 12:01:33 +04:00
|
|
|
$conn->executeUpdate('DELETE FROM ecommerce_categories');
|
2009-07-01 13:18:08 +04:00
|
|
|
}
|
2010-09-29 00:36:26 +04:00
|
|
|
|
2009-05-21 12:53:40 +04:00
|
|
|
if (isset($this->_usedModelSets['company'])) {
|
2010-07-04 14:17:15 +04:00
|
|
|
$conn->executeUpdate('DELETE FROM company_contract_employees');
|
2011-12-22 03:19:35 +04:00
|
|
|
$conn->executeUpdate('DELETE FROM company_contract_managers');
|
2010-07-04 14:17:15 +04:00
|
|
|
$conn->executeUpdate('DELETE FROM company_contracts');
|
2009-10-20 12:01:33 +04:00
|
|
|
$conn->executeUpdate('DELETE FROM company_persons_friends');
|
|
|
|
$conn->executeUpdate('DELETE FROM company_managers');
|
|
|
|
$conn->executeUpdate('DELETE FROM company_employees');
|
2009-08-13 14:13:06 +04:00
|
|
|
$conn->executeUpdate('UPDATE company_persons SET spouse_id = NULL');
|
2009-10-20 12:01:33 +04:00
|
|
|
$conn->executeUpdate('DELETE FROM company_persons');
|
|
|
|
$conn->executeUpdate('DELETE FROM company_raffles');
|
|
|
|
$conn->executeUpdate('DELETE FROM company_auctions');
|
2009-11-03 21:30:21 +03:00
|
|
|
$conn->executeUpdate('UPDATE company_organizations SET main_event_id = NULL');
|
2009-10-20 12:01:33 +04:00
|
|
|
$conn->executeUpdate('DELETE FROM company_events');
|
|
|
|
$conn->executeUpdate('DELETE FROM company_organizations');
|
2009-05-21 12:53:40 +04:00
|
|
|
}
|
2010-09-29 00:36:26 +04:00
|
|
|
|
2009-06-20 16:59:33 +04:00
|
|
|
if (isset($this->_usedModelSets['generic'])) {
|
2010-02-26 22:39:12 +03:00
|
|
|
$conn->executeUpdate('DELETE FROM boolean_model');
|
2009-10-20 12:01:33 +04:00
|
|
|
$conn->executeUpdate('DELETE FROM date_time_model');
|
2010-02-26 22:39:12 +03:00
|
|
|
$conn->executeUpdate('DELETE FROM decimal_model');
|
|
|
|
$conn->executeUpdate('DELETE FROM serialize_model');
|
2009-06-20 16:59:33 +04:00
|
|
|
}
|
2010-02-09 20:13:49 +03:00
|
|
|
|
2010-02-15 00:26:15 +03:00
|
|
|
if (isset($this->_usedModelSets['routing'])) {
|
|
|
|
$conn->executeUpdate('DELETE FROM RoutingRouteLegs');
|
|
|
|
$conn->executeUpdate('DELETE FROM RoutingRouteBooking');
|
|
|
|
$conn->executeUpdate('DELETE FROM RoutingRoute');
|
|
|
|
$conn->executeUpdate('DELETE FROM RoutingLeg');
|
|
|
|
$conn->executeUpdate('DELETE FROM RoutingLocation');
|
|
|
|
}
|
|
|
|
|
2010-04-03 18:38:06 +04:00
|
|
|
if(isset($this->_usedModelSets['navigation'])) {
|
|
|
|
$conn->executeUpdate('DELETE FROM navigation_tour_pois');
|
|
|
|
$conn->executeUpdate('DELETE FROM navigation_photos');
|
|
|
|
$conn->executeUpdate('DELETE FROM navigation_pois');
|
|
|
|
$conn->executeUpdate('DELETE FROM navigation_tours');
|
|
|
|
$conn->executeUpdate('DELETE FROM navigation_countries');
|
|
|
|
}
|
2010-09-22 02:15:45 +04:00
|
|
|
if (isset($this->_usedModelSets['directorytree'])) {
|
2010-11-19 01:07:32 +03:00
|
|
|
$conn->executeUpdate('DELETE FROM ' . $this->_em->getConnection()->getDatabasePlatform()->quoteIdentifier("file"));
|
2010-09-29 00:36:26 +04:00
|
|
|
// MySQL doesnt know deferred deletions therefore only executing the second query gives errors.
|
|
|
|
$conn->executeUpdate('DELETE FROM Directory WHERE parentDirectory_id IS NOT NULL');
|
2010-09-22 02:15:45 +04:00
|
|
|
$conn->executeUpdate('DELETE FROM Directory');
|
|
|
|
}
|
2011-01-01 20:17:19 +03:00
|
|
|
if (isset($this->_usedModelSets['ddc117'])) {
|
|
|
|
return;
|
|
|
|
$conn->executeUpdate('DELETE FROM ddc117editor_ddc117translation');
|
|
|
|
$conn->executeUpdate('DELETE FROM DDC117Editor');
|
|
|
|
$conn->executeUpdate('DELETE FROM DDC117ApproveChanges');
|
2011-07-28 01:22:20 +04:00
|
|
|
$conn->executeUpdate('DELETE FROM DDC117Link');
|
2011-01-01 20:17:19 +03:00
|
|
|
$conn->executeUpdate('DELETE FROM DDC117Reference');
|
|
|
|
$conn->executeUpdate('DELETE FROM DDC117ArticleDetails');
|
|
|
|
$conn->executeUpdate('DELETE FROM DDC117Translation');
|
|
|
|
$conn->executeUpdate('DELETE FROM DDC117Article');
|
|
|
|
}
|
2011-02-05 13:42:10 +03:00
|
|
|
if (isset($this->_usedModelSets['stockexchange'])) {
|
|
|
|
$conn->executeUpdate('DELETE FROM exchange_bonds_stocks');
|
|
|
|
$conn->executeUpdate('DELETE FROM exchange_bonds');
|
|
|
|
$conn->executeUpdate('DELETE FROM exchange_stocks');
|
|
|
|
$conn->executeUpdate('DELETE FROM exchange_markets');
|
|
|
|
}
|
2011-07-28 12:46:38 +04:00
|
|
|
if (isset($this->_usedModelSets['legacy'])) {
|
2011-07-29 11:35:59 +04:00
|
|
|
$conn->executeUpdate('DELETE FROM legacy_users_cars');
|
|
|
|
$conn->executeUpdate('DELETE FROM legacy_users_reference');
|
2011-07-28 12:46:38 +04:00
|
|
|
$conn->executeUpdate('DELETE FROM legacy_articles');
|
|
|
|
$conn->executeUpdate('DELETE FROM legacy_cars');
|
|
|
|
$conn->executeUpdate('DELETE FROM legacy_users');
|
|
|
|
}
|
2010-04-03 18:38:06 +04:00
|
|
|
|
2011-11-19 03:35:29 +04:00
|
|
|
if (isset($this->_usedModelSets['customtype'])) {
|
|
|
|
$conn->executeUpdate('DELETE FROM customtype_parent_friends');
|
|
|
|
$conn->executeUpdate('DELETE FROM customtype_parents');
|
|
|
|
$conn->executeUpdate('DELETE FROM customtype_children');
|
|
|
|
$conn->executeUpdate('DELETE FROM customtype_uppercases');
|
|
|
|
}
|
|
|
|
|
2009-01-12 16:34:41 +03:00
|
|
|
$this->_em->clear();
|
2008-05-24 21:37:26 +04:00
|
|
|
}
|
2009-01-07 20:46:02 +03:00
|
|
|
|
2012-02-20 13:33:16 +04:00
|
|
|
protected function setUpEntitySchema(array $classNames)
|
|
|
|
{
|
|
|
|
if ($this->_em === null) {
|
|
|
|
throw new \RuntimeException("EntityManager not set, you have to call parent::setUp() before invoking this method.");
|
|
|
|
}
|
|
|
|
|
|
|
|
$classes = array();
|
|
|
|
foreach ($classNames as $className) {
|
|
|
|
if ( ! isset(static::$_entityTablesCreated[$className])) {
|
|
|
|
static::$_entityTablesCreated[$className] = true;
|
|
|
|
$classes[] = $this->_em->getClassMetadata($className);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($classes) {
|
|
|
|
$this->_schemaTool->createSchema($classes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-30 23:43:05 +04:00
|
|
|
/**
|
|
|
|
* Creates a connection to the test database, if there is none yet, and
|
|
|
|
* creates the necessary tables.
|
|
|
|
*/
|
2009-01-07 20:46:02 +03:00
|
|
|
protected function setUp()
|
|
|
|
{
|
2009-03-30 23:43:05 +04:00
|
|
|
$forceCreateTables = false;
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2010-10-29 18:46:21 +04:00
|
|
|
if ( ! isset(static::$_sharedConn)) {
|
|
|
|
static::$_sharedConn = TestUtil::getConnection();
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2010-10-29 18:46:21 +04:00
|
|
|
if (static::$_sharedConn->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) {
|
2009-03-30 23:43:05 +04:00
|
|
|
$forceCreateTables = true;
|
|
|
|
}
|
2009-01-07 20:46:02 +03:00
|
|
|
}
|
2010-07-04 15:17:26 +04:00
|
|
|
|
|
|
|
if (isset($GLOBALS['DOCTRINE_MARK_SQL_LOGS'])) {
|
2010-10-29 18:46:21 +04:00
|
|
|
if (in_array(static::$_sharedConn->getDatabasePlatform()->getName(), array("mysql", "postgresql"))) {
|
|
|
|
static::$_sharedConn->executeQuery('SELECT 1 /*' . get_class($this) . '*/');
|
|
|
|
} else if (static::$_sharedConn->getDatabasePlatform()->getName() == "oracle") {
|
|
|
|
static::$_sharedConn->executeQuery('SELECT 1 /*' . get_class($this) . '*/ FROM dual');
|
2010-07-04 15:17:26 +04:00
|
|
|
}
|
|
|
|
}
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2009-01-12 16:34:41 +03:00
|
|
|
if ( ! $this->_em) {
|
|
|
|
$this->_em = $this->_getEntityManager();
|
2009-03-30 23:43:05 +04:00
|
|
|
$this->_schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->_em);
|
|
|
|
}
|
|
|
|
|
|
|
|
$classes = array();
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2009-05-21 12:53:40 +04:00
|
|
|
foreach ($this->_usedModelSets as $setName => $bool) {
|
2010-04-14 22:20:44 +04:00
|
|
|
if ( ! isset(static::$_tablesCreated[$setName])/* || $forceCreateTables*/) {
|
|
|
|
foreach (static::$_modelSets[$setName] as $className) {
|
2009-03-30 23:43:05 +04:00
|
|
|
$classes[] = $this->_em->getClassMetadata($className);
|
|
|
|
}
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2010-04-14 22:20:44 +04:00
|
|
|
static::$_tablesCreated[$setName] = true;
|
2009-03-30 23:43:05 +04:00
|
|
|
}
|
|
|
|
}
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2009-03-30 23:43:05 +04:00
|
|
|
if ($classes) {
|
2009-05-30 16:08:15 +04:00
|
|
|
$this->_schemaTool->createSchema($classes);
|
2009-01-12 16:34:41 +03:00
|
|
|
}
|
2009-11-04 14:39:49 +03:00
|
|
|
|
|
|
|
$this->_sqlLoggerStack->enabled = true;
|
2009-01-07 20:46:02 +03:00
|
|
|
}
|
|
|
|
|
2009-03-30 23:43:05 +04:00
|
|
|
/**
|
|
|
|
* Gets an EntityManager for testing purposes.
|
|
|
|
*
|
|
|
|
* @param Configuration $config The Configuration to pass to the EntityManager.
|
|
|
|
* @param EventManager $eventManager The EventManager to pass to the EntityManager.
|
|
|
|
* @return EntityManager
|
|
|
|
*/
|
2009-01-07 20:46:02 +03:00
|
|
|
protected function _getEntityManager($config = null, $eventManager = null) {
|
2009-02-04 21:03:05 +03:00
|
|
|
// NOTE: Functional tests use their own shared metadata cache, because
|
|
|
|
// the actual database platform used during execution has effect on some
|
|
|
|
// metadata mapping behaviors (like the choice of the ID generation).
|
|
|
|
if (is_null(self::$_metadataCacheImpl)) {
|
2012-01-03 22:01:53 +04:00
|
|
|
if (isset($GLOBALS['DOCTRINE_CACHE_IMPL'])) {
|
|
|
|
self::$_metadataCacheImpl = new $GLOBALS['DOCTRINE_CACHE_IMPL'];
|
|
|
|
} else {
|
|
|
|
self::$_metadataCacheImpl = new \Doctrine\Common\Cache\ArrayCache;
|
|
|
|
}
|
2009-02-04 21:03:05 +03:00
|
|
|
}
|
2010-03-15 20:19:00 +03:00
|
|
|
|
2009-05-21 23:18:14 +04:00
|
|
|
if (is_null(self::$_queryCacheImpl)) {
|
2010-04-10 19:35:18 +04:00
|
|
|
self::$_queryCacheImpl = new \Doctrine\Common\Cache\ArrayCache;
|
2009-05-21 23:18:14 +04:00
|
|
|
}
|
2009-11-04 14:39:49 +03:00
|
|
|
|
|
|
|
$this->_sqlLoggerStack = new \Doctrine\DBAL\Logging\DebugStack();
|
|
|
|
$this->_sqlLoggerStack->enabled = false;
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2009-10-06 14:04:32 +04:00
|
|
|
//FIXME: two different configs! $conn and the created entity manager have
|
|
|
|
// different configs.
|
2009-01-22 22:38:10 +03:00
|
|
|
$config = new \Doctrine\ORM\Configuration();
|
2009-02-04 21:03:05 +03:00
|
|
|
$config->setMetadataCacheImpl(self::$_metadataCacheImpl);
|
2009-05-21 23:18:14 +04:00
|
|
|
$config->setQueryCacheImpl(self::$_queryCacheImpl);
|
2009-10-15 00:18:36 +04:00
|
|
|
$config->setProxyDir(__DIR__ . '/Proxies');
|
|
|
|
$config->setProxyNamespace('Doctrine\Tests\Proxies');
|
2010-04-10 19:35:18 +04:00
|
|
|
|
2010-04-11 13:06:54 +04:00
|
|
|
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver());
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2010-10-29 18:46:21 +04:00
|
|
|
$conn = static::$_sharedConn;
|
2010-04-01 00:47:35 +04:00
|
|
|
$conn->getConfiguration()->setSQLLogger($this->_sqlLoggerStack);
|
2011-06-19 00:47:21 +04:00
|
|
|
|
|
|
|
// get rid of more global state
|
|
|
|
$evm = $conn->getEventManager();
|
|
|
|
foreach ($evm->getListeners() AS $event => $listeners) {
|
|
|
|
foreach ($listeners AS $listener) {
|
|
|
|
$evm->removeEventListener(array($event), $listener);
|
|
|
|
}
|
|
|
|
}
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2011-06-26 19:20:03 +04:00
|
|
|
if (isset($GLOBALS['db_event_subscribers'])) {
|
|
|
|
foreach (explode(",", $GLOBALS['db_event_subscribers']) AS $subscriberClass) {
|
|
|
|
$subscriberInstance = new $subscriberClass();
|
|
|
|
$evm->addEventSubscriber($subscriberInstance);
|
|
|
|
}
|
|
|
|
}
|
2011-07-08 16:27:59 +04:00
|
|
|
|
|
|
|
if (isset($GLOBALS['debug_uow_listener'])) {
|
|
|
|
$evm->addEventListener(array('onFlush'), new \Doctrine\ORM\Tools\DebugUnitOfWorkListener());
|
|
|
|
}
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2009-08-13 14:13:06 +04:00
|
|
|
return \Doctrine\ORM\EntityManager::create($conn, $config);
|
2009-01-07 20:46:02 +03:00
|
|
|
}
|
2009-11-04 14:39:49 +03:00
|
|
|
|
|
|
|
protected function onNotSuccessfulTest(\Exception $e)
|
|
|
|
{
|
2010-02-07 00:26:56 +03:00
|
|
|
if ($e instanceof \PHPUnit_Framework_AssertionFailedError) {
|
2009-12-05 00:40:03 +03:00
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
|
2010-01-31 17:35:10 +03:00
|
|
|
if(isset($this->_sqlLoggerStack->queries) && count($this->_sqlLoggerStack->queries)) {
|
2009-11-04 14:39:49 +03:00
|
|
|
$queries = "";
|
2010-09-16 00:11:09 +04:00
|
|
|
for($i = count($this->_sqlLoggerStack->queries)-1; $i > max(count($this->_sqlLoggerStack->queries)-25, 0) && isset($this->_sqlLoggerStack->queries[$i]); $i--) {
|
2009-11-04 14:39:49 +03:00
|
|
|
$query = $this->_sqlLoggerStack->queries[$i];
|
2010-04-18 21:12:38 +04:00
|
|
|
$params = array_map(function($p) { if (is_object($p)) return get_class($p); else return "'".$p."'"; }, $query['params'] ?: array());
|
2009-11-04 14:39:49 +03:00
|
|
|
$queries .= ($i+1).". SQL: '".$query['sql']."' Params: ".implode(", ", $params).PHP_EOL;
|
|
|
|
}
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2009-11-04 14:39:49 +03:00
|
|
|
$trace = $e->getTrace();
|
|
|
|
$traceMsg = "";
|
|
|
|
foreach($trace AS $part) {
|
|
|
|
if(isset($part['file'])) {
|
|
|
|
if(strpos($part['file'], "PHPUnit/") !== false) {
|
|
|
|
// Beginning with PHPUnit files we don't print the trace anymore.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$traceMsg .= $part['file'].":".$part['line'].PHP_EOL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$message = "[".get_class($e)."] ".$e->getMessage().PHP_EOL.PHP_EOL."With queries:".PHP_EOL.$queries.PHP_EOL."Trace:".PHP_EOL.$traceMsg;
|
|
|
|
|
|
|
|
throw new \Exception($message, (int)$e->getCode(), $e);
|
|
|
|
}
|
|
|
|
throw $e;
|
|
|
|
}
|
2010-12-04 21:44:10 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Using the SQL Logger Stack this method retrieves the current query count executed in this test.
|
2011-12-20 01:56:19 +04:00
|
|
|
*
|
2010-12-04 21:44:10 +03:00
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
protected function getCurrentQueryCount()
|
|
|
|
{
|
|
|
|
return count($this->_sqlLoggerStack->queries);
|
|
|
|
}
|
2009-07-01 13:18:08 +04:00
|
|
|
}
|