Skip to content

Commit

Permalink
Run tests without doctrine/annotations installed (#2781)
Browse files Browse the repository at this point in the history
* Add a test build with doctrine/annotations uninstalled

* Update tests to only register either the annotation or attribute driver to avoid unintended overwrites due to namespaces

* Don't fail fast to let all jobs run

* Need new coverage artifact names for no-annotations builds
  • Loading branch information
mbabker committed Jun 9, 2024
1 parent 58ca22b commit c16c401
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 39 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env:

jobs:
phpunit:
name: "PHPUnit ${{ matrix.php-version }} (${{ matrix.deps }})"
name: "PHPUnit ${{ matrix.php-version }} (${{ matrix.deps }})${{ matrix.no-annotations == true && ' - Without Annotations' || '' }}"
runs-on: "ubuntu-20.04"

services:
Expand All @@ -21,6 +21,7 @@ jobs:
- 27017:27017

strategy:
fail-fast: false
matrix:
php-version:
- "7.4"
Expand All @@ -30,11 +31,19 @@ jobs:
- "8.3"
deps:
- "highest"
no-annotations:
- false
include:
- deps: "lowest"
php-version: "7.4"
- deps: "highest"
php-version: "8.3"
- deps: "highest"
php-version: "7.4"
no-annotations: true
- deps: "highest"
php-version: "8.3"
no-annotations: true

steps:
- name: "Checkout"
Expand All @@ -53,6 +62,11 @@ jobs:
- name: "Remove PHP-CS-Fixer"
run: "composer remove --dev --no-update friendsofphp/php-cs-fixer"

# Remove doctrine/annotations if configured to do so
- name: "Remove doctrine/annotations"
if: "${{ matrix.no-annotations }}"
run: "composer remove --dev --no-update doctrine/annotations"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v3"
with:
Expand All @@ -64,7 +78,7 @@ jobs:
- name: "Upload coverage file"
uses: "actions/upload-artifact@v4"
with:
name: "${{ github.job }}-${{ matrix.php-version }}-${{ matrix.deps }}-coverage"
name: "${{ github.job }}-${{ matrix.php-version }}-${{ matrix.deps }}-${{ matrix.no-annotations == true && 'no-annotations' || 'with-annotations' }}-coverage"
path: "coverage.xml"

lint-doctrine-xml-schema:
Expand Down
1 change: 1 addition & 0 deletions tests/Gedmo/Mapping/Fixture/Unmapped/Timestampable.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ class Timestampable
*
* @Tmsp(on="create")
*/
#[Tmsp(on: 'create')]
private $created;
}
16 changes: 4 additions & 12 deletions tests/Gedmo/Mapping/LoggableORMMappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ public static function dataLoggableObject(): \Generator
{
if (PHP_VERSION_ID >= 80000) {
yield 'Model with attributes' => [AnnotatedLoggable::class];
}

if (class_exists(AnnotationDriver::class)) {
} elseif (class_exists(AnnotationDriver::class)) {
yield 'Model with annotations' => [AnnotatedLoggable::class];
}

Expand Down Expand Up @@ -121,9 +119,7 @@ public static function dataLoggableObjectWithCompositeKey(): \Generator

if (PHP_VERSION_ID >= 80000) {
yield 'Model with attributes' => [AnnotatedLoggableComposite::class];
}

if (class_exists(AnnotationDriver::class)) {
} elseif (class_exists(AnnotationDriver::class)) {
yield 'Model with annotations' => [AnnotatedLoggableComposite::class];
}

Expand Down Expand Up @@ -166,9 +162,7 @@ public static function dataLoggableObjectWithCompositeKeyAndRelation(): \Generat

if (PHP_VERSION_ID >= 80000) {
yield 'Model with attributes' => [AnnotatedLoggableCompositeRelation::class];
}

if (class_exists(AnnotationDriver::class)) {
} elseif (class_exists(AnnotationDriver::class)) {
yield 'Model with annotations' => [AnnotatedLoggableCompositeRelation::class];
}

Expand Down Expand Up @@ -214,9 +208,7 @@ public static function dataLoggableObjectWithEmbedded(): \Generator
{
if (PHP_VERSION_ID >= 80000) {
yield 'Model with attributes' => [AnnotatedLoggableWithEmbedded::class];
}

if (class_exists(AnnotationDriver::class)) {
} elseif (class_exists(AnnotationDriver::class)) {
yield 'Model with annotations' => [AnnotatedLoggableWithEmbedded::class];
}
}
Expand Down
10 changes: 9 additions & 1 deletion tests/Gedmo/Mapping/MetadataFactory/CustomDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Gedmo\Tests\Mapping\MetadataFactory;

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\Configuration;
Expand All @@ -19,6 +20,7 @@
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use Gedmo\Mapping\Driver\AttributeReader;
use Gedmo\Tests\Mapping\Fixture\Unmapped\Timestampable;
use Gedmo\Timestampable\TimestampableListener;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -48,7 +50,13 @@ protected function setUp(): void

$evm = new EventManager();
$this->timestampable = new TimestampableListener();
$this->timestampable->setAnnotationReader($_ENV['annotation_reader']);

if (PHP_VERSION >= 80000) {
$this->timestampable->setAnnotationReader(new AttributeReader());
} elseif (class_exists(AnnotationReader::class)) {
$this->timestampable->setAnnotationReader($_ENV['annotation_reader']);
}

$evm->addEventSubscriber($this->timestampable);
$connection = DriverManager::getConnection($conn, $config);
$this->em = new EntityManager($connection, $config, $evm);
Expand Down
4 changes: 1 addition & 3 deletions tests/Gedmo/Mapping/ORMMappingTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ final protected function createChainedMappingDriver(): MappingDriverChain

if (PHP_VERSION_ID >= 80000) {
$chain->addDriver(new AttributeDriver([]), 'Gedmo\Tests\Mapping\Fixture');
}

if (class_exists(AnnotationDriver::class)) {
} elseif (class_exists(AnnotationDriver::class) && class_exists(AnnotationReader::class)) {
$chain->addDriver(new AnnotationDriver(new AnnotationReader()), 'Gedmo\Tests\Mapping\Fixture');
}

Expand Down
4 changes: 1 addition & 3 deletions tests/Gedmo/Mapping/SluggableMappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ public static function dataSluggableObject(): \Generator

if (PHP_VERSION_ID >= 80000) {
yield 'Model with attributes' => [AnnotatedSluggable::class];
}

if (class_exists(AnnotationDriver::class)) {
} elseif (class_exists(AnnotationDriver::class)) {
yield 'Model with annotations' => [AnnotatedSluggable::class];
}
}
Expand Down
4 changes: 1 addition & 3 deletions tests/Gedmo/Mapping/SoftDeleteableMappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ public static function dataSoftDeleteableObject(): \Generator

if (PHP_VERSION_ID >= 80000) {
yield 'Model with attributes' => [AnnotatedSoftDeleteable::class];
}

if (class_exists(AnnotationDriver::class)) {
} elseif (class_exists(AnnotationDriver::class)) {
yield 'Model with annotations' => [AnnotatedSoftDeleteable::class];
}

Expand Down
4 changes: 1 addition & 3 deletions tests/Gedmo/Mapping/SortableMappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ public static function dataSortableObject(): \Generator

if (PHP_VERSION_ID >= 80000) {
yield 'Model with attributes' => [AnnotatedSortable::class];
}

if (class_exists(AnnotationDriver::class)) {
} elseif (class_exists(AnnotationDriver::class)) {
yield 'Model with annotations' => [AnnotatedSortable::class];
}

Expand Down
4 changes: 1 addition & 3 deletions tests/Gedmo/Mapping/TimestampableMappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ public static function dataTimestampableObject(): \Generator
{
if (PHP_VERSION_ID >= 80000) {
yield 'Model with attributes' => [AnnotatedCategory::class];
}

if (class_exists(AnnotationDriver::class)) {
} elseif (class_exists(AnnotationDriver::class)) {
yield 'Model with annotations' => [AnnotatedCategory::class];
}

Expand Down
4 changes: 1 addition & 3 deletions tests/Gedmo/Mapping/TranslatableMappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ public static function dataSortableObject(): \Generator

if (PHP_VERSION_ID >= 80000) {
yield 'Model with attributes' => [AnnotatedUser::class];
}

if (class_exists(AnnotationDriver::class)) {
} elseif (class_exists(AnnotationDriver::class)) {
yield 'Model with annotations' => [AnnotatedUser::class];
}

Expand Down
4 changes: 1 addition & 3 deletions tests/Gedmo/Mapping/UploadableMappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ public static function dataUploadableObject(): \Generator

if (PHP_VERSION_ID >= 80000) {
yield 'Model with attributes' => [AnnotatedUploadable::class];
}

if (class_exists(AnnotationDriver::class)) {
} elseif (class_exists(AnnotationDriver::class)) {
yield 'Model with annotations' => [AnnotatedUploadable::class];
}

Expand Down
2 changes: 2 additions & 0 deletions tests/Gedmo/Timestampable/AttributeChangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*
* @requires PHP >= 8.0
*
* @todo This test requires {@see ChangeTest} to have been run first to load the {@see TimestampableListenerStub}
*/
final class AttributeChangeTest extends BaseTestCaseORM
{
Expand Down
6 changes: 3 additions & 3 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

require dirname(__DIR__).'/vendor/autoload.php';

$reader = new AnnotationReader();
$reader = new PsrCachedReader($reader, new ArrayAdapter());
$_ENV['annotation_reader'] = $reader;
if (class_exists(AnnotationReader::class)) {
$_ENV['annotation_reader'] = new PsrCachedReader(new AnnotationReader(), new ArrayAdapter());
}

Type::addType('uuid', UuidType::class);

0 comments on commit c16c401

Please sign in to comment.