Comments (3)
This bundle now seems to support paratest out of the box? Except I'm still getting this issue with caching the sqlite database.
Following @mente's example resolves the issue. The below is the only change required to the SqliteDatabaseBackup class.
Would it be worth me submitting a PR for this?
public function getBackupFilePath(): string
{
+ $token = \getenv('TEST_TOKEN') ?: 'default';
+ return $this->container->getParameter('kernel.cache_dir').'/test_sqlite_'.$token.\md5(\serialize($this->metadatas).\serialize($this->classNames)).'.db';
- return $this->container->getParameter('kernel.cache_dir').'/test_sqlite_'.md5(serialize($this->metadatas).serialize($this->classNames)).'.db';
}
from liiptestfixturesbundle.
Thanks for the detailed issue.
The support of paratest was removed to ease the maintenance of this bundle in #56, but we can restore it.
So we have to be able to:
- define a custom name for the database
- define a custom path for the backup
Could you please show the code that work for you today?
from liiptestfixturesbundle.
Thanks for looking into this.
We use the ConnectionFactory from the old times of the bundle (even has old reference to LiipFunctionalTestBundle):
use Doctrine\Bundle\DoctrineBundle\ConnectionFactory as BaseConnectionFactory;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Configuration;
/**
* Creates a connection taking the db name from the env with
* a unique number defined by current process ID.
*
* @link https://github.com/liip/LiipFunctionalTestBundle/blob/master/Factory/ConnectionFactory.php idea borrowed here
*/
class DBALConnectionFactory extends BaseConnectionFactory
{
/**
* Create a connection by name.
*
* @param array $params
* @param Configuration $config
* @param EventManager $eventManager
* @param array $mappingTypes
*
* @return \Doctrine\DBAL\Connection
*/
public function createConnection(array $params, Configuration $config = null, EventManager $eventManager = null, array $mappingTypes = array())
{
$parallelPrefix = getenv('TEST_TOKEN');
if ($params['driver'] === 'pdo_sqlite') {
$params['path'] = str_replace('__DBNAME__', $parallelPrefix, $params['path']);
} else {
$params['dbname'] = str_replace('__DBNAME__', $parallelPrefix, $params['dbname']);
}
return parent::createConnection($params, $config, $eventManager, $mappingTypes);
}
}
And the one we use for sqlite fixtures replacement
use Doctrine\Common\DataFixtures\Executor\AbstractExecutor;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManager;
/**
* @author Aleksey Tupichenkov <[email protected]>
*/
final class SqliteDatabaseBackup extends AbstractDatabaseBackup implements DatabaseBackupInterface
{
public function getBackupFilePath(): string
{
$token = getenv('TEST_TOKEN') ?: 'default';
return $this->container->getParameter('kernel.cache_dir').'/test_sqlite_'. $token . md5(serialize($this->metadatas).serialize($this->classNames)).'.db';
}
private function getDatabaseName(Connection $connection): string
{
$params = $connection->getParams();
if (isset($params['master'])) {
$params = $params['master'];
}
$name = $params['path'] ?? ($params['dbname'] ?? false);
if (!$name) {
throw new \InvalidArgumentException("Connection does not contain a 'path' or 'dbname' parameter and cannot be dropped.");
}
return $name;
}
public function isBackupActual(): bool
{
$backupDBFileName = $this->getBackupFilePath();
$backupReferenceFileName = $backupDBFileName.'.ser';
return file_exists($backupDBFileName) && file_exists($backupReferenceFileName) && $this->isBackupUpToDate($backupDBFileName);
}
public function backup(AbstractExecutor $executor): void
{
/** @var EntityManager $em */
$em = $executor->getReferenceRepository()->getManager();
$connection = $em->getConnection();
$executor->getReferenceRepository()->save($this->getBackupFilePath());
copy($this->getDatabaseName($connection), $this->getBackupFilePath());
}
public function restore(AbstractExecutor $executor, array $excludedTables = []): void
{
/** @var EntityManager $em */
$em = $executor->getReferenceRepository()->getManager();
$connection = $em->getConnection();
copy($this->getBackupFilePath(), $this->getDatabaseName($connection));
$executor->getReferenceRepository()->load($this->getBackupFilePath());
}
}
Had to copy-paste class because it's final in the bundle. Need to note that we're using latest 1.x version due to older symfony dependencies.
from liiptestfixturesbundle.
Related Issues (20)
- [Feature Request]: Add support of Behat
- [Bug]: Multiple entity managers per connection OR entity manager name does not match connection name HOT 5
- Drop support of PHP 7.2 and 7.3? HOT 1
- [Bug]: keep_database_and_schema config is ignored it is always false with SQL Server HOT 2
- facing issue in new pimcore version 10.6 HOT 5
- [Feature Request]: Add LoadFixtureGroup method HOT 2
- Deprecated DBAL APIs still in use HOT 1
- Question: cached database with GitLab CI pipeline HOT 2
- Load fixture without a file path HOT 7
- [Feature Request]: Support Symfony 7 HOT 1
- [Bug]: $referenceRepository->getReferences() is broken HOT 1
- [Bug]: mysqldump: unknown variable 'column-statistics=0' error HOT 7
- Performance with LiipTestFixturesBundle v2.6.0 HOT 7
- SqlitePlatform::getName() is deprecated HOT 4
- [Bug]: Impossible to set "keep_database_and_schema" HOT 4
- [Bug]: 2.7.2 - Doctrine MongoDB Manager can not be used anymore HOT 2
- [Feature Request]: Upgrading doctrine/dbal Connection handling HOT 5
- [Feature Request]: Support "doctrine/dbal" 4 HOT 1
- [Feature Request]: Prepare release 3.x HOT 1
- [Bug]: Undeclared dependency on doctrine/dbal ^3.1.0 | ^4.0.1 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from liiptestfixturesbundle.