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

Run tests without doctrine/annotations installed #2781

Merged
merged 4 commits into from
Jun 9, 2024
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
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);