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

Remove workaround for testing with PHP 8 #344

Merged
merged 3 commits into from
Feb 17, 2021
Merged
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
5 changes: 0 additions & 5 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ jobs:
coverage: "xdebug"
ini-values: "zend.assertions=1"

# to be removed when doctrine/orm adds support for PHP 8
- name: "Pretend this is PHP 7.4"
run: "composer config platform.php 7.4.99"
if: "${{ matrix.php-version == '8.0' }}"

- name: "Use dev stability"
run: "composer config minimum-stability dev"
if: "${{ matrix.stability == 'dev' }}"
Expand Down
10 changes: 5 additions & 5 deletions Command/LoadDataFixturesDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use const E_USER_DEPRECATED;

use function implode;
use function sprintf;
use function trigger_error;

use const E_USER_DEPRECATED;

/**
* Load data fixtures from bundles.
*/
Expand Down Expand Up @@ -52,14 +54,13 @@ public function __construct(SymfonyFixturesLoader $fixturesLoader, ?ManagerRegis
$this->purgerFactories = $purgerFactories;
}

// phpcs:ignore SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint
protected function configure()
{
$this
->setName('doctrine:fixtures:load')
->setDescription('Load data fixtures to your database')
->addOption('append', null, InputOption::VALUE_NONE, 'Append the data fixtures instead of deleting all data from the database first.')
->addOption('group', null, InputOption::VALUE_IS_ARRAY|InputOption::VALUE_REQUIRED, 'Only load fixtures that belong to this group')
->addOption('group', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Only load fixtures that belong to this group')
->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.')
->addOption('purger', null, InputOption::VALUE_REQUIRED, 'The purger to use for this command', 'default')
->addOption('purge-exclusions', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'List of database tables to ignore while purging')
Expand Down Expand Up @@ -92,7 +93,6 @@ protected function configure()
/**
* @return int
*/
// phpcs:ignore SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint
protected function execute(InputInterface $input, OutputInterface $output)
{
$ui = new SymfonyStyle($input, $output);
Expand Down Expand Up @@ -149,7 +149,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$input->getOption('purge-with-truncate')
);
$executor = new ORMExecutor($em, $purger);
$executor->setLogger(static function ($message) use ($ui) : void {
$executor->setLogger(static function ($message) use ($ui): void {
$ui->text(sprintf(' <comment>></comment> <info>%s</info>', $message));
});
$executor->execute($fixtures, $input->getOption('append'));
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/CompilerPass/FixturesCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class FixturesCompilerPass implements CompilerPassInterface
{
public const FIXTURE_TAG = 'doctrine.fixture.orm';

public function process(ContainerBuilder $container) : void
public function process(ContainerBuilder $container): void
{
$definition = $container->getDefinition('doctrine.fixtures.loader');
$taggedServices = $container->findTaggedServiceIds(self::FIXTURE_TAG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

use function sprintf;

final class PurgerFactoryCompilerPass implements CompilerPassInterface
{
public const PURGER_FACTORY_TAG = 'doctrine.fixtures.purger_factory';

public function process(ContainerBuilder $container) : void
public function process(ContainerBuilder $container): void
{
$definition = $container->getDefinition('doctrine.fixtures_load_command');
$taggedServices = $container->findTaggedServiceIds(self::PURGER_FACTORY_TAG);
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/DoctrineFixturesExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

use function dirname;

class DoctrineFixturesExtension extends Extension
Expand Down
4 changes: 0 additions & 4 deletions DoctrineFixturesBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
* Bundle.
*/
class DoctrineFixturesBundle extends Bundle
{
// phpcs:ignore SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint
public function build(ContainerBuilder $container)
{
$container->addCompilerPass(new FixturesCompilerPass());
Expand Down
2 changes: 1 addition & 1 deletion FixtureGroupInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ interface FixtureGroupInterface
*
* @return string[]
*/
public static function getGroups() : array;
public static function getGroups(): array;
}
18 changes: 10 additions & 8 deletions Loader/SymfonyFixturesLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use ReflectionClass;
use RuntimeException;
use Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader;

use function array_key_exists;
use function array_values;
use function get_class;
Expand All @@ -27,8 +28,10 @@ final class SymfonyFixturesLoader extends ContainerAwareLoader

/**
* @internal
*
* @psalm-param list<array{fixture: FixtureInterface, groups: list<string>}> $fixtures
*/
public function addFixtures(array $fixtures) : void
public function addFixtures(array $fixtures): void
{
// Because parent::addFixture may call $this->createFixture
// we cannot call $this->addFixture in this loop
Expand All @@ -45,7 +48,7 @@ public function addFixtures(array $fixtures) : void
}
}

public function addFixture(FixtureInterface $fixture) : void
public function addFixture(FixtureInterface $fixture): void
{
$class = get_class($fixture);
$this->loadedFixtures[$class] = $fixture;
Expand All @@ -62,10 +65,9 @@ public function addFixture(FixtureInterface $fixture) : void

/**
* Overridden to not allow new fixture classes to be instantiated.
*
* @param string $class
* {@inheritDoc}
*/
protected function createFixture($class) : FixtureInterface
protected function createFixture($class): FixtureInterface
{
/*
* We don't actually need to create the fixture. We just
Expand All @@ -90,7 +92,7 @@ protected function createFixture($class) : FixtureInterface
*
* @return FixtureInterface[]
*/
public function getFixtures(array $groups = []) : array
public function getFixtures(array $groups = []): array
{
$fixtures = parent::getFixtures();

Expand Down Expand Up @@ -121,7 +123,7 @@ public function getFixtures(array $groups = []) : array
*
* @param string[] $groups
*/
private function addGroupsFixtureMapping(string $className, array $groups) : void
private function addGroupsFixtureMapping(string $className, array $groups): void
{
foreach ($groups as $group) {
$this->groupsFixtureMapping[$group][$className] = true;
Expand All @@ -133,7 +135,7 @@ private function addGroupsFixtureMapping(string $className, array $groups) : voi
*
* @throws RuntimeException
*/
private function validateDependencies(array $fixtures, FixtureInterface $fixture) : void
private function validateDependencies(array $fixtures, FixtureInterface $fixture): void
{
if (! $fixture instanceof DependentFixtureInterface) {
return;
Expand Down
11 changes: 9 additions & 2 deletions Purger/ORMPurgerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@

final class ORMPurgerFactory implements PurgerFactory
{
public function createForEntityManager(?string $emName, EntityManagerInterface $em, array $excluded = [], bool $purgeWithTruncate = false) : PurgerInterface
{
/**
* {@inheritDoc}
*/
public function createForEntityManager(
?string $emName,
EntityManagerInterface $em,
array $excluded = [],
bool $purgeWithTruncate = false
): PurgerInterface {
$purger = new ORMPurger($em, $excluded);
$purger->setPurgeMode($purgeWithTruncate ? ORMPurger::PURGE_MODE_TRUNCATE : ORMPurger::PURGE_MODE_DELETE);

Expand Down
10 changes: 9 additions & 1 deletion Purger/PurgerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@

interface PurgerFactory
{
public function createForEntityManager(?string $emName, EntityManagerInterface $em, array $excluded = [], bool $purgeWithTruncate = false) : PurgerInterface;
/**
* @psalm-param list<string> $excluded
*/
public function createForEntityManager(
?string $emName,
EntityManagerInterface $em,
array $excluded = [],
bool $purgeWithTruncate = false
): PurgerInterface;
}
22 changes: 10 additions & 12 deletions Tests/Command/LoadDataFixturesDoctrineCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,36 @@

namespace Doctrine\Bundle\FixturesBundle\Tests\Command;

use Doctrine\Bundle\DoctrineBundle\Command\DoctrineCommand;
use Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand;
use Doctrine\Bundle\FixturesBundle\Loader\SymfonyFixturesLoader;
use Doctrine\Persistence\ManagerRegistry;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Container;
use TypeError;
use const PHP_VERSION_ID;

use function sprintf;

use const PHP_VERSION_ID;

class LoadDataFixturesDoctrineCommandTest extends TestCase
{
/**
* @group legacy
* @expectedDeprecation Argument 2 of Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand::__construct() expects an instance of Doctrine\Persistence\ManagerRegistry, not passing it will throw a \TypeError in DoctrineFixturesBundle 4.0.
*/
public function testInstantiatingWithoutManagerRegistry() : void
public function testInstantiatingWithoutManagerRegistry(): void
{
$loader = new SymfonyFixturesLoader(new Container());

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/runner/work/DoctrineFixturesBundle/DoctrineFixturesBundle/Command/LoadDataFixturesDoctrineCommand.php on line 49
MESSAGE
);
throw $e;
}
$this->expectExceptionMessage(sprintf(
'Argument 1 passed to Doctrine\Bundle\DoctrineBundle\Command\DoctrineCommand::__construct() must be an instance of %s, null given',
PHP_VERSION_ID >= 80000 ?
'%s::__construct(): Argument #1 ($doctrine) must be of type %s, null given' :
'Argument 1 passed to %s::__construct() must be an instance of %s, null given',
DoctrineCommand::class,
ManagerRegistry::class
));

Expand All @@ -46,7 +44,7 @@ public function testInstantiatingWithoutManagerRegistry() : void
/**
* @doesNotPerformAssertions
*/
public function testInstantiatingWithManagerRegistry() : void
public function testInstantiatingWithManagerRegistry(): void
{
$registry = $this->createMock(ManagerRegistry::class);
$loader = new SymfonyFixturesLoader(new Container());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@

class DependentOnRequiredConstructorArgsFixtures implements ORMFixtureInterface, DependentFixtureInterface
{
public function load(ObjectManager $manager) : void
public function load(ObjectManager $manager): void
{
// ...
}

public function getDependencies() : array
/**
* {@inheritDoc}
*/
public function getDependencies(): array
{
return [RequiredConstructorArgsFixtures::class];
}
Expand Down
7 changes: 5 additions & 2 deletions Tests/Fixtures/FooBundle/DataFixtures/OtherFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@

class OtherFixtures implements ORMFixtureInterface, FixtureGroupInterface
{
public function load(ObjectManager $manager) : void
public function load(ObjectManager $manager): void
{
// ...
}

public static function getGroups() : array
/**
* {@inheritDoc}
*/
public static function getGroups(): array
{
return ['staging', 'fulfilledDependencyGroup'];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct(string $fooRequiredArg)
{
}

public function load(ObjectManager $manager) : void
public function load(ObjectManager $manager): void
{
// ...
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,23 @@

class WithDependenciesFixtures implements ORMFixtureInterface, DependentFixtureInterface, FixtureGroupInterface
{
public function load(ObjectManager $manager) : void
public function load(ObjectManager $manager): void
{
// ...
}

public function getDependencies() : array
/**
* {@inheritDoc}
*/
public function getDependencies(): array
{
return [OtherFixtures::class];
}

public static function getGroups() : array
/**
* {@inheritDoc}
*/
public static function getGroups(): array
{
return ['missingDependencyGroup', 'fulfilledDependencyGroup'];
}
Expand Down
Loading