Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow option to exclude purged tables/views #330

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ jobs:
php: 7.3
env: DEPENDENCIES="dev"

- stage: test
php: nightly
before_install:
- composer config platform.php 7.4.99
- composer config minimum-stability dev

# Run phpcs
- stage: Code Quality
php: 7.2
Expand Down
4 changes: 3 additions & 1 deletion Command/LoadDataFixturesDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ protected function configure()
->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.')
->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command.')
->addOption('purge-with-truncate', null, InputOption::VALUE_NONE, 'Purge data by using a database-level TRUNCATE statement')
->addOption('purge-excluded', null, InputOption::VALUE_IS_ARRAY|InputOption::VALUE_OPTIONAL, 'Array of table/view names to be excluded from purge')
->setHelp(<<<EOT
The <info>%command.name%</info> command loads data fixtures from your application:

Expand Down Expand Up @@ -118,7 +119,8 @@ protected function execute(InputInterface $input, OutputInterface $output)

return 1;
}
$purger = new ORMPurger($em);
$excluded = $input->getOption('purge-excluded');
$purger = new ORMPurger($em, $excluded);
$purger->setPurgeMode($input->getOption('purge-with-truncate') ? ORMPurger::PURGE_MODE_TRUNCATE : ORMPurger::PURGE_MODE_DELETE);
$executor = new ORMExecutor($em, $purger);
$executor->setLogger(static function ($message) use ($ui) : void {
Expand Down
9 changes: 9 additions & 0 deletions Tests/Command/LoadDataFixturesDoctrineCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Container;
use TypeError;
use const PHP_VERSION_ID;

class LoadDataFixturesDoctrineCommandTest extends TestCase
{
Expand All @@ -24,6 +25,14 @@ public function testInstantiatingWithoutManagerRegistry() : void
try {
new LoadDataFixturesDoctrineCommand($loader);
} catch (TypeError $e) {
if (PHP_VERSION_ID >= 80000) {
$this->expectExceptionMessage(
<<<'MESSAGE'
Doctrine\Bundle\DoctrineBundle\Command\DoctrineCommand::__construct(): Argument #1 ($doctrine) must be of type Doctrine\Persistence\ManagerRegistry, null given, called in /home/travis/build/doctrine/DoctrineFixturesBundle/Command/LoadDataFixturesDoctrineCommand.php on line 41
MESSAGE
);
throw $e;
}
$this->expectExceptionMessage('Argument 1 passed to Doctrine\Bundle\DoctrineBundle\Command\DoctrineCommand::__construct() must be an instance of Doctrine\Persistence\ManagerRegistry, null given');

throw $e;
Expand Down
15 changes: 7 additions & 8 deletions Tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\RequiredConstructorArgsFixtures;
use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\WithDependenciesFixtures;
use Doctrine\Common\DataFixtures\Loader;
use LogicException;
use PHPUnit\Framework\TestCase;
use RuntimeException;
use Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader;
Expand Down Expand Up @@ -85,10 +86,6 @@ public function testFixturesLoaderWhenFixtureHasDepdencenyThatIsNotYetLoaded() :
$this->assertInstanceOf(WithDependenciesFixtures::class, $actualFixtures[1]);
}

/**
* @expectedException \LogicException
* @expectedExceptionMessage The getDependencies() method returned a class (Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\RequiredConstructorArgsFixtures) that has required constructor arguments. Upgrade to "doctrine/data-fixtures" version 1.3 or higher to support this.
*/
public function testExceptionWithDependenciesWithRequiredArguments() : void
{
// see https://github.com/doctrine/data-fixtures/pull/274
Expand All @@ -112,16 +109,15 @@ public function testExceptionWithDependenciesWithRequiredArguments() : void
$kernel->boot();
$container = $kernel->getContainer();

$this->expectException(LogicException::class);
$this->expectExceptionMessage('The getDependencies() method returned a class (Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\RequiredConstructorArgsFixtures) that has required constructor arguments. Upgrade to "doctrine/data-fixtures" version 1.3 or higher to support this.');

/** @var ContainerAwareLoader $loader */
$loader = $container->get('test.doctrine.fixtures.loader');

$loader->getFixtures();
}

/**
* @expectedException \LogicException
* @expectedExceptionMessage The "Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\RequiredConstructorArgsFixtures" fixture class is trying to be loaded, but is not available. Make sure this class is defined as a service and tagged with "doctrine.fixture.orm".
*/
public function testExceptionIfDependentFixtureNotWired() : void
{
// only runs on newer versions of doctrine/data-fixtures
Expand All @@ -139,6 +135,9 @@ public function testExceptionIfDependentFixtureNotWired() : void
$kernel->boot();
$container = $kernel->getContainer();

$this->expectException(LogicException::class);
$this->expectExceptionMessage('The "Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\RequiredConstructorArgsFixtures" fixture class is trying to be loaded, but is not available. Make sure this class is defined as a service and tagged with "doctrine.fixture.orm".');

/** @var ContainerAwareLoader $loader */
$loader = $container->get('test.doctrine.fixtures.loader');

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
}
],
"require": {
"php": "^7.1",
"php": "^7.1 || ^8.0",
"doctrine/data-fixtures": "^1.3",
"doctrine/doctrine-bundle": "^1.11|^2.0",
"doctrine/orm": "^2.6.0",
"doctrine/persistence": "^1.3",
"doctrine/persistence": "^1.3|^2.0",
"symfony/config": "^3.4|^4.3|^5.0",
"symfony/console": "^3.4|^4.3|^5.0",
"symfony/dependency-injection": "^3.4|^4.3|^5.0",
Expand All @@ -33,7 +33,7 @@
},
"require-dev": {
"doctrine/coding-standard": "^6.0",
"phpunit/phpunit": "^7.4",
"phpunit/phpunit": "^7.4 || ^9.2",
"symfony/phpunit-bridge": "^4.1|^5.0"
},
"autoload": {
Expand Down