Skip to content

Commit

Permalink
Test PHPUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 committed Mar 6, 2023
1 parent e970cf5 commit a2c507a
Show file tree
Hide file tree
Showing 62 changed files with 1,496 additions and 18 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
"symfony/workflow": "^5.4 || ^6.0",
"twig/twig": "^2.12 || ^3.0",
"vimeo/psalm": "^4.22",
"rector/rector": "^0.13.5"
"rector/rector": "^0.13.5",
"symfony/messenger": "^5.4 || ^6.0"
},
"suggest": {
"doctrine/orm": "^2.5",
Expand Down
4 changes: 3 additions & 1 deletion src/Bundle/DependencyInjection/SyliusResourceExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ private function loadResources(array $loadedResources, ContainerBuilder $contain

$metadata = Metadata::fromAliasAndConfiguration($alias, $resourceConfig);

DriverProvider::get($metadata)->load($container, $metadata);
if ($metadata->getDriver()) {
DriverProvider::get($metadata)->load($container, $metadata);
}
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions src/Bundle/Resources/config/services/integrations/grid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,5 @@
<argument type="service" id="sylius.grid.data_provider" />
</service>
<service id="Sylius\Component\Resource\Grid\View\Factory\GridViewFactoryInterface" alias="sylius.grid.view_factory.resource" />

<service id="Sylius\Component\Resource\Grid\State\RequestGridProvider">
<argument type="service" id="sylius.grid.view_factory.resource" />
<argument type="service" id="sylius.grid.service_grid_provider" />
<tag name="sylius.state_provider" />
</service>
</services>
</container>
6 changes: 6 additions & 0 deletions src/Bundle/Resources/config/services/state.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,11 @@
<argument type="service" id="twig" on-invalid="null" />
<tag name="sylius.state_responder" />
</service>

<service id="Sylius\Component\Resource\Grid\State\RequestGridProvider">
<argument type="service" id="sylius.grid.view_factory.resource" on-invalid="null" />
<argument type="service" id="sylius.grid.service_grid_provider" on-invalid="null" />
<tag name="sylius.state_provider" />
</service>
</services>
</container>
5 changes: 5 additions & 0 deletions src/Bundle/test/config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ doctrine:
type: attribute
dir: '%kernel.project_dir%/src/BoardGameBlog/Domain'
prefix: 'App\BoardGameBlog\Domain'
Subscription:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/src/Subscription/Entity'
prefix: 'App\Subscription\Entity'
4 changes: 3 additions & 1 deletion src/Bundle/test/config/packages/framework.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
framework:
assets: false
translator: { fallbacks: ["%locale%"] }
translator:
default_path: '%kernel.project_dir%/translations'
fallbacks: ["%locale%"]
secret: "%secret%"
form: ~
csrf_protection: true
Expand Down
11 changes: 11 additions & 0 deletions src/Bundle/test/config/packages/messenger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
framework:
messenger:
default_bus: command.bus
buses:
command.bus: ~
query.bus: ~
transports:
sync: 'sync://'
routing:
'App\Shared\Application\Query\QueryInterface': 'sync'
'App\Shared\Application\Command\CommandInterface': 'sync'
1 change: 1 addition & 0 deletions src/Bundle/test/config/packages/test/fos_rest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ fos_rest:
empty_content: 204
format_listener:
rules:
- { path: '^/admin/*', priorities: ['html'], fallback_format: html }
- { path: '^/science-books/*', priorities: ['html'], fallback_format: html }
- { path: '^/', priorities: ['json'], fallback_format: json, prefer_extension: true }
exception:
Expand Down
6 changes: 6 additions & 0 deletions src/Bundle/test/config/packages/test/sylius_grid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sylius_grid:
templates:
action:
delete: 'grid/action/delete.html.twig'
show: 'grid/action/show.html.twig'
update: 'grid/action/update.html.twig'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sylius_resource:
mapping:
paths: ['%kernel.project_dir%/src/Entity']
3 changes: 3 additions & 0 deletions src/Bundle/test/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,6 @@ services:

App\BoardGameBlog\:
resource: '../src/BoardGameBlog'

App\Subscription\:
resource: '../src/Subscription'
9 changes: 9 additions & 0 deletions src/Bundle/test/config/sylius/resources.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
sylius_resource:
mapping:
paths:
- '%kernel.project_dir%/src/BoardGameBlog/Infrastructure/Sylius/Resource'
- '%kernel.project_dir%/src/Subscription/Entity'

translation:
locale_provider: test.translation_locale_provider

Expand Down Expand Up @@ -42,3 +47,7 @@ sylius_resource:
classes:
model: App\Entity\PullRequest
form: App\Form\Type\PullRequestType

app.subscription:
classes:
model: App\Subscription\Entity\Subscription
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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\BoardGameBlog\Application\Command;

use App\BoardGameBlog\Domain\ValueObject\BoardGameName;
use App\Shared\Application\Command\CommandInterface;

final class CreateBoardGameCommand implements CommandInterface
{
public function __construct(
public BoardGameName $name,
) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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\BoardGameBlog\Application\Command;

use App\BoardGameBlog\Domain\Model\BoardGame;
use App\BoardGameBlog\Domain\Repository\BoardGameRepositoryInterface;
use App\Shared\Application\Command\CommandHandlerInterface;

final class CreateBoardGameCommandHandler implements CommandHandlerInterface
{
public function __construct(private BoardGameRepositoryInterface $boardGameRepository)
{
}

public function __invoke(CreateBoardGameCommand $command): BoardGame
{
$boardGame = new BoardGame(
$command->name,
);

$this->boardGameRepository->save($boardGame);

return $boardGame;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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\BoardGameBlog\Application\Command;

use App\BoardGameBlog\Domain\ValueObject\BoardGameId;
use App\Shared\Application\Command\CommandInterface;

final class DeleteBoardGameCommand implements CommandInterface
{
public function __construct(
public BoardGameId $id,
) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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\BoardGameBlog\Application\Command;

use App\BoardGameBlog\Domain\Repository\BoardGameRepositoryInterface;
use App\Shared\Application\Command\CommandHandlerInterface;

final class DeleteBoardGameCommandHandler implements CommandHandlerInterface
{
public function __construct(private BoardGameRepositoryInterface $boardGameRepository)
{
}

public function __invoke(DeleteBoardGameCommand $command): void
{
if (null === $boardGame = $this->boardGameRepository->ofId($command->id)) {
return;
}

$this->boardGameRepository->remove($boardGame);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?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\BoardGameBlog\Application\Command;

use App\BoardGameBlog\Domain\ValueObject\BoardGameId;
use App\BoardGameBlog\Domain\ValueObject\BoardGameName;
use App\Shared\Application\Command\CommandInterface;

final class UpdateBoardGameCommand implements CommandInterface
{
public function __construct(
public BoardGameId $id,
public ?BoardGameName $name = null,
) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?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\BoardGameBlog\Application\Command;

use App\BoardGameBlog\Domain\Exception\MissingBoardGameException;
use App\BoardGameBlog\Domain\Model\BoardGame;
use App\BoardGameBlog\Domain\Repository\BoardGameRepositoryInterface;
use App\Shared\Application\Command\CommandHandlerInterface;

final class UpdateBoardGameCommandHandler implements CommandHandlerInterface
{
public function __construct(private BoardGameRepositoryInterface $boardGameRepository)
{
}

public function __invoke(UpdateBoardGameCommand $command): BoardGame
{
$boardGame = $this->boardGameRepository->ofId($command->id);
if (null === $boardGame) {
throw new MissingBoardGameException($command->id);
}

$boardGame->update(
name: $command->name,
);

$this->boardGameRepository->save($boardGame);

return $boardGame;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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\BoardGameBlog\Application\Query;

use App\BoardGameBlog\Domain\ValueObject\BoardGameId;
use App\Shared\Application\Query\QueryInterface;

final class FindBoardGameQuery implements QueryInterface
{
public function __construct(
public BoardGameId $id,
) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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\BoardGameBlog\Application\Query;

use App\BoardGameBlog\Domain\Model\BoardGame;
use App\BoardGameBlog\Domain\Repository\BoardGameRepositoryInterface;
use App\Shared\Application\Query\QueryHandlerInterface;

final class FindBoardGameQueryHandler implements QueryHandlerInterface
{
public function __construct(private BoardGameRepositoryInterface $repository)
{
}

public function __invoke(FindBoardGameQuery $query): ?BoardGame
{
return $this->repository->ofId($query->id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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\BoardGameBlog\Domain\Exception;

use App\BoardGameBlog\Domain\ValueObject\BoardGameId;

final class MissingBoardGameException extends \RuntimeException
{
public function __construct(BoardGameId $id, int $code = 0, ?\Throwable $previous = null)
{
parent::__construct(sprintf('Cannot find board game with id %s', (string) $id), $code, $previous);
}
}
Loading

0 comments on commit a2c507a

Please sign in to comment.