-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
587c934
commit a622314
Showing
5 changed files
with
72 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
use Doctrine\Common\DataFixtures\Executor\AbstractExecutor; | ||
use Doctrine\ORM\EntityManager; | ||
use Doctrine\ORM\Tools\SchemaTool; | ||
use function in_array; | ||
|
||
/** | ||
* @author Aleksey Tupichenkov <[email protected]> | ||
|
@@ -28,6 +29,8 @@ final class MysqlDatabaseBackup extends AbstractDatabaseBackup | |
|
||
public function getBackupFilePath(): string | ||
{ | ||
// file_put_contents('/tmp/cache.log', 'getBackupFilePath : $this->classNames = “'.print_r($this->classNames, true).'”'.PHP_EOL, FILE_APPEND | LOCK_EX); | ||
|
||
return $this->container->getParameter('kernel.cache_dir').'/test_mysql_'.md5(serialize($this->metadatas).serialize($this->classNames)).'.sql'; | ||
} | ||
|
||
|
@@ -95,7 +98,7 @@ public function restore(AbstractExecutor $executor, array $excludedTables = []): | |
foreach ($this->metadatas as $classMetadata) { | ||
$tableName = $classMetadata->table['name']; | ||
|
||
if (!\in_array($tableName, $excludedTables, true)) { | ||
if (!in_array($tableName, $excludedTables, true)) { | ||
$truncateSql[] = 'DELETE FROM '.$tableName; // in small tables it's really faster than truncate | ||
} | ||
} | ||
|
@@ -124,6 +127,8 @@ public function restore(AbstractExecutor $executor, array $excludedTables = []): | |
$connection->query('SET FOREIGN_KEY_CHECKS = 1;'); | ||
} | ||
|
||
file_put_contents('/tmp/cache.log', 'restore unserialize = “'.print_r(unserialize($this->getReferenceBackup()), true).'”'.PHP_EOL, FILE_APPEND | LOCK_EX); | ||
|
||
if (self::$metadata) { | ||
// it need for better performance | ||
foreach (self::$metadata as $class => $data) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,8 @@ | |
use Liip\TestFixturesBundle\Event\PreFixtureBackupRestoreEvent; | ||
use Liip\TestFixturesBundle\Event\ReferenceSaveEvent; | ||
use Liip\TestFixturesBundle\LiipTestFixturesEvents; | ||
use function count; | ||
use function in_array; | ||
|
||
/** | ||
* @author Aleksey Tupichenkov <[email protected]> | ||
|
@@ -76,6 +78,9 @@ public function loadFixtures(array $classNames = [], bool $append = false): Abst | |
$backupService = $this->getBackupService(); | ||
|
||
if ($backupService && $this->databaseCacheEnabled) { | ||
|
||
file_put_contents('/tmp/cache.log', 'loadFixtures if = “'.print_r($classNames, true).'”'.PHP_EOL, FILE_APPEND | LOCK_EX); | ||
|
||
$backupService->init($this->getMetadatas(), $classNames, $append); | ||
|
||
if ($backupService->isBackupActual()) { | ||
|
@@ -103,7 +108,7 @@ public function loadFixtures(array $classNames = [], bool $append = false): Abst | |
// TODO: handle case when using persistent connections. Fail loudly? | ||
if (false === $this->getKeepDatabaseAndSchemaParameter()) { | ||
$schemaTool = new SchemaTool($this->om); | ||
if (\count($this->excludedDoctrineTables) > 0 || true === $append) { | ||
if (count($this->excludedDoctrineTables) > 0 || true === $append) { | ||
if (!empty($this->getMetadatas())) { | ||
$schemaTool->updateSchema($this->getMetadatas()); | ||
} | ||
|
@@ -179,7 +184,7 @@ protected function createDatabaseIfNotExists(): void | |
$tmpConnection = DriverManager::getConnection($params); | ||
$tmpConnection->connect(); | ||
|
||
if (!\in_array($dbName, $tmpConnection->getSchemaManager()->listDatabases(), true)) { | ||
if (!in_array($dbName, $tmpConnection->getSchemaManager()->listDatabases(), true)) { | ||
$tmpConnection->getSchemaManager()->createDatabase($dbName); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,21 +24,21 @@ class LoadUserData extends AbstractFixture | |
*/ | ||
public function load(ObjectManager $manager): void | ||
{ | ||
$user = new User(); | ||
$user->setId(1); | ||
$user->setName('foo bar'); | ||
$user->setEmail('[email protected]'); | ||
$user1 = new User(); | ||
$user1->setId(1); | ||
$user1->setName('foo bar'); | ||
$user1->setEmail('[email protected]'); | ||
|
||
$manager->persist($user); | ||
$manager->persist($user1); | ||
$manager->flush(); | ||
|
||
$this->addReference('user', $user); | ||
$this->addReference('user', $user1); | ||
|
||
$user = clone $this->getReference('user'); | ||
$user2 = clone $user1; | ||
|
||
$user->setId(2); | ||
$user2->setId(2); | ||
|
||
$manager->persist($user); | ||
$manager->persist($user2); | ||
$manager->flush(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters