diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c633565..15ea900 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -6,9 +6,6 @@ on: - master pull_request: -env: - SYMFONY_DEPRECATIONS_HELPER: weak - jobs: PHPUnit: diff --git a/.gitignore b/.gitignore index d22d043..c20d882 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +tests/Fixtures/var vendor/ composer.lock phpunit.xml$ diff --git a/composer.json b/composer.json index a51ead7..83a5781 100644 --- a/composer.json +++ b/composer.json @@ -32,14 +32,18 @@ "symfony/dependency-injection": "^5.4|^6.4|^7.0", "symfony/deprecation-contracts": "^2.0|^3.0", "symfony/event-dispatcher": "^5.4|^6.4|^7.0", + "symfony/framework-bundle": "^5.4|^6.4", "symfony/http-kernel": "^5.4|^6.4|^7.0" }, "require-dev": { - "phpunit/phpunit": "^8.5.36|^9.6", + "doctrine/common": "^2.0|^3.1", + "doctrine/doctrine-bundle": "^2.0", + "phpunit/phpunit": "^9.6.18", "symfony/error-handler": "^5.4|^6.4|^7.0", "symfony/phpunit-bridge": ">= 7.0", - "webfactory/doctrine-orm-test-infrastructure": "^1.9" + "symfony/yaml": "^5.4|^6.4|^7.0", + "webfactory/doctrine-orm-test-infrastructure": "^1.14" }, "config": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3883f00..84f0a22 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,6 +1,6 @@ @@ -9,17 +9,13 @@ tests - - - - - src - - src/Resources - - - - + + + + + + + diff --git a/src/WebfactoryPolyglotBundle.php b/src/WebfactoryPolyglotBundle.php index 1e7da45..a35ebed 100644 --- a/src/WebfactoryPolyglotBundle.php +++ b/src/WebfactoryPolyglotBundle.php @@ -15,7 +15,7 @@ final class WebfactoryPolyglotBundle extends Bundle { - public function build(ContainerBuilder $container) + public function build(ContainerBuilder $container): void { $container->addCompilerPass(new RegisterDoctrineTypePass()); } diff --git a/tests/Doctrine/PersistentTranslatableTest.php b/tests/Doctrine/PersistentTranslatableTest.php index 04192c3..c445c2a 100644 --- a/tests/Doctrine/PersistentTranslatableTest.php +++ b/tests/Doctrine/PersistentTranslatableTest.php @@ -12,8 +12,8 @@ use Symfony\Component\ErrorHandler\BufferingLogger; use Webfactory\Bundle\PolyglotBundle\Doctrine\PersistentTranslatable; use Webfactory\Bundle\PolyglotBundle\Locale\DefaultLocaleProvider; -use Webfactory\Bundle\PolyglotBundle\Tests\TestEntity; -use Webfactory\Bundle\PolyglotBundle\Tests\TestEntityTranslation; +use Webfactory\Bundle\PolyglotBundle\Tests\Fixtures\Entity\TestEntity; +use Webfactory\Bundle\PolyglotBundle\Tests\Fixtures\Entity\TestEntityTranslation; class PersistentTranslatableTest extends TestCase { diff --git a/tests/Doctrine/TranslatableClassMetadataTest.php b/tests/Doctrine/TranslatableClassMetadataTest.php index d32f876..27beea9 100644 --- a/tests/Doctrine/TranslatableClassMetadataTest.php +++ b/tests/Doctrine/TranslatableClassMetadataTest.php @@ -5,8 +5,8 @@ use Doctrine\Common\Annotations\AnnotationReader; use PHPUnit\Framework\TestCase; use Webfactory\Bundle\PolyglotBundle\Doctrine\TranslatableClassMetadata; -use Webfactory\Bundle\PolyglotBundle\Tests\TestEntity; -use Webfactory\Bundle\PolyglotBundle\Tests\TestEntityTranslation; +use Webfactory\Bundle\PolyglotBundle\Tests\Fixtures\Entity\TestEntity; +use Webfactory\Bundle\PolyglotBundle\Tests\Fixtures\Entity\TestEntityTranslation; use Webfactory\Doctrine\ORMTestInfrastructure\ORMInfrastructure; class TranslatableClassMetadataTest extends TestCase diff --git a/tests/TestEntity.php b/tests/Fixtures/Entity/TestEntity.php similarity index 96% rename from tests/TestEntity.php rename to tests/Fixtures/Entity/TestEntity.php index e0157c7..135b145 100644 --- a/tests/TestEntity.php +++ b/tests/Fixtures/Entity/TestEntity.php @@ -7,7 +7,7 @@ * file that was distributed with this source code. */ -namespace Webfactory\Bundle\PolyglotBundle\Tests; +namespace Webfactory\Bundle\PolyglotBundle\Tests\Fixtures\Entity; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; diff --git a/tests/TestEntityTranslation.php b/tests/Fixtures/Entity/TestEntityTranslation.php similarity index 94% rename from tests/TestEntityTranslation.php rename to tests/Fixtures/Entity/TestEntityTranslation.php index dccac9b..8923924 100644 --- a/tests/TestEntityTranslation.php +++ b/tests/Fixtures/Entity/TestEntityTranslation.php @@ -7,7 +7,7 @@ * file that was distributed with this source code. */ -namespace Webfactory\Bundle\PolyglotBundle\Tests; +namespace Webfactory\Bundle\PolyglotBundle\Tests\Fixtures\Entity; use Doctrine\ORM\Mapping as ORM; use Webfactory\Bundle\PolyglotBundle\Entity\BaseTranslation; diff --git a/tests/Fixtures/TestKernel.php b/tests/Fixtures/TestKernel.php new file mode 100644 index 0000000..11a99a7 --- /dev/null +++ b/tests/Fixtures/TestKernel.php @@ -0,0 +1,28 @@ +load(__DIR__.'/config/config.yml'); + } + + public function getProjectDir(): string + { + return __DIR__; + } +} diff --git a/tests/Fixtures/config/config.yml b/tests/Fixtures/config/config.yml new file mode 100644 index 0000000..1e0abc0 --- /dev/null +++ b/tests/Fixtures/config/config.yml @@ -0,0 +1,18 @@ +framework: + test: true + +doctrine: + dbal: + driver: pdo_sqlite + memory: true + orm: + # The following would silence Doctrine bundle deprecation messages, but it's not straightforward + # to do while still being compliant across a range of ORM / DoctrineBundle versions. + #report_fields_where_declared: true + #enable_lazy_ghost_objects: true + mappings: + WebfactoryPolyglotBundle: + type: annotation + dir: ../tests/Fixtures/Entity + prefix: Webfactory\Bundle\PolyglotBundle\Tests\Fixtures\Entity + diff --git a/tests/Functional/IntegrationTest.php b/tests/Functional/IntegrationTest.php index 5a36eba..3a29ae4 100644 --- a/tests/Functional/IntegrationTest.php +++ b/tests/Functional/IntegrationTest.php @@ -2,8 +2,8 @@ namespace Webfactory\Bundle\PolyglotBundle\Tests\Functional; -use Webfactory\Bundle\PolyglotBundle\Tests\TestEntity; -use Webfactory\Bundle\PolyglotBundle\Tests\TestEntityTranslation; +use Webfactory\Bundle\PolyglotBundle\Tests\Fixtures\Entity\TestEntity; +use Webfactory\Bundle\PolyglotBundle\Tests\Fixtures\Entity\TestEntityTranslation; use Webfactory\Bundle\PolyglotBundle\Translatable; use Webfactory\Bundle\PolyglotBundle\TranslatableInterface; diff --git a/tests/Functional/SymfonyIntegrationTest.php b/tests/Functional/SymfonyIntegrationTest.php new file mode 100644 index 0000000..f64fb9e --- /dev/null +++ b/tests/Functional/SymfonyIntegrationTest.php @@ -0,0 +1,44 @@ +get('doctrine.orm.entity_manager'); + + $schemaTool = new SchemaTool($entityManager); + $schemaTool->createSchema([ + $entityManager->getClassMetadata(TestEntity::class), + $entityManager->getClassMetadata(TestEntityTranslation::class), + ]); + + $value = new Translatable('english', 'en_GB'); + $value->setTranslation('deutsch', 'de_DE'); + $entity = new TestEntity($value); + + $entityManager->persist($entity); + $entityManager->flush(); + $entityManager->clear(); + + $reloadedEntity = $entityManager->find(TestEntity::class, $entity->getId()); + + self::assertSame('english', $reloadedEntity->getText()->translate('en_GB')); + self::assertSame('deutsch', $reloadedEntity->getText()->translate('de_DE')); + } +}