Skip to content

Commit

Permalink
Merge branch '3.2'
Browse files Browse the repository at this point in the history
* 3.2:
  Remove calls to deprecated method where possible
  Don't pass wrong object to legacy constructors
  Add test to instantiate Loader with ManagerRegistry
  removed workaround for Composer issue with --prefer-lowest
  • Loading branch information
alcaeus committed Jun 12, 2019
2 parents f5a3f11 + e814837 commit f0db517
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ before_install:
- if [[ $DEPENDENCIES == *"/"* ]]; then composer require --no-update $DEPENDENCIES; fi;

install:
# To be removed when this issue will be resolved: https://github.com/composer/composer/issues/5355
- if [[ "$COMPOSER_FLAGS" == *"--prefer-lowest"* ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-stable --quiet; fi
- travis_retry composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction

script:
Expand Down
16 changes: 12 additions & 4 deletions Command/LoadDataFixturesDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\Console\Style\SymfonyStyle;
use const E_USER_DEPRECATED;
use function implode;
use function method_exists;
use function sprintf;
use function trigger_error;

Expand All @@ -38,7 +39,8 @@ public function __construct(SymfonyFixturesLoader $fixturesLoader, ?ManagerRegis
), E_USER_DEPRECATED);
}

parent::__construct($doctrine);
// @todo The method_exists call can be removed once the DoctrineBundle dependency has been bumped to at least 1.10
parent::__construct(method_exists($this, 'getDoctrine') ? $doctrine : null);

$this->fixturesLoader = $fixturesLoader;
}
Expand Down Expand Up @@ -83,9 +85,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$ui = new SymfonyStyle($input, $output);

/** @var ManagerRegistry $doctrine */
$doctrine = $this->getContainer()->get('doctrine');
$em = $doctrine->getManager($input->getOption('em'));
// @todo The method_exists call can be removed once the DoctrineBundle dependency has been bumped to at least 1.10
if (method_exists($this, 'getDotrine')) {
$doctrine = $this->getDoctrine();
} else {
/** @var ManagerRegistry $doctrine */
$doctrine = $this->getContainer()->get('doctrine');
}

$em = $doctrine->getManager($input->getOption('em'));

if (! $input->getOption('append')) {
if (! $ui->confirm(sprintf('Careful, database "%s" will be purged. Do you want to continue?', $em->getConnection()->getDatabase()), ! $input->isInteractive())) {
Expand Down
36 changes: 36 additions & 0 deletions Tests/Command/LoadDataFixturesDoctrineCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Doctrine\Bundle\FixturesBundle\Tests\Command;

use Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand;
use Doctrine\Bundle\FixturesBundle\Loader\SymfonyFixturesLoader;
use Doctrine\Common\Persistence\ManagerRegistry;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Container;

class LoadDataFixturesDoctrineCommandTest extends TestCase
{
/**
* @group legacy
* @expectedDeprecation The "Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand" constructor expects a "Doctrine\Common\Persistence\ManagerRegistry" instance as second argument, not passing it will throw a \TypeError in DoctrineFixturesBundle 4.0.
*/
public function testInstantiatingWithoutManagerRegistry() : void
{
$loader = new SymfonyFixturesLoader(new Container());

new LoadDataFixturesDoctrineCommand($loader);
}

/**
* @doesNotPerformAssertions
*/
public function testInstantiatingWithManagerRegistry() : void
{
$registry = $this->createMock(ManagerRegistry::class);
$loader = new SymfonyFixturesLoader(new Container());

new LoadDataFixturesDoctrineCommand($loader, $registry);
}
}
4 changes: 4 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@
</exclude>
</whitelist>
</filter>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
</phpunit>

0 comments on commit f0db517

Please sign in to comment.