Skip to content

Commit

Permalink
add minimal functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu authored and core23 committed Nov 22, 2019
1 parent 2f23bca commit a52e433
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 12 deletions.
25 changes: 13 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,26 @@
"sonata-project/doctrine-extensions": "^1.1",
"sonata-project/form-extensions": "^1.0",
"sonata-project/twig-extensions": "^1.0",
"symfony/asset": "^4.3 || 5.0",
"symfony/config": "^4.3 || 5.0",
"symfony/console": "^4.3 || 5.0",
"symfony/dependency-injection": "^4.3 || 5.0",
"symfony/asset": "^4.3 || ^5.0",
"symfony/config": "^4.3 || ^5.0",
"symfony/console": "^4.3 || ^5.0",
"symfony/dependency-injection": "^4.3 || ^5.0",
"symfony/event-dispatcher-contracts": "^1.1",
"symfony/form": "^4.3 || 5.0",
"symfony/framework-bundle": "^4.3 || 5.0",
"symfony/http-foundation": "^4.3 || 5.0",
"symfony/http-kernel": "^4.3 || 5.0",
"symfony/options-resolver": "^4.3 || 5.0",
"symfony/twig-bundle": "^4.3 || 5.0",
"symfony/form": "^4.3 || ^5.0",
"symfony/framework-bundle": "^4.3 || ^5.0",
"symfony/http-foundation": "^4.3 || ^5.0",
"symfony/http-kernel": "^4.3 || ^5.0",
"symfony/options-resolver": "^4.3 || ^5.0",
"symfony/twig-bundle": "^4.3 || ^5.0",
"twig/twig": "^2.11 || ^3.0"
},
"require-dev": {
"knplabs/knp-menu-bundle": "^2.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.0",
"symfony/debug": "^4.3 || 5.0",
"symfony/browser-kit": "^4.3 || ^5.0",
"symfony/debug": "^4.3 || ^5.0",
"symfony/phpunit-bridge": "^5.0",
"symfony/stopwatch": "^4.3 || 5.0"
"symfony/stopwatch": "^4.3 || ^5.0"
},
"suggest": {
"knplabs/knp-menu-bundle": "^2.0",
Expand Down
72 changes: 72 additions & 0 deletions tests/App/AppKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\BlockBundle\Tests\App;

use Sonata\BlockBundle\SonataBlockBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\RouteCollectionBuilder;

final class AppKernel extends Kernel
{
use MicroKernelTrait;

public function __construct()
{
parent::__construct('test', false);
}

public function registerBundles()
{
return [
new FrameworkBundle(),
new TwigBundle(),
new SonataBlockBundle(),
];
}

public function getCacheDir(): string
{
return $this->getBaseDir().'cache';
}

public function getLogDir(): string
{
return $this->getBaseDir().'log';
}

public function getProjectDir(): string
{
return __DIR__;
}

protected function configureRoutes(RouteCollectionBuilder $routes)
{
$routes->import(__DIR__.'/Controller/', '/', 'annotation');
}

protected function configureContainer(ContainerBuilder $containerBuilder, LoaderInterface $loader)
{
$loader->load(__DIR__.'/config.yml');
}

private function getBaseDir(): string
{
return sys_get_temp_dir().'/sonata-block-bundle/var/';
}
}
27 changes: 27 additions & 0 deletions tests/App/Block/DemoBlockService.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 Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\BlockBundle\Tests\App\Block;

use Sonata\BlockBundle\Block\Service\AbstractBlockService;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class DemoBlockService extends AbstractBlockService
{
public function configureSettings(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'template' => 'block.html.twig',
]);
}
}
28 changes: 28 additions & 0 deletions tests/App/Controller/DemoController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\BlockBundle\Tests\App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

final class DemoController extends AbstractController
{
/**
* @Route("/", name="home")
*/
public function index()
{
return $this->render('index.html.twig');
}
}
18 changes: 18 additions & 0 deletions tests/App/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
framework:
secret: secret

twig:
paths:
- '%kernel.project_dir%/templates'

services:
_defaults:
autowire: true
autoconfigure: true

Sonata\BlockBundle\Tests\App\Block\DemoBlockService:
tags: ['sonata.block']

Sonata\BlockBundle\Tests\App\Controller\DemoController:
tags:
- controller.service_arguments
1 change: 1 addition & 0 deletions tests/App/templates/block.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Foo
14 changes: 14 additions & 0 deletions tests/App/templates/index.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Welcome!</title>
</head>
<body>
{{ sonata_block_render({ 'type': 'Sonata\\BlockBundle\\Tests\\App\\Block\\DemoBlockService' }, {
}) }}

{{ sonata_block_render({ 'type': 'sonata.block.service.text' }, {
}) }}
</body>
</html>
30 changes: 30 additions & 0 deletions tests/Functional/FunctionalTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\BlockBundle\Tests\Functional;

use Sonata\BlockBundle\Tests\App\AppKernel;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

final class FunctionalTest extends WebTestCase
{
public function testRenderBlock(): void
{
$kernel = new AppKernel();
$client = new KernelBrowser($kernel);
$client->request('GET', '/');

$this->assertSame(200, $client->getResponse()->getStatusCode());
}
}

0 comments on commit a52e433

Please sign in to comment.