/** * perform all neccessary uninstall tasks and return true if successful * * @return boolean */ public function uninstall($deleteModels = false, $removeAttributes = false) { if ($deleteModels) { $em = $this->Application()->Models(); $platform = $em->getConnection()->getDatabasePlatform(); $platform->registerDoctrineTypeMapping('enum', 'string'); $tool = new \Doctrine\ORM\Tools\SchemaTool($em); $classes = array($em->getClassMetadata('Shopware\\CustomModels\\MoptPayoneTransactionLog\\MoptPayoneTransactionLog')); $tool->dropSchema($classes); $classes = array($em->getClassMetadata('Shopware\\CustomModels\\MoptPayoneApiLog\\MoptPayoneApiLog')); $tool->dropSchema($classes); $classes = array($em->getClassMetadata('Shopware\\CustomModels\\MoptPayoneConfig\\MoptPayoneConfig')); $tool->dropSchema($classes); } if ($removeAttributes) { Shopware()->Models()->removeAttribute('s_user_attributes', 'mopt_payone', 'consumerscore_result'); Shopware()->Models()->removeAttribute('s_user_attributes', 'mopt_payone', 'consumerscore_date'); Shopware()->Models()->removeAttribute('s_user_attributes', 'mopt_payone', 'consumerscore_color'); Shopware()->Models()->removeAttribute('s_user_attributes', 'mopt_payone', 'consumerscore_value'); // billing adress extension user Shopware()->Models()->removeAttribute('s_user_billingaddress_attributes', 'mopt_payone', 'addresscheck_result'); Shopware()->Models()->removeAttribute('s_user_billingaddress_attributes', 'mopt_payone', 'addresscheck_date'); Shopware()->Models()->removeAttribute('s_user_billingaddress_attributes', 'mopt_payone', 'addresscheck_personstatus'); Shopware()->Models()->removeAttribute('s_user_billingaddress_attributes', 'mopt_payone', 'consumerscore_result'); Shopware()->Models()->removeAttribute('s_user_billingaddress_attributes', 'mopt_payone', 'consumerscore_date'); Shopware()->Models()->removeAttribute('s_user_billingaddress_attributes', 'mopt_payone', 'consumerscore_color'); Shopware()->Models()->removeAttribute('s_user_billingaddress_attributes', 'mopt_payone', 'consumerscore_value'); // shipping adress extension Shopware()->Models()->removeAttribute('s_user_shippingaddress_attributes', 'mopt_payone', 'addresscheck_result'); Shopware()->Models()->removeAttribute('s_user_shippingaddress_attributes', 'mopt_payone', 'addresscheck_date'); Shopware()->Models()->removeAttribute('s_user_shippingaddress_attributes', 'mopt_payone', 'addresscheck_personstatus'); Shopware()->Models()->removeAttribute('s_user_shippingaddress_attributes', 'mopt_payone', 'consumerscore_color'); Shopware()->Models()->removeAttribute('s_user_shippingaddress_attributes', 'mopt_payone', 'consumerscore_value'); // order extension Shopware()->Models()->removeAttribute('s_order_attributes', 'mopt_payone', 'txid'); Shopware()->Models()->removeAttribute('s_order_attributes', 'mopt_payone', 'status'); Shopware()->Models()->removeAttribute('s_order_attributes', 'mopt_payone', 'sequencenumber'); Shopware()->Models()->removeAttribute('s_order_attributes', 'mopt_payone', 'is_authorized'); Shopware()->Models()->removeAttribute('s_order_attributes', 'mopt_payone', 'is_finally_captured'); Shopware()->Models()->removeAttribute('s_order_attributes', 'mopt_payone', 'clearing_data', 'text'); // orderdetails(order articles) extension Shopware()->Models()->removeAttribute('s_order_details_attributes', 'mopt_payone', 'payment_status'); Shopware()->Models()->removeAttribute('s_order_details_attributes', 'mopt_payone', 'shipment_date'); Shopware()->Models()->removeAttribute('s_order_details_attributes', 'mopt_payone', 'captured'); Shopware()->Models()->removeAttribute('s_order_details_attributes', 'mopt_payone', 'debit'); Shopware()->Models()->generateAttributeModels(array('s_user_attributes', 's_core_paymentmeans_attributes', 's_user_billingaddress_attributes', 's_user_shippingaddress_attributes', 's_order_attributes', 's_order_details_attributes')); } return true; }
/** * create schema from annotation mapping files * @return void */ protected function _createSchemas() { $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->_em); $classes = array($this->_em->getClassMetadata("\\Ali\\DatatableBundle\\Tests\\TestBundle\\Entity\\Category"), $this->_em->getClassMetadata("\\Ali\\DatatableBundle\\Tests\\TestBundle\\Entity\\Product"), $this->_em->getClassMetadata("\\Ali\\DatatableBundle\\Tests\\TestBundle\\Entity\\Feature")); $schemaTool->dropSchema($classes); $schemaTool->createSchema($classes); }
public function runAction() { $em = $this->getEntityManager(); $console = $this->getServiceLocator()->get('console'); $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em); $console->writeLine('建立資料表中, 請稍待!!', ColorInterface::GREEN); $classes = $em->getMetadataFactory()->getAllMetadata(); if ($this->params()->fromRoute('re-create-database')) { $schemaTool->dropSchema($classes); } $schemaTool->createSchema($classes); // 安裝預設管理人員及選單 $username = '******'; $password = \Zend\Math\Rand::getString(8, null, true); $user = new \Base\Entity\User(); $user->setUsername($username); $user->setPassword(\Zend\Ldap\Attribute::createPassword($password)); $user->setDisplayName('管理者'); $user->setRole('admin'); $em->persist($user); $em->flush(); $menu = new \Base\Entity\Menu(); $menu->setName('首頁'); $menu->setUser($user); $params = ['max_records' => 10, 'order_kind' => 'desc', 'term' => '']; $menu->setParams(serialize($params)); $em->persist($menu); $em->flush(); $console->writeLine('建立完成!!', ColorInterface::GREEN); $console->writeLine('預設帳號 ' . $username . ', 密碼 ' . $password, ColorInterface::GREEN); }
public function initDb() { $this->create_database("whathood_test"); $DEBUG = false; // Retrieve the Doctrine 2 entity manager $em = $this->getServiceManager()->get('mydoctrineentitymanager'); // Instantiate the schema tool $tool = new \Doctrine\ORM\Tools\SchemaTool($em); // Retrieve all of the mapping metadata $classes = $em->getMetadataFactory()->getAllMetadata(); if ($DEBUG) { print "dropping schema\n"; } // Delete the existing test database schema $tool->dropSchema($classes); if ($DEBUG) { print "creating schema\n"; } // Create the test database schema $tool->createSchema($classes); if ($DEBUG) { print "schema created\n"; } // don't really know why we have to clear this but it works to stop // it when the entity manager doesn't seem to persist shit $em->clear(); }
public function setUp() { if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0RC4-DEV', '>=')) { $this->markTestSkipped('Doctrine common is 2.1.0RC4-DEV version, skipping.'); } else { if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0-BETA3-DEV', '>=')) { $reader = new AnnotationReader(); $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\'); $reader->setIgnoreNotImportedAnnotations(true); $reader->setAnnotationNamespaceAlias('Gedmo\\Mapping\\Annotation\\', 'gedmo'); $reader->setEnableParsePhpImports(false); $reader->setAutoloadAnnotations(true); $reader = new CachedReader(new \Doctrine\Common\Annotations\IndexedReader($reader), new ArrayCache()); } else { $reader = new AnnotationReader(); $reader->setAutoloadAnnotations(true); $reader->setAnnotationNamespaceAlias('Gedmo\\Mapping\\Annotation\\', 'gedmo'); $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\'); } } $config = new \Doctrine\ORM\Configuration(); $config->setProxyDir(TESTS_TEMP_DIR); $config->setProxyNamespace('Gedmo\\Mapping\\Proxy'); $config->setMetadataDriverImpl(new AnnotationDriver($reader)); $conn = array('driver' => 'pdo_sqlite', 'memory' => true); //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger()); $evm = new \Doctrine\Common\EventManager(); $this->timestampable = new \Gedmo\Timestampable\TimestampableListener(); $evm->addEventSubscriber($this->timestampable); $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm); $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em); $schemaTool->dropSchema(array()); $schemaTool->createSchema(array($this->em->getClassMetadata(self::ARTICLE))); }
/** * データベースを初期化する. * * データベースを初期化し、マイグレーションを行なう. * 全てのデータが初期化されるため注意すること. * * @link http://jamesmcfadden.co.uk/database-unit-testing-with-doctrine-2-and-phpunit/ */ public function initializeDatabase() { // Get an instance of your entity manager $entityManager = $this->app['orm.em']; // Retrieve PDO instance $pdo = $entityManager->getConnection()->getWrappedConnection(); // Clear Doctrine to be safe $entityManager->clear(); // Schema Tool to process our entities $tool = new \Doctrine\ORM\Tools\SchemaTool($entityManager); $classes = $entityManager->getMetaDataFactory()->getAllMetaData(); // Drop all classes and re-build them for each test case $tool->dropSchema($classes); $tool->createSchema($classes); $config = new Configuration($this->app['db']); $config->setMigrationsNamespace('DoctrineMigrations'); $migrationDir = __DIR__ . '/../../../src/Eccube/Resource/doctrine/migration'; $config->setMigrationsDirectory($migrationDir); $config->registerMigrationsFromDirectory($migrationDir); $migration = new Migration($config); $migration->migrate(null, false); // 通常は eccube_install.sh で追加されるデータを追加する $sql = "INSERT INTO dtb_member (member_id, login_id, password, salt, work, del_flg, authority, creator_id, rank, update_date, create_date,name,department) VALUES (2, 'admin', 'test', 'test', 1, 0, 0, 1, 1, current_timestamp, current_timestamp,'管理者','EC-CUBE SHOP')"; $stmt = $pdo->prepare($sql); $stmt->execute(); $sql = "INSERT INTO dtb_base_info (id, shop_name, email01, email02, email03, email04, update_date, option_product_tax_rule) VALUES (1, 'SHOP_NAME', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', current_timestamp, 0)"; $stmt = $pdo->prepare($sql); $stmt->execute(); }
private function prepare() { $cmf = $this->em->getMetadataFactory(); $metadata = new ClassMetadata('Mapping\\Fixture\\Unmapped\\Timestampable'); $id = array(); $id['fieldName'] = 'id'; $id['type'] = 'integer'; $id['nullable'] = false; $id['columnName'] = 'id'; $id['id'] = true; $metadata->mapField($id); $created = array(); $created['fieldName'] = 'created'; $created['type'] = 'datetime'; $created['nullable'] = false; $created['columnName'] = 'created'; $metadata->mapField($created); $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_IDENTITY); $metadata->setIdGenerator(new \Doctrine\ORM\Id\IdentityGenerator(null)); $metadata->setPrimaryTable(array('name' => 'temp_test')); $cmf->setMetadataFor('Mapping\\Fixture\\Unmapped\\Timestampable', $metadata); // trigger loadClassMetadata event $evm = $this->em->getEventManager(); $eventArgs = new \Doctrine\ORM\Event\LoadClassMetadataEventArgs($metadata, $this->em); $evm->dispatchEvent(\Doctrine\ORM\Events::loadClassMetadata, $eventArgs); if (Version::compare('2.3.0-dev') <= 0) { $metadata->wakeupReflection($cmf->getReflectionService()); } $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em); $schemaTool->dropSchema(array()); $schemaTool->createSchema(array($this->em->getClassMetadata('Mapping\\Fixture\\Unmapped\\Timestampable'))); }
/** * @test */ public function shouldHandleApcQueryCache() { if (!extension_loaded('apc') || !ini_get('apc.enable_cli')) { $this->markTestSkipped('APC extension is not loaded.'); } $config = new \Doctrine\ORM\Configuration(); $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ApcCache()); $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ApcCache()); $config->setProxyDir(__DIR__); $config->setProxyNamespace('Gedmo\\Mapping\\Proxy'); $config->getAutoGenerateProxyClasses(false); $config->setMetadataDriverImpl($this->getMetadataDriverImplementation()); $conn = array('driver' => 'pdo_sqlite', 'memory' => true); $em = \Doctrine\ORM\EntityManager::create($conn, $config); $schema = array_map(function ($class) use($em) { return $em->getClassMetadata($class); }, (array) $this->getUsedEntityFixtures()); $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em); $schemaTool->dropSchema(array()); $schemaTool->createSchema($schema); $this->populate($em); $_GET['filterField'] = 'a.title'; $_GET['filterValue'] = 'summer'; $query = $em->createQuery('SELECT a FROM Test\\Fixture\\Entity\\Article a'); $p = new Paginator(); $view = $p->paginate($query, 1, 10); $query = $em->createQuery('SELECT a FROM Test\\Fixture\\Entity\\Article a'); $view = $p->paginate($query, 1, 10); }
protected function setUp() { $config = new Configuration(); //$config->setHydratorDir(sys_get_temp_dir()); //$config->setHydratorNamespace('Hydrators'); $config->setProxyDir(sys_get_temp_dir()); $config->setProxyNamespace('Proxies'); $locatorXml = new SymfonyFileLocator(array(__DIR__ . '/../../../../../lib/Vespolina/Product/Mapping' => 'Vespolina\\Entity\\Product', __DIR__ . '/../../../../../vendor/vespolina/pricing/lib/Vespolina/Pricing/Mapping' => 'Vespolina\\Entity\\Pricing', __DIR__ . '/../../../../../vendor/vespolina/taxonomy/lib/Vespolina/Taxonomy/Mapping' => 'Vespolina\\Entity\\Taxonomy'), '.orm.xml'); $drivers = new MappingDriverChain(); $xmlDriver = new XmlDriver($locatorXml); $config->setMetadataDriverImpl($xmlDriver); $config->setMetadataCacheImpl(new ArrayCache()); $config->setAutoGenerateProxyClasses(true); $eventManager = new EventManager(); $treeListener = new TreeListener(); $eventManager->addEventSubscriber($treeListener); $em = EntityManager::create(array('driver' => 'pdo_sqlite', 'path' => 'database.sqlite'), $config, $eventManager); $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em); $classes = array($em->getClassMetadata('Vespolina\\Entity\\Product\\Product'), $em->getClassMetadata('Vespolina\\Entity\\Taxonomy\\TaxonomyNode')); try { $schemaTool->dropSchema(array()); $schemaTool->createSchema($classes); } catch (\Exception $e) { } $this->productGateway = new ProductDoctrineORMGateway($em, 'Vespolina\\Entity\\Product\\Product'); $this->taxonomyGateway = new TaxonomyDoctrineORMGateway($em, 'Vespolina\\Entity\\Taxonomy\\TaxonomyNode'); parent::setUp(); }
public function initDb() { $configArray = $this->sm->get('config'); $db_name = $configArray['doctrine']['connection']['orm_default']; \Zend\Debug\Debug::dump($db_name); exit; $DEBUG = true; // Retrieve the Doctrine 2 entity manager $em = $this->sm->get('doctrine.entitymanager.orm_default'); // Instantiate the schema tool $tool = new \Doctrine\ORM\Tools\SchemaTool($em); // Retrieve all of the mapping metadata $classes = $em->getMetadataFactory()->getAllMetadata(); if ($DEBUG) { print "dropping schema\n"; } // Delete the existing test database schema $tool->dropSchema($classes); if ($DEBUG) { print "creating schema\n"; } // Create the test database schema $tool->createSchema($classes); if ($DEBUG) { print "schema created\n"; } }
/** * @see http://jamesmcfadden.co.uk/database-unit-testing-with-doctrine-2-and-phpunit/ */ public function getConnection() { // 別途 Application を生成しているような箇所があると動作しないので注意 $app = EccubeTestCase::createApplication(); // Get an instance of your entity manager $entityManager = $app['orm.em']; // Retrieve PDO instance $pdo = $entityManager->getConnection()->getWrappedConnection(); // Clear Doctrine to be safe $entityManager->clear(); // Schema Tool to process our entities $tool = new \Doctrine\ORM\Tools\SchemaTool($entityManager); $classes = $entityManager->getMetaDataFactory()->getAllMetaData(); // Drop all classes and re-build them for each test case $tool->dropSchema($classes); $tool->createSchema($classes); $config = new Configuration($app['db']); $config->setMigrationsNamespace('DoctrineMigrations'); $migrationDir = __DIR__ . '/../../../src/Eccube/Resource/doctrine/migration'; $config->setMigrationsDirectory($migrationDir); $config->registerMigrationsFromDirectory($migrationDir); $migration = new Migration($config); $migration->migrate(null, false); self::$app = $app; // Pass to PHPUnit return $this->createDefaultDBConnection($pdo, 'db_name'); }
public function remove(GenericEvent $event) { if ($event->getArgument('plugin_name') != 'newscoop/meteoblue-plugin-bundle') { return; } $tool = new \Doctrine\ORM\Tools\SchemaTool($this->em); $tool->dropSchema($this->getClasses(), true); }
protected function dropAndCreateSchema() { $em = $this->getEntityManager(); $metadatas = $em->getMetadataFactory()->getAllMetadata(); $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->getEntityManager()); $schemaTool->dropSchema($metadatas); $schemaTool->createSchema($metadatas); }
public function preTestSetUp(EntityManagerEventArgs $eventArgs) { $this->preTestEvent = true; $em = $eventArgs->getEntityManager(); $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em); $classes = array($em->getClassMetadata(__NAMESPACE__ . "\\BlogPost"), $em->getClassMetadata('DoctrineExtensions\\Versionable\\Entity\\ResourceVersion')); $schemaTool->dropSchema($classes); $schemaTool->createSchema($classes); }
/** * Remove custom table * * @return bool */ public function uninstall() { $this->registerCustomModels(); $em = Shopware()->Models(); $tool = new \Doctrine\ORM\Tools\SchemaTool($em); $classes = array($em->getClassMetadata('Shopware\\CustomModels\\SwagDynamicEmotion\\Store')); $tool->dropSchema($classes); return true; }
/** */ protected function generateSchema() { $metadatas = $this->getMetadatas(); if (!empty($metadatas)) { $tool = new \Doctrine\ORM\Tools\SchemaTool($this->em); $tool->dropSchema($metadatas); $tool->createSchema($metadatas); } }
public function remove(GenericEvent $event) { $tool = new \Doctrine\ORM\Tools\SchemaTool($this->em); $tool->dropSchema($this->getClasses(), true); $removeEmail = $this->em->getRepository('Newscoop\\NewscoopBundle\\Entity\\SystemPreferences')->findOneBy(array('option' => 'SendRecommendationEmail')); $this->em->remove($removeEmail); $this->em->remove($removeNonUserPref); $this->em->flush(); }
public function preTestSetUp(Event\EntityManagerEventArgs $eventArgs) { $this->preTestEvent = true; $em = $eventArgs->getEntityManager(); $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em); $classes = array($em->getClassMetadata(__NAMESPACE__ . "\\User")); $schemaTool->dropSchema($classes); $schemaTool->createSchema($classes); }
public function uninstall() { $this->registerCustomModels(); $em = $this->Application()->Models(); $tool = new \Doctrine\ORM\Tools\SchemaTool($em); $classes = array($em->getClassMetadata('Shopware\\CustomModels\\Product\\Product')); $tool->dropSchema($classes); return true; }
public function execute() { if (envIsNot('development') || !ENV_DOCTRINE_ENABLED) { die('NOK'); } $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->entityManager); $classes = $this->entityManager->getMetadataFactory()->getAllMetadata(); $schemaTool->dropSchema($classes); die('OK'); }
public function setUpSchema() { if (!$this->em) { return; } $tool = new \Doctrine\ORM\Tools\SchemaTool($this->em); $classes = array($this->em->getClassMetadata($this->mailQueueEntity)); $tool->dropSchema($classes); $tool->createSchema($classes); }
public function setUp() { $this->sm = Bootstrap::getServiceManager(); $this->em = $this->sm->get('doctrine.entitymanager.orm_default'); $tool = new \Doctrine\ORM\Tools\SchemaTool($this->em); $classes = $this->em->getMetadataFactory()->getAllMetadata(); $tool->dropSchema($classes); $tool->createSchema($classes); parent::setUp(); }
protected function setUp() { parent::setUp(); $this->containerBuilder = new ContainerBuilder(); $loader = new LexikFixturesMapperExtension(); $loader->load(array(), $this->containerBuilder); $this->em = $this->getMockSqliteEntityManager(); $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em); $schemaTool->dropSchema(array()); $schemaTool->createSchema($this->em->getMetadataFactory()->getAllMetadata()); }
private function dropAll() { if (!isset($this->connectionOptions['path'])) { return; } $metadataClasses = $this->getMetadataClassesOfEntities(); if (count($metadataClasses) > 0) { $tool = new \Doctrine\ORM\Tools\SchemaTool($this->entityManager); $tool->dropSchema($metadataClasses); } }
public function dropSchema() { print "dropping schema\n"; // Instantiate the schema tool $tool = new \Doctrine\ORM\Tools\SchemaTool($this->em); $factory = $this->em->getMetadataFactory(); // Retrieve all of the mapping metadata $classes = $factory->getAllMetadata(); // Delete the existing test database schema $tool->dropSchema($classes); print "schema dropped\n"; }
protected function setUp() { if (!class_exists('Zend\\Paginator\\Paginator')) { $this->markTestSkipped('Zend paginator library is required'); } $this->kernel = $this->getBaseKernelMock(); $this->container = $this->getContainerBuilder(); $this->em = $this->getMockSqliteEntityManager(); $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em); $schemaTool->dropSchema(array()); $schemaTool->createSchema(array($this->em->getClassMetadata(self::FIXTURE_ARTICLE), $this->em->getClassMetadata(self::FIXTURE_COMMENT))); $this->populate(); }
/** * @BeforeScenario */ public function setUp() { Date::setTestingNow(new \DateTime("now")); $container = $this->kernel->getContainer(); $entityManager = $container->get('doctrine.orm.default_entity_manager'); $metadatas = $entityManager->getMetadataFactory()->getAllMetadata(); $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($entityManager); $schemaTool->dropSchema($metadatas); $schemaTool->createSchema($metadatas); // Load fixtures here $entityManager->flush(); $entityManager->clear(); }
/** * Creates the database scheme from an existing doctrine model. * * Will remove the table first, so handle with care. */ protected function updateSchema() { $this->registerCustomModels(); $em = $this->Application()->Models(); $tool = new \Doctrine\ORM\Tools\SchemaTool($em); $classes = array($em->getClassMetadata('Shopware\\CustomModels\\SwagModelPlugin\\MyPluginModel')); try { $tool->dropSchema($classes); } catch (Exception $e) { //ignore } $tool->createSchema($classes); }
protected function getConnection() { if (is_null($this->app)) { $this->app = $this->getApplication(); } $this->em = EntityManagerFactory::initializeTestEntityManager($this->app); $pdo = $this->em->getConnection()->getWrappedConnection(); $this->em->clear(); $tool = new \Doctrine\ORM\Tools\SchemaTool($this->em); $classes = $this->em->getMetadataFactory()->getAllMetadata(); $tool->dropSchema($classes); $tool->createSchema($classes); return $this->createDefaultDBConnection($pdo, 'fcms_test'); }
/** * データベースを初期化する. * * データベースを初期化し、マイグレーションを行なう. * 全てのデータが初期化されるため注意すること. * * @link http://jamesmcfadden.co.uk/database-unit-testing-with-doctrine-2-and-phpunit/ */ public function initializeDatabase() { // Get an instance of your entity manager $entityManager = $this->app['orm.em']; // Retrieve PDO instance $pdo = $entityManager->getConnection()->getWrappedConnection(); // Clear Doctrine to be safe $entityManager->getConnection()->getConfiguration()->setSQLLogger(null); $entityManager->clear(); gc_collect_cycles(); // Schema Tool to process our entities $tool = new \Doctrine\ORM\Tools\SchemaTool($entityManager); $classes = $entityManager->getMetaDataFactory()->getAllMetaData(); // Drop all classes and re-build them for each test case $tool->dropSchema($classes); $tool->createSchema($classes); $config = new Configuration($this->app['db']); $config->setMigrationsNamespace('DoctrineMigrations'); $migrationDir = __DIR__ . '/../../../src/Eccube/Resource/doctrine/migration'; $config->setMigrationsDirectory($migrationDir); $config->registerMigrationsFromDirectory($migrationDir); $migration = new Migration($config); // initialize migrations.sql from bootstrap if (!file_exists(sys_get_temp_dir() . '/migrations.sql')) { $sql = $migration->migrate(null, false); file_put_contents(sys_get_temp_dir() . '/migrations.sql', json_encode($sql)); } else { $migrations = json_decode(file_get_contents(sys_get_temp_dir() . '/migrations.sql'), true); foreach ($migrations as $migration_sql) { foreach ($migration_sql as $sql) { if ($this->isSqliteInMemory()) { // XXX #1199 の問題を無理矢理回避... $sql = preg_replace('/CURRENT_TIMESTAMP/i', "datetime('now','-9 hours')", $sql); } $stmt = $pdo->prepare($sql); $stmt->execute(); $stmt->closeCursor(); } } } // 通常は eccube_install.sh で追加されるデータを追加する $sql = "INSERT INTO dtb_member (member_id, login_id, password, salt, work, del_flg, authority, creator_id, rank, update_date, create_date,name,department) VALUES (2, 'admin', 'test', 'test', 1, 0, 0, 1, 1, current_timestamp, current_timestamp,'管理者','EC-CUBE SHOP')"; $stmt = $pdo->prepare($sql); $stmt->execute(); $stmt->closeCursor(); $sql = "INSERT INTO dtb_base_info (id, shop_name, email01, email02, email03, email04, update_date, option_product_tax_rule) VALUES (1, 'SHOP_NAME', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', current_timestamp, 0)"; $stmt = $pdo->prepare($sql); $stmt->execute(); $stmt->closeCursor(); }