Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jordisala1991 committed Jul 20, 2021
1 parent 80935f7 commit 609f00e
Show file tree
Hide file tree
Showing 25 changed files with 406 additions and 116 deletions.
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"gedmo/doctrine-extensions": "^3.0",
"knplabs/doctrine-behaviors": "^2.0.6",
"phpunit/phpunit": "^9.5",
"psr/container": "^1.1 || ^2.0",
"sonata-project/admin-bundle": "^3.103 || ^4.0@dev",
"sonata-project/doctrine-extensions": "^1.13",
"sonata-project/doctrine-orm-admin-bundle": "^3.34 || ^4.0@dev",
Expand Down Expand Up @@ -70,6 +71,7 @@
"psalm/plugin-phpunit": "^0.16",
"psalm/plugin-symfony": "^2.0",
"psr/event-dispatcher": "^1.0",
"symfony/browser-kit": "^5.3",
"symfony/phpunit-bridge": "^5.3",
"symplify/monorepo-builder": "^9.3",
"theofidry/alice-data-fixtures": "^1.3",
Expand Down
5 changes: 4 additions & 1 deletion packages/basic-page-bundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"friendsofsymfony/ckeditor-bundle": "^2.2",
"gedmo/doctrine-extensions": "^3.0",
"knplabs/doctrine-behaviors": "^2.0.6",
"psr/container": "^1.1 || ^2.0",
"runroom-packages/seo-bundle": "^0.11@dev",
"sonata-project/admin-bundle": "^3.103 || ^4.0@dev",
"sonata-project/doctrine-orm-admin-bundle": "^3.34 || ^4.0@dev",
Expand All @@ -35,14 +36,16 @@
"symfony/form": "^4.4 || ^5.3",
"symfony/http-foundation": "^4.4.7 || ^5.3",
"symfony/http-kernel": "^4.4.13 || ^5.3",
"symfony/validator": "^4.4 || ^5.3"
"symfony/validator": "^4.4 || ^5.3",
"twig/twig": "^2.12 || ^3.0"
},
"require-dev": {
"a2lix/auto-form-bundle": "^0.3.1",
"matthiasnoback/symfony-config-test": "^4.2",
"matthiasnoback/symfony-dependency-injection-test": "^4.1",
"phpunit/phpunit": "^9.5",
"runroom-packages/testing": "^0.11@dev",
"symfony/browser-kit": "^5.3",
"symfony/framework-bundle": "^4.4 || ^5.3",
"symfony/phpunit-bridge": "^5.3",
"symfony/routing": "^4.4 || ^5.3",
Expand Down
16 changes: 14 additions & 2 deletions packages/basic-page-bundle/src/Resources/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
* file that was distributed with this source code.
*/

use Psr\Container\ContainerInterface;
use Runroom\BasicPageBundle\Admin\BasicPageAdmin;
use Runroom\BasicPageBundle\Controller\BasicPageController;
use Runroom\BasicPageBundle\Entity\BasicPage;
use Runroom\BasicPageBundle\Repository\BasicPageRepository;
use Runroom\BasicPageBundle\Service\BasicPageAlternateLinksProvider;
use Runroom\BasicPageBundle\Service\BasicPageMetaInformationProvider;
use Runroom\BasicPageBundle\Service\BasicPageService;
use Runroom\BasicPageBundle\Twig\BasicPageExtension;
use Runroom\BasicPageBundle\Twig\BasicPageRuntime;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;

Expand All @@ -31,9 +34,11 @@
->tag('sonata.admin', ['manager_type' => 'orm', 'label' => 'Basic pages']);

$services->set(BasicPageController::class)
->public()
->arg('$service', new ReferenceConfigurator(BasicPageService::class))
->call('setContainer', [new ReferenceConfigurator('service_container')])
->tag('controller.service_subscriber');
->call('setContainer', [new ReferenceConfigurator(ContainerInterface::class)])
->tag('container.service_subscriber')
->tag('controller.service_arguments');

$services->set(BasicPageService::class)
->arg('$repository', new ReferenceConfigurator(BasicPageRepository::class));
Expand All @@ -48,4 +53,11 @@
->arg('$registry', new ReferenceConfigurator('doctrine'))
->arg('$requestStack', new ReferenceConfigurator('request_stack'))
->tag('doctrine.repository_service');

$services->set(BasicPageExtension::class)
->tag('twig.extension');

$services->set(BasicPageRuntime::class)
->arg('$repository', new ReferenceConfigurator(BasicPageRepository::class))
->tag('twig.runtime');
};
4 changes: 2 additions & 2 deletions packages/basic-page-bundle/src/Resources/views/show.html.twig
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<h1>{{ page.content.basicPage.title }}</h1>
<div>{{ page.content.basicPage.content|raw }}</div>
<h1>{{ model.basicPage.title }}</h1>
<div>{{ model.basicPage.content|raw }}</div>
27 changes: 27 additions & 0 deletions packages/basic-page-bundle/src/Twig/BasicPageExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Runroom package.
*
* (c) Runroom <runroom@runroom.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Runroom\BasicPageBundle\Twig;

use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class BasicPageExtension extends AbstractExtension
{
public function getFunctions(): array
{
return [
new TwigFunction('get_basic_pages', [BasicPageRuntime::class, 'getBasicPages']),
];
}
}
40 changes: 40 additions & 0 deletions packages/basic-page-bundle/src/Twig/BasicPageRuntime.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Runroom package.
*
* (c) Runroom <runroom@runroom.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Runroom\BasicPageBundle\Twig;

use Runroom\BasicPageBundle\Entity\BasicPage;
use Runroom\BasicPageBundle\Repository\BasicPageRepository;
use Twig\Extension\RuntimeExtensionInterface;

class BasicPageRuntime implements RuntimeExtensionInterface
{
private BasicPageRepository $repository;

public function __construct(BasicPageRepository $repository)
{
$this->repository = $repository;
}

/** @return BasicPage[] */
public function getBasicPages(?string $location = null): array
{
$criteria = ['publish' => true];

if (null !== $location) {
$criteria['location'] = $location;
}

return $this->repository->findBy($criteria) ?? [];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
"get_basic_pages" function
--TEMPLATE--
{% set basicPages = get_basic_pages('footer') %}

{% for basicPage in basicPages %}
{{ basicPage.getLocation }}
{% endfor %}
--DATA--
return []
--EXPECT--
footer
footer
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Runroom package.
*
* (c) Runroom <runroom@runroom.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Runroom\BasicPageBundle\Tests\Functional;

use Runroom\BasicPageBundle\Factory\BasicPageFactory;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Zenstruck\Foundry\Test\Factories;
use Zenstruck\Foundry\Test\ResetDatabase;

class BasicPageControllerTest extends WebTestCase
{
use Factories;
use ResetDatabase;

/** @test */
public function itRendersStatic(): void
{
$client = static::createClient();

$basicPage = BasicPageFactory::new(['publish' => true])->withTranslations(['en'])->create()->object();

$client->request('GET', '/' . $basicPage->getSlug());

self::assertResponseIsSuccessful();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Runroom package.
*
* (c) Runroom <runroom@runroom.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Runroom\BasicPageBundle\Tests\Integration;

use Runroom\BasicPageBundle\Entity\BasicPage;
use Runroom\BasicPageBundle\Factory\BasicPageFactory;
use Runroom\BasicPageBundle\Repository\BasicPageRepository;
use Runroom\BasicPageBundle\Twig\BasicPageExtension;
use Runroom\BasicPageBundle\Twig\BasicPageRuntime;
use Twig\RuntimeLoader\RuntimeLoaderInterface;
use Twig\Test\IntegrationTestCase;
use Zenstruck\Foundry\Test\Factories;

class BasicPageExtensionTest extends IntegrationTestCase
{
use Factories;

public function getFixturesDir()
{
return __DIR__ . '/../Fixtures/Twig/';
}

protected function getExtensions()
{
return [
new BasicPageExtension(),
];
}

protected function getRuntimeLoaders()
{
$basicPages = BasicPageFactory::createMany(2, [
'publish' => true,
'location' => BasicPage::LOCATION_FOOTER,
]);

$basicPageRepository = $this->createStub(BasicPageRepository::class);
$basicPageRepository->method('findBy')->willReturn($basicPages);

$basicPageRuntime = new BasicPageRuntime($basicPageRepository);

$runtimeLoader = $this->createMock(RuntimeLoaderInterface::class);
$runtimeLoader->method('load')->with(BasicPageRuntime::class)->willReturn($basicPageRuntime);

return [$runtimeLoader];
}
}
5 changes: 4 additions & 1 deletion packages/cookies-bundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"doctrine/persistence": "^2.0",
"friendsofsymfony/ckeditor-bundle": "^2.2",
"knplabs/doctrine-behaviors": "^2.0.6",
"psr/container": "^1.1 || ^2.0",
"runroom-packages/form-handler-bundle": "^0.11@dev",
"sonata-project/admin-bundle": "^3.103 || ^4.0@dev",
"sonata-project/doctrine-orm-admin-bundle": "^3.34 || ^4.0@dev",
Expand All @@ -33,14 +34,16 @@
"symfony/form": "^4.4 || ^5.3",
"symfony/http-foundation": "^4.4.7 || ^5.3",
"symfony/http-kernel": "^4.4.13 || ^5.3",
"symfony/validator": "^4.4 || ^5.3"
"symfony/validator": "^4.4 || ^5.3",
"twig/twig": "^2.12 || ^3.0"
},
"require-dev": {
"a2lix/auto-form-bundle": "^0.3.1",
"matthiasnoback/symfony-config-test": "^4.2",
"matthiasnoback/symfony-dependency-injection-test": "^4.1",
"phpunit/phpunit": "^9.5",
"runroom-packages/testing": "^0.11@dev",
"symfony/browser-kit": "^5.3",
"symfony/phpunit-bridge": "^5.3",
"zenstruck/foundry": "^1.10"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Runroom\CookiesBundle\DependencyInjection;

use Runroom\CookiesBundle\Service\CookiesPageService;
use Runroom\CookiesBundle\Service\CookiesService;
use Runroom\CookiesBundle\Twig\CookiesRuntime;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
Expand All @@ -30,7 +30,7 @@ public function load(array $configs, ContainerBuilder $container): void
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$definition = $container->getDefinition(CookiesService::class);
$definition = $container->getDefinition(CookiesRuntime::class);
$definition->setArgument('$cookies', $config['cookies']);

$definition = $container->getDefinition(CookiesPageService::class);
Expand Down
19 changes: 14 additions & 5 deletions packages/cookies-bundle/src/Resources/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@
* file that was distributed with this source code.
*/

use Psr\Container\ContainerInterface;
use Runroom\CookiesBundle\Admin\CookiesPageAdmin;
use Runroom\CookiesBundle\Controller\CookiesPageController;
use Runroom\CookiesBundle\Entity\CookiesPage;
use Runroom\CookiesBundle\Repository\CookiesPageRepository;
use Runroom\CookiesBundle\Service\CookiesPageService;
use Runroom\CookiesBundle\Service\CookiesService;
use Runroom\CookiesBundle\Twig\CookiesExtension;
use Runroom\CookiesBundle\Twig\CookiesRuntime;
use Runroom\FormHandlerBundle\FormHandler;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
// Use "service" function for creating references to services when dropping support for Symfony 4.4
// Use "abstract_arg" function for creating references to arguments without value when dropping support for Symfony 4.4
$services = $containerConfigurator->services();

$services->set(CookiesPageAdmin::class)
Expand All @@ -31,19 +34,25 @@
->tag('sonata.admin', ['manager_type' => 'orm', 'label' => 'Cookies']);

$services->set(CookiesPageController::class)
->public()
->arg('$service', new ReferenceConfigurator(CookiesPageService::class))
->call('setContainer', [new ReferenceConfigurator(ContainerInterface::class)])
->tag('container.service_subscriber')
->tag('controller.service_arguments');

$services->set(CookiesPageService::class)
->arg('$repository', new ReferenceConfigurator(CookiesPageRepository::class))
->arg('$handler', new ReferenceConfigurator(FormHandler::class))
->arg('$cookies', null);

$services->set(CookiesService::class)
->arg('$cookies', null)
->tag('kernel.event_subscriber');

$services->set(CookiesPageRepository::class)
->arg('$registry', new ReferenceConfigurator('doctrine'))
->tag('doctrine.repository_service');

$services->set(CookiesExtension::class)
->tag('twig.extension');

$services->set(CookiesRuntime::class)
->arg('$cookies', null)
->tag('twig.runtime');
};

0 comments on commit 609f00e

Please sign in to comment.