Skip to content

Commit

Permalink
minor #934 Reproduce getting the translation repository by its interf…
Browse files Browse the repository at this point in the history
…ace use case (loic425)

This PR was merged into the 1.11 branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Bug fix?        | no
| New feature?    | no
| BC breaks?      | no
| Deprecations?   | no
| Related tickets |
| License         | MIT

On 1.12 branch 
![image](https://github.com/user-attachments/assets/46e22535-0a7a-4dc0-bd33-2fc115329bbc)


Commits
-------

b4e0976 Reproduce getting the translation repository by its interface use case
  • Loading branch information
GSadee authored Sep 11, 2024
2 parents 75f314d + b4e0976 commit 543e707
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
1 change: 1 addition & 0 deletions tests/Application/config/sylius/resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ sylius_resource:
translation:
classes:
model: App\Entity\BookTranslation
interface: App\Entity\BookTranslationInterface
form: App\Form\Type\BookTranslationType

app.comic_book:
Expand Down
3 changes: 1 addition & 2 deletions tests/Application/src/Entity/BookTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@

use Doctrine\ORM\Mapping as ORM;
use Sylius\Resource\Model\AbstractTranslation;
use Sylius\Resource\Model\ResourceInterface;

#[ORM\Entity]
#[ORM\MappedSuperclass]
#[ORM\Table(name: 'app_book_translation')]
class BookTranslation extends AbstractTranslation implements ResourceInterface
class BookTranslation extends AbstractTranslation implements BookTranslationInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
Expand Down
23 changes: 23 additions & 0 deletions tests/Application/src/Entity/BookTranslationInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Entity;

use Sylius\Resource\Model\ResourceInterface;

interface BookTranslationInterface extends ResourceInterface
{
public function getTitle(): ?string;

public function setTitle(?string $title): void;
}
37 changes: 37 additions & 0 deletions tests/Bundle/EventListener/ORMTranslatableListenerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Bundle\EventListener;

use App\Entity\BookTranslationInterface;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

final class ORMTranslatableListenerTest extends KernelTestCase
{
public function testGettingTranslationRepositoryByItsInterface(): void
{
self::bootKernel();

$this->assertInstanceOf(
EntityRepository::class,
$this->getEntityManager()->getRepository(BookTranslationInterface::class),
);
}

private function getEntityManager(): EntityManagerInterface
{
return $this->getContainer()->get(EntityManagerInterface::class);
}
}

0 comments on commit 543e707

Please sign in to comment.