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

Merge 3.6.x up into 4.0.x #435

Merged
merged 21 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3b81e67
Update index.rst
Dumkaaa Dec 15, 2023
6c3253b
Merge pull request #419 from Dumkaaa/patch-1
greg0ire Dec 15, 2023
b83a046
Dismiss new PHPStan issues
greg0ire Mar 27, 2024
e1db891
Merge pull request #424 from greg0ire/baseline-issues
greg0ire Mar 28, 2024
c27df72
Merge pull request #425 from doctrine/3.5.x
greg0ire Mar 28, 2024
134bd7e
Switch to a modern directory structure
greg0ire Mar 29, 2024
33c2627
Configure docs path depending on the branch
greg0ire Mar 29, 2024
73d9271
Remove changelog (#428)
greg0ire Mar 30, 2024
838207b
Merge pull request #426 from greg0ire/modern-directory-structure
greg0ire Apr 1, 2024
7727a85
Merge pull request #427 from greg0ire/dynamic-docs-path
greg0ire Apr 1, 2024
bbaac82
Bump workflow actions
greg0ire Apr 2, 2024
0e15b20
Merge pull request #429 from greg0ire/bump-workflows
SenseException Apr 2, 2024
8b3d927
Automatically extract fixture dependencies
cs278 Jan 16, 2024
b7f5ed4
Merge pull request #421 from cs278/load-dependencies
greg0ire May 2, 2024
87f5d53
Merge pull request #431 from doctrine/3.5.x
greg0ire May 2, 2024
0a2f769
Update branch metadata
greg0ire May 2, 2024
05084ff
Address deprecation of HttpKernel Extension class
greg0ire May 2, 2024
82a6a68
Merge remote-tracking branch 'origin/3.6.x' into 4.0.x
greg0ire May 2, 2024
3a3dda5
Merge pull request #434 from greg0ire/fix-build
greg0ire May 2, 2024
b359438
Merge pull request #433 from greg0ire/update-branch-metadata
greg0ire May 2, 2024
ceaf8f1
Merge remote-tracking branch 'origin/3.6.x' into 4.0.x
greg0ire May 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/.gitattributes export-ignore
/.github export-ignore
/.gitignore export-ignore
/Tests export-ignore
/tests export-ignore
/phpcs.xml.dist export-ignore
/phpunit.xml.dist export-ignore
/phpstan.neon.dist export-ignore
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ on:
jobs:
coding-standards:
name: "Coding Standards"
uses: "doctrine/.github/.github/workflows/coding-standards.yml@3.1.0"
uses: "doctrine/.github/.github/workflows/coding-standards.yml@4.0.0"
2 changes: 1 addition & 1 deletion .github/workflows/release-on-milestone-closed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
release:
name: "Git tag, release & create merge-up PR"
uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@3.1.0"
uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@4.0.0"
secrets:
GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }}
GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ on:

jobs:
static-analysis:
uses: "doctrine/.github/.github/workflows/static-analysis.yml@3.1.0"
uses: "doctrine/.github/.github/workflows/static-analysis.yml@4.0.0"
16 changes: 12 additions & 4 deletions .symfony.bundle.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
branches: ["3.3.x", "3.4.x", "3.5.x", "3.6.x"]
maintained_branches: ["3.5.x", "3.6.x"]
doc_dir: "Resources/doc/"
dev_branch: "3.6.x"
branches:
- "3.3.x"
- "3.4.x"
- "3.5.x"
- "3.6.x"
- "3.7.x"
maintained_branches:
- "3.5.x"
- "3.6.x"
- "3.7.x"
doc_dir: "docs/"
dev_branch: "3.7.x"
14 changes: 0 additions & 14 deletions CHANGELOG-3.1.md

This file was deleted.

5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
"doctrine/dbal": "< 3"
},
"autoload": {
"psr-4": { "Doctrine\\Bundle\\FixturesBundle\\": "" }
"psr-4": { "Doctrine\\Bundle\\FixturesBundle\\": "src" }
},
"autoload-dev": {
"psr-4": { "Doctrine\\Bundle\\FixturesBundle\\Tests\\": "tests" }
},
"config": {
"sort-packages": true,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion Resources/doc/index.rst → docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ First, add a new ``PSR-4`` autoload-entry in the ``composer.json`` with the new

.. note::

You need to dump the autoloader with ``composer dump-autoloader``
You need to dump the autoloader with ``composer dump-autoload``

Then, enable Dependency Injection for the ``fixtures`` directory:

Expand Down
16 changes: 8 additions & 8 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@
<!-- Ignore warnings and show progress of the run -->
<arg value="nps"/>

<file>.</file>
<exclude-pattern>/vendor</exclude-pattern>
<file>src</file>
<file>tests</file>

<rule ref="Doctrine" />


<rule ref="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix">
<exclude-pattern>FixtureGroupInterface.php</exclude-pattern>
<exclude-pattern>ORMFixtureInterface.php</exclude-pattern>
<exclude-pattern>src/FixtureGroupInterface.php</exclude-pattern>
<exclude-pattern>src/ORMFixtureInterface.php</exclude-pattern>
</rule>
<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
<exclude-pattern>Loader/SymfonyBridgeLoader.php</exclude-pattern>
<exclude-pattern>Command/CommandCompatibility.php</exclude-pattern>
<exclude-pattern>Tests/IntegrationTest.php</exclude-pattern>
<exclude-pattern>src/Loader/SymfonyBridgeLoader.php</exclude-pattern>
<exclude-pattern>src/Command/CommandCompatibility.php</exclude-pattern>
<exclude-pattern>tests/IntegrationTest.php</exclude-pattern>
</rule>
<rule ref="Squiz.Classes.ClassFileName.NoMatch">
<exclude-pattern>Tests/IntegrationTest.php</exclude-pattern>
<exclude-pattern>tests/IntegrationTest.php</exclude-pattern>
</rule>
</ruleset>
3 changes: 1 addition & 2 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ parameters:
-
message: "#^Constructor of class Doctrine\\\\Bundle\\\\FixturesBundle\\\\Tests\\\\Fixtures\\\\FooBundle\\\\DataFixtures\\\\RequiredConstructorArgsFixtures has an unused parameter \\$fooRequiredArg\\.$#"
count: 1
path: Tests/Fixtures/FooBundle/DataFixtures/RequiredConstructorArgsFixtures.php

path: tests/Fixtures/FooBundle/DataFixtures/RequiredConstructorArgsFixtures.php
5 changes: 2 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ parameters:
phpVersion: 80100
level: 3
paths:
- .
excludePaths:
- vendor
- src
- tests

includes:
- phpstan-baseline.neon
9 changes: 2 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@
<phpunit colors="true" bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="DoctrineFixturesBundle for the Symfony Framework">
<directory>./Tests</directory>
<directory>./tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>.</directory>
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
<directory>src</directory>
</whitelist>
</filter>

Expand Down
11 changes: 2 additions & 9 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,8 @@
findUnusedCode="false"
>
<projectFiles>
<directory name="Command" />
<directory name="DependencyInjection" />
<directory name="Loader" />
<directory name="Purger" />
<directory name="Tests" />
<file name="DoctrineFixturesBundle.php" />
<file name="Fixture.php" />
<file name="FixtureGroupInterface.php" />
<file name="ORMFixtureInterface.php" />
<directory name="src" />
<directory name="tests" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use Doctrine\Bundle\FixturesBundle\ORMFixtureInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

use function dirname;

Expand All @@ -20,7 +20,7 @@ class DoctrineFixturesExtension extends Extension
*/
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new XmlFileLoader($container, new FileLocator(dirname(__DIR__) . '/Resources/config'));
$loader = new XmlFileLoader($container, new FileLocator(dirname(__DIR__) . '/../config'));

$loader->load('services.xml');

Expand Down
7 changes: 7 additions & 0 deletions DoctrineFixturesBundle.php → src/DoctrineFixturesBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

use function dirname;

class DoctrineFixturesBundle extends Bundle
{
public function build(ContainerBuilder $container): void
{
$container->addCompilerPass(new FixturesCompilerPass());
$container->addCompilerPass(new PurgerFactoryCompilerPass());
}

public function getPath(): string
{
return dirname(__DIR__);
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
use Doctrine\Common\DataFixtures\Loader;
use LogicException;
use ReflectionClass;
use RuntimeException;

use function array_key_exists;
use function array_keys;
use function array_values;
use function get_class;
use function sprintf;
Expand Down Expand Up @@ -100,19 +99,22 @@ public function getFixtures(array $groups = []): array
return $fixtures;
}

$filteredFixtures = [];
foreach ($fixtures as $fixture) {
foreach ($groups as $group) {
$fixtureClass = $fixture::class;
if (isset($this->groupsFixtureMapping[$group][$fixtureClass])) {
$filteredFixtures[$fixtureClass] = $fixture;
continue 2;
}
$requiredFixtures = [];
foreach ($groups as $group) {
if (! isset($this->groupsFixtureMapping[$group])) {
continue;
}

$requiredFixtures += $this->collectDependencies(...array_keys($this->groupsFixtureMapping[$group]));
}

foreach ($filteredFixtures as $fixture) {
$this->validateDependencies($filteredFixtures, $fixture);
$filteredFixtures = [];
foreach ($fixtures as $order => $fixture) {
$fixtureClass = $fixture::class;
if (isset($requiredFixtures[$fixtureClass])) {
$filteredFixtures[$order] = $fixture;
continue;
}
}

return array_values($filteredFixtures);
Expand All @@ -131,22 +133,25 @@ private function addGroupsFixtureMapping(string $className, array $groups): void
}

/**
* @param string[] $fixtures An array of fixtures with class names as keys
* Collect any dependent fixtures from the given classes.
*
* @throws RuntimeException
* @psalm-return array<string,true>
*/
private function validateDependencies(array $fixtures, FixtureInterface $fixture): void
private function collectDependencies(string ...$fixtureClass): array
{
if (! $fixture instanceof DependentFixtureInterface) {
return;
}
$dependencies = [];

$dependenciesClasses = $fixture->getDependencies();
foreach ($fixtureClass as $class) {
$dependencies[$class] = true;
$fixture = $this->getFixture($class);

foreach ($dependenciesClasses as $class) {
if (! array_key_exists($class, $fixtures)) {
throw new RuntimeException(sprintf('Fixture "%s" was declared as a dependency for fixture "%s", but it was not included in any of the loaded fixture groups.', $class, $fixture::class));
if (! $fixture instanceof DependentFixtureInterface) {
continue;
}

$dependencies += $this->collectDependencies(...$fixture->getDependencies());
}

return $dependencies;
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures;

use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
use Doctrine\Bundle\FixturesBundle\ORMFixtureInterface;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;

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

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

/**
* {@inheritDoc}
*/
public static function getGroups(): array
{
return ['groupWithDeepDependencies'];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public function getDependencies(): array
*/
public static function getGroups(): array
{
return ['missingDependencyGroup', 'fulfilledDependencyGroup'];
return ['groupWithDependencies', 'fulfilledDependencyGroup'];
}
}
23 changes: 15 additions & 8 deletions Tests/IntegrationTest.php → tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Doctrine\Bundle\FixturesBundle\Purger\PurgerFactory;
use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\DependentOnRequiredConstructorArgsFixtures;
use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\OtherFixtures;
use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\RequiredConstructorArgsFixtures;
use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\WithDeepDependenciesFixtures;
use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\WithDependenciesFixtures;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use Doctrine\Common\EventManager;
Expand All @@ -19,7 +21,6 @@
use Doctrine\Persistence\ManagerRegistry;
use LogicException;
use PHPUnit\Framework\TestCase;
use RuntimeException;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -171,18 +172,26 @@ public function testFixturesLoaderWithGroupsOptionViaTag(): void
$this->assertCount(0, $loader->getFixtures(['group3']));
}

public function testLoadFixturesViaGroupWithMissingDependency(): void
public function testLoadFixturesViaGroupWithDependenciesNotInGroup(): void
{
$kernel = new IntegrationTestKernel('dev', true);
$kernel->addServices(static function (ContainerBuilder $c): void {
// has a "staging" group via the getGroups() method
$c->autowire(OtherFixtures::class)
->addTag(FixturesCompilerPass::FIXTURE_TAG);

// no getGroups() method
$c->autowire(WithDependenciesFixtures::class)
->addTag(FixturesCompilerPass::FIXTURE_TAG);

$c->autowire(WithDeepDependenciesFixtures::class)
->addTag(FixturesCompilerPass::FIXTURE_TAG);

$c->autowire(RequiredConstructorArgsFixtures::class)
->setArgument('$fooRequiredArg', 'test')
->addTag(FixturesCompilerPass::FIXTURE_TAG);

$c->autowire(DependentOnRequiredConstructorArgsFixtures::class)
->addTag(FixturesCompilerPass::FIXTURE_TAG);

$c->setAlias('test.doctrine.fixtures.loader', new Alias('doctrine.fixtures.loader', true));
});
$kernel->boot();
Expand All @@ -191,10 +200,8 @@ public function testLoadFixturesViaGroupWithMissingDependency(): void
$loader = $container->get('test.doctrine.fixtures.loader');
$this->assertInstanceOf(SymfonyFixturesLoader::class, $loader);

$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Fixture "Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\OtherFixtures" was declared as a dependency for fixture "Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\WithDependenciesFixtures", but it was not included in any of the loaded fixture groups.');

$loader->getFixtures(['missingDependencyGroup']);
self::assertCount(2, $loader->getFixtures(['groupWithDependencies']));
self::assertCount(5, $loader->getFixtures(['groupWithDeepDependencies']));
}

public function testLoadFixturesViaGroupWithFulfilledDependency(): void
Expand Down
File renamed without changes.