-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests with the Symfony full-stack framework (#54)
This fixes #43. It would have helped to spot the broken wiring of Doctrine lifecycle subscribers fixed in #51, or the declaration of compatibility with Symfony 7 in #20 that missed the `annotation_reader` depencency.
- Loading branch information
Showing
13 changed files
with
115 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
tests/Fixtures/var | ||
vendor/ | ||
composer.lock | ||
phpunit.xml$ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Webfactory\Bundle\PolyglotBundle\Tests\Fixtures; | ||
|
||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
use Symfony\Component\HttpKernel\Kernel; | ||
|
||
class TestKernel extends Kernel | ||
{ | ||
public function registerBundles(): iterable | ||
{ | ||
return [ | ||
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(), | ||
new \Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), | ||
new \Webfactory\Bundle\PolyglotBundle\WebfactoryPolyglotBundle(), | ||
]; | ||
} | ||
|
||
public function registerContainerConfiguration(LoaderInterface $loader): void | ||
{ | ||
$loader->load(__DIR__.'/config/config.yml'); | ||
} | ||
|
||
public function getProjectDir(): string | ||
{ | ||
return __DIR__; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
framework: | ||
test: true | ||
annotations: false | ||
|
||
|
||
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: attribute | ||
dir: ../tests/Fixtures/Entity | ||
prefix: Webfactory\Bundle\PolyglotBundle\Tests\Fixtures\Entity | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Webfactory\Bundle\PolyglotBundle\Tests\Functional; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Doctrine\ORM\Tools\SchemaTool; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Webfactory\Bundle\PolyglotBundle\Tests\Fixtures\Entity\TestEntity; | ||
use Webfactory\Bundle\PolyglotBundle\Tests\Fixtures\Entity\TestEntityTranslation; | ||
use Webfactory\Bundle\PolyglotBundle\Translatable; | ||
|
||
class SymfonyIntegrationTest extends KernelTestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function persist_and_reload_entity_in_Symfony(): void | ||
{ | ||
self::bootKernel(); | ||
$container = static::getContainer(); | ||
|
||
/** @var EntityManagerInterface $entityManager */ | ||
$entityManager = $container->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')); | ||
} | ||
} |