-
-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
621 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ | |
/symfony.lock | ||
|
||
/.phpunit.result.cache | ||
|
||
src/Bundle/test/src/Tests/Tmp/ |
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
47 changes: 47 additions & 0 deletions
47
src/Bundle/DependencyInjection/Compiler/RegisterStubCommandsPass.php
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,47 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler; | ||
|
||
use Sylius\Component\Resource\Symfony\Command\StubMakeResource; | ||
use Sylius\Component\Resource\Symfony\Maker\MakeResource; | ||
use Symfony\Bundle\MakerBundle\MakerBundle; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
final class RegisterStubCommandsPass implements CompilerPassInterface | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
if (!$this->isMakerEnabled($container)) { | ||
$container->register(StubMakeResource::class)->setClass(StubMakeResource::class)->addTag('console.command'); | ||
$container->removeDefinition('sylius.maker.resource'); | ||
$container->removeAlias(MakeResource::class); | ||
} | ||
} | ||
|
||
private function isMakerEnabled(ContainerBuilder $container): bool | ||
{ | ||
if (!class_exists(MakerBundle::class)) { | ||
return false; | ||
} | ||
|
||
/** @var array $bundles */ | ||
$bundles = $container->getParameter('kernel.bundles'); | ||
|
||
return in_array(MakerBundle::class, $bundles, true); | ||
} | ||
} |
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,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
This file is part of the Sylius package. | ||
(c) Paweł Jędrzejewski | ||
For the full copyright and license information, please view the LICENSE | ||
file that was distributed with this source code. | ||
--> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
<services> | ||
<service id="sylius.maker.resource" class="Sylius\Component\Resource\Symfony\Maker\MakeResource"> | ||
<tag name="maker.command" /> | ||
</service> | ||
</services> | ||
</container> |
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
70 changes: 70 additions & 0 deletions
70
src/Bundle/Tests/DependencyInjection/Compiler/RegisterStubCommandsPassTest.php
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,70 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DependencyInjection\Compiler; | ||
|
||
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; | ||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\RegisterStubCommandsPass; | ||
use Sylius\Component\Resource\Symfony\Command\StubMakeResource; | ||
use Sylius\Component\Resource\Symfony\Maker\MakeResource; | ||
use Symfony\Bundle\MakerBundle\MakerBundle; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
final class RegisterStubCommandsPassTest extends AbstractCompilerPassTestCase | ||
{ | ||
/** @test */ | ||
public function it_registers_stub_commands_when_maker_is_not_registered(): void | ||
{ | ||
$this->compile(); | ||
|
||
$this->assertContainerBuilderHasService(StubMakeResource::class, StubMakeResource::class); | ||
} | ||
|
||
/** @test */ | ||
public function it_does_not_register_stub_commands_when_maker_is_registered(): void | ||
{ | ||
$this->setParameter('kernel.bundles', [MakerBundle::class]); | ||
|
||
$this->compile(); | ||
|
||
$this->assertContainerBuilderNotHasService(StubMakeResource::class); | ||
} | ||
|
||
/** @test */ | ||
public function it_unregisters_definition_for_grid_maker_when_maker_is_not_registered(): void | ||
{ | ||
$this->registerService('sylius.maker.resource', MakeResource::class); | ||
|
||
$this->compile(); | ||
|
||
$this->assertContainerBuilderNotHasService(MakeResource::class); | ||
} | ||
|
||
/** @test */ | ||
public function it_does_not_unregister_definition_for_grid_maker_when_maker_is_registered(): void | ||
{ | ||
$this->setParameter('kernel.bundles', [MakerBundle::class]); | ||
$this->registerService('sylius.maker.resource', MakeResource::class); | ||
|
||
$this->compile(); | ||
|
||
$this->assertContainerBuilderHasService('sylius.maker.resource', MakeResource::class); | ||
} | ||
|
||
protected function registerCompilerPass(ContainerBuilder $container): void | ||
{ | ||
$this->setParameter('kernel.bundles', []); | ||
|
||
$container->addCompilerPass(new RegisterStubCommandsPass()); | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* 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\Tests\Tmp\Entity; | ||
|
||
use App\Repository\Tests\Tmp\Entity\BookRepository; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
#[ORM\Entity(repositoryClass: BookRepository::class)] | ||
class Book | ||
{ | ||
#[ORM\Id] | ||
#[ORM\GeneratedValue] | ||
#[ORM\Column] | ||
private ?int $id = null; | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/Bundle/test/src/Repository/Tests/Tmp/Entity/BookRepository.php
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,77 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* 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\Repository\Tests\Tmp\Entity; | ||
|
||
use App\Entity\Tests\Tmp\Entity\Book; | ||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||
use Doctrine\Persistence\ManagerRegistry; | ||
|
||
/** | ||
* @extends ServiceEntityRepository<Book> | ||
* | ||
* @method Book|null find($id, $lockMode = null, $lockVersion = null) | ||
* @method Book|null findOneBy(array $criteria, array $orderBy = null) | ||
* @method Book[] findAll() | ||
* @method Book[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) | ||
*/ | ||
class BookRepository extends ServiceEntityRepository | ||
{ | ||
public function __construct(ManagerRegistry $registry) | ||
{ | ||
parent::__construct($registry, Book::class); | ||
} | ||
|
||
public function save(Book $entity, bool $flush = false): void | ||
{ | ||
$this->getEntityManager()->persist($entity); | ||
|
||
if ($flush) { | ||
$this->getEntityManager()->flush(); | ||
} | ||
} | ||
|
||
public function remove(Book $entity, bool $flush = false): void | ||
{ | ||
$this->getEntityManager()->remove($entity); | ||
|
||
if ($flush) { | ||
$this->getEntityManager()->flush(); | ||
} | ||
} | ||
|
||
// /** | ||
// * @return Book[] Returns an array of Book objects | ||
// */ | ||
// public function findByExampleField($value): array | ||
// { | ||
// return $this->createQueryBuilder('b') | ||
// ->andWhere('b.exampleField = :val') | ||
// ->setParameter('val', $value) | ||
// ->orderBy('b.id', 'ASC') | ||
// ->setMaxResults(10) | ||
// ->getQuery() | ||
// ->getResult() | ||
// ; | ||
// } | ||
|
||
// public function findOneBySomeField($value): ?Book | ||
// { | ||
// return $this->createQueryBuilder('b') | ||
// ->andWhere('b.exampleField = :val') | ||
// ->setParameter('val', $value) | ||
// ->getQuery() | ||
// ->getOneOrNullResult() | ||
// ; | ||
// } | ||
} |
55 changes: 55 additions & 0 deletions
55
src/Bundle/test/src/Sylius/Resource/Tests/Tmp/Sylius/Resource/BookResource.php
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,55 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* 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\Sylius\Resource\Tests\Tmp\Sylius\Resource; | ||
|
||
use Sylius\Component\Resource\Metadata\Create; | ||
use Sylius\Component\Resource\Metadata\Delete; | ||
use Sylius\Component\Resource\Metadata\Index; | ||
use Sylius\Component\Resource\Metadata\Resource; | ||
use Sylius\Component\Resource\Metadata\Show; | ||
use Sylius\Component\Resource\Metadata\Update; | ||
use Sylius\Component\Resource\Model\ResourceInterface; | ||
use Symfony\Component\Uid\AbstractUid; | ||
|
||
#[Resource] | ||
#[Index( | ||
// grid: Tests\Tmp\Sylius\Resource\BookGrid::class, | ||
)] | ||
#[Create( | ||
// processor: CreateTests\Tmp\Sylius\Resource\BookProcessor::class, | ||
)] | ||
#[Update( | ||
// provider: Tests\Tmp\Sylius\Resource\BookItemProvider::class, | ||
// processor: UpdateTests\Tmp\Sylius\Resource\BookProcessor::class, | ||
)] | ||
#[Delete( | ||
// provider: Tests\Tmp\Sylius\Resource\BookItemProvider::class, | ||
// processor: DeleteTests\Tmp\Sylius\Resource\BookProcessor::class, | ||
)] | ||
#[Show( | ||
// template: 'tests\tmp\sylius\resource\book/show.html.twig', | ||
// provider: Tests\Tmp\Sylius\Resource\BookItemProvider::class, | ||
)] | ||
final class BookResource implements ResourceInterface | ||
{ | ||
public function __construct( | ||
public ?AbstractUid $id = null, | ||
) { | ||
} | ||
|
||
public function getId(): ?string | ||
{ | ||
return $this->id?->__toString(); | ||
} | ||
} |
Oops, something went wrong.