Skip to content

Commit

Permalink
chore: remove annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
alexislefebvre committed Mar 10, 2024
1 parent d517a8f commit 696c0e0
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 148 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ jobs:
composer config extra.symfony.require "${{ matrix.symfony-version }}"
composer require --no-update symfony/framework-bundle=${{ matrix.symfony-version }}
# This is needed to fix builds on Symfony 5.4 where the `annotation_reader` service may not be set up if the Annotations package is not in the production dependencies
- name: Move Annotations to require
run: composer require --no-update "doctrine/annotations:^1.8.0|^2.0"

- name: Install Composer dependencies
if: matrix.composer-flags == ''
run: composer install
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"symfony/yaml": "^5.4 || ^6.3 || ^7.0"
},
"require-dev": {
"doctrine/annotations": "^1.8.0 || ^2.0",
"doctrine/data-fixtures": "^1.7",
"doctrine/doctrine-bundle": "^2.11",
"doctrine/doctrine-fixtures-bundle": "^3.5.1 || ^4.0",
Expand Down
8 changes: 1 addition & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
beStrictAboutOutputDuringTests="true"
processIsolation="true"
>

<php>
Expand All @@ -18,11 +19,4 @@
<directory>tests/Test</directory>
</testsuite>
</testsuites>

<groups>
<exclude>
<group>mysql</group>
<group>pgsql</group>
</exclude>
</groups>
</phpunit>
9 changes: 2 additions & 7 deletions src/Services/DatabaseToolCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Liip\TestFixturesBundle\Services;

use Doctrine\Common\Annotations\Reader;
use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool;
use Symfony\Bridge\Doctrine\ManagerRegistry;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand All @@ -25,21 +24,17 @@ final class DatabaseToolCollection
{
private ContainerInterface $container;

/** @var Reader|null */
private $annotationReader;

/**
* @var AbstractDatabaseTool[][]
*/
private array $items = [];

public function __construct(ContainerInterface $container, ?Reader $annotationReader = null)
public function __construct(ContainerInterface $container, mixed $annotationReader = null)
{
$this->container = $container;
$this->annotationReader = $annotationReader;

if (null !== $annotationReader) {
trigger_deprecation('liip/test-fixtures-bundle', '2.5', 'Passing a "%s" to the "%s" constructor is deprecated.', Reader::class, self::class);
throw new \RuntimeException(sprintf('Passing a second argument to the "%s" constructor is not supported since liip/test-fixtures-bundle 3.0.', self::class));
}
}

Expand Down
24 changes: 0 additions & 24 deletions tests/App/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,24 @@
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*
* @ORM\Table(name="liip_user")
*/
#[ORM\Entity]
#[ORM\Table(name: 'liip_user')]
class User
{
/**
* @ORM\Id
*
* @ORM\Column(type="integer")
*
* @ORM\GeneratedValue(strategy="AUTO")
*/
#[ORM\Id]
#[ORM\Column(type: Types::INTEGER)]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private ?int $id = null;

/**
* @ORM\Column
*/
#[ORM\Column]
private string $name;

/**
* @ORM\Column
*/
#[ORM\Column]
private string $salt;

/**
* @ORM\Column
*/
#[ORM\Column]
private string $email;

/**
* @ORM\Column(nullable=true)
*/
#[ORM\Column(nullable: true)]
private ?string $dummyText = null;

Expand Down
32 changes: 12 additions & 20 deletions tests/Test/ConfigEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@

namespace Liip\Acme\Tests\Test;

use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation;
use Liip\Acme\Tests\AppConfigEvents\AppConfigEventsKernel;
use Liip\Acme\Tests\AppConfigEvents\EventListener\FixturesSubscriber;
use Liip\Acme\Tests\Traits\ContainerProvider;
use Liip\TestFixturesBundle\LiipTestFixturesEvents;
use Liip\TestFixturesBundle\Services\DatabaseToolCollection;
use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool;
use Liip\TestFixturesBundle\Services\DatabaseTools\ORMSqliteDatabaseTool;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

/**
Expand All @@ -30,14 +31,9 @@
* Tests/App/AppKernel.php.
* So it must be loaded in a separate process.
*
* @runTestsInSeparateProcesses
*
* @preserveGlobalState disabled
*
* @IgnoreAnnotation("dataProvider")
*
* @internal
*/
#[PreserveGlobalState(false)]
class ConfigEventsTest extends KernelTestCase
{
use ContainerProvider;
Expand Down Expand Up @@ -88,10 +84,9 @@ public function testLoadEmptyFixturesAndCheckEvents(): void
* Check that events are called.
*
* We disable the cache to ensure that all the code is executed.
*
* @dataProvider fixturesEventsProvider
*/
public function testLoadEmptyFixturesAndCheckEventsAreCalled(string $eventName, string $methodName, int $numberOfInvocations, bool $withCache = true): void
#[DataProvider('fixturesEventsProvider')]
public function testLoadEmptyFixturesAndCheckEventsAreCalled(string $eventName, string $methodName, int $numberOfInvocations, ?bool $withCache = true): void
{
/** @var AbstractDatabaseTool $databaseTool */
$databaseTool = $this->getTestContainer()->get(DatabaseToolCollection::class)->get();
Expand Down Expand Up @@ -127,9 +122,8 @@ public function testLoadEmptyFixturesAndCheckEventsAreCalled(string $eventName,

/**
* We disable the cache to ensure that other events are called.
*
* @dataProvider fixturesEventsProvider
*/
#[DataProvider('fixturesEventsProvider')]
public function testLoadEmptyFixturesAndCheckEventsAreCalledWithoutCache(string $eventName, string $methodName, int $numberOfInvocations): void
{
// Swap 0 → 1 and 1 → 0
Expand All @@ -138,15 +132,13 @@ public function testLoadEmptyFixturesAndCheckEventsAreCalledWithoutCache(string
$this->testLoadEmptyFixturesAndCheckEventsAreCalled($eventName, $methodName, $numberOfInvocations, false);
}

public static function fixturesEventsProvider(): array
public static function fixturesEventsProvider(): iterable
{
return [
[LiipTestFixturesEvents::PRE_FIXTURE_BACKUP_RESTORE, 'preFixtureBackupRestore', 1],
[LiipTestFixturesEvents::POST_FIXTURE_SETUP, 'postFixtureSetup', 0],
[LiipTestFixturesEvents::POST_FIXTURE_BACKUP_RESTORE, 'postFixtureBackupRestore', 1],
[LiipTestFixturesEvents::PRE_REFERENCE_SAVE, 'preReferenceSave', 0],
[LiipTestFixturesEvents::POST_REFERENCE_SAVE, 'postReferenceSave', 0],
];
yield 'preFixtureBackupRestore' => [LiipTestFixturesEvents::PRE_FIXTURE_BACKUP_RESTORE, 'preFixtureBackupRestore', 1];
yield 'postFixtureSetup' => [LiipTestFixturesEvents::POST_FIXTURE_SETUP, 'postFixtureSetup', 0];
yield 'postFixtureBackupRestore' => [LiipTestFixturesEvents::POST_FIXTURE_BACKUP_RESTORE, 'postFixtureBackupRestore', 1];
yield 'preReferenceSave' => [LiipTestFixturesEvents::PRE_REFERENCE_SAVE, 'preReferenceSave', 0];
yield 'postReferenceSave' => [LiipTestFixturesEvents::POST_REFERENCE_SAVE, 'postReferenceSave', 0];
}

protected static function getKernelClass(): string
Expand Down
20 changes: 15 additions & 5 deletions tests/Test/ConfigMongodbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

declare(strict_types=1);

/*
* This file is part of the Liip/TestFixturesBundle
*
* (c) Lukas Kahwe Smith <smith@pooteeweet.org>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Liip\Acme\Tests\Test;

/*
* This file is part of the Liip/TestFixturesBundle
*
Expand All @@ -12,6 +23,7 @@
*/

use Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle;
use Doctrine\Common\DataFixtures\Executor\MongoDBExecutor;
use Doctrine\Common\DataFixtures\ProxyReferenceRepository;
use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
use Liip\Acme\Tests\AppConfigMongodb\AppConfigMongodbKernel;
Expand All @@ -21,6 +33,7 @@
use Liip\TestFixturesBundle\Services\DatabaseToolCollection;
use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool;
use Liip\TestFixturesBundle\Services\DatabaseTools\MongoDBDatabaseTool;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

/**
Expand All @@ -30,12 +43,9 @@
* Tests/App/AppKernel.php.
* So it must be loaded in a separate process.
*
* @#runTestsInSeparateProcesses
*
* @preserveGlobalState disabled
*
* @internal
*/
#[PreserveGlobalState(false)]
class ConfigMongodbTest extends KernelTestCase
{
use ContainerProvider;
Expand Down Expand Up @@ -75,7 +85,7 @@ public function testLoadFixturesMongodb(): void
]);

$this->assertInstanceOf(
Doctrine\Common\DataFixtures\Executor\MongoDBExecutor::class,
MongoDBExecutor::class,
$fixtures
);

Expand Down
16 changes: 3 additions & 13 deletions tests/Test/ConfigMysqlCacheDbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

namespace Liip\Acme\Tests\Test;

use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation;
use Liip\Acme\Tests\App\Entity\User;
use Liip\Acme\Tests\AppConfigMysqlCacheDb\AppConfigMysqlKernelCacheDb;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\PreserveGlobalState;

/**
* Test MySQL database with database caching enabled.
Expand All @@ -31,19 +32,11 @@
* Tests/App/AppKernel.php.
* So it must be loaded in a separate process.
*
* @runTestsInSeparateProcesses
*
* @preserveGlobalState disabled
*
* @IgnoreAnnotation("group")
*
* @internal
*/
#[PreserveGlobalState(false)]
class ConfigMysqlCacheDbTest extends ConfigMysqlTest
{
/**
* @group mysql
*/
public function testLoadFixturesAndCheckBackup(): void
{
$this->assertTrue($this->databaseTool->isDatabaseCacheEnabled());
Expand Down Expand Up @@ -114,9 +107,6 @@ public function testLoadFixturesAndCheckBackup(): void
);
}

/**
* @group mysql
*/
public function testLoadFixturesCheckReferences(): void
{
$this->markTestSkipped('This test is broken right now.');
Expand Down
9 changes: 2 additions & 7 deletions tests/Test/ConfigMysqlKeepDatabaseAndSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

namespace Liip\Acme\Tests\Test;

use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation;
use Liip\Acme\Tests\AppConfigMysqlKeepDatabaseAndSchema\AppConfigMysqlKernelKeepDatabaseAndSchema;
use PHPUnit\Framework\Attributes\PreserveGlobalState;

/**
* Test MySQL database with database caching enabled.
Expand All @@ -30,14 +30,9 @@
* Tests/App/AppKernel.php.
* So it must be loaded in a separate process.
*
* @runTestsInSeparateProcesses
*
* @preserveGlobalState disabled
*
* @IgnoreAnnotation("group")
*
* @internal
*/
#[PreserveGlobalState(false)]
class ConfigMysqlKeepDatabaseAndSchemaTest extends ConfigMysqlTest
{
protected static function getKernelClass(): string
Expand Down
Loading

0 comments on commit 696c0e0

Please sign in to comment.