Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve code linting and testing #18

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/Tests/app/cache/*
/Tests/app/logs/*
/node_modules/
/Tests/Application/var/*
/vendor/
/composer.phar
/composer.lock
/.sass-cache/
.php_cs.cache
*~

Expand Down
15 changes: 10 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,25 @@ matrix:
include:
- php: 7.2
env:
- COMPOSER_FLAGS="--prefer-lowest --prefer-dist --no-interaction"
- php: 7.3
- COMPOSER_FLAGS="--prefer-lowest --prefer-stable --prefer-dist --no-interaction"
- php: 7.4
env:
- COMPOSER_FLAGS="--prefer-dist --no-interaction"
- PHPSTAN=true
- LINT=true
- PECL_INSTALL=imagick

before_install:
- |
if [[ $PECL_INSTALL ]]; then
printf "\n" | pecl install $PECL_INSTALL
fi
- echo "memory_limit=4096M" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- phpenv config-rm xdebug.ini

before_script:
- phpenv config-rm xdebug.ini
- composer self-update
- COMPOSER_MEMORY_LIMIT=-1 travis_retry composer update $COMPOSER_FLAGS

script:
- if [[ $PHPSTAN = true ]]; then composer phpstan; fi
- if [[ $LINT = true ]]; then composer lint; fi
- composer phpunit
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class WebspaceStructureProviderCompilerPass implements CompilerPassInterface
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
if (!$container->hasDefinition('sulu.content.webspace_structure_provider')) {
return;
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/SuluThemeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SuluThemeExtension extends Extension
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load(sprintf('%s.xml', $container->getParameter('sulu.context')));
Expand Down
7 changes: 0 additions & 7 deletions EventListener/SetThemeEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,13 @@ class SetThemeEventListener
*/
private $activeTheme;

/**
* @param ActiveTheme $activeTheme
*/
public function __construct(ActiveTheme $activeTheme)
{
$this->activeTheme = $activeTheme;
}

/**
* Set the active theme if there is a portal.
*
* @param GetResponseEvent $event
*/
public function setActiveThemeOnRequest(GetResponseEvent $event): void
{
Expand All @@ -52,8 +47,6 @@ public function setActiveThemeOnRequest(GetResponseEvent $event): void

/**
* Set the active theme for a preview rendering.
*
* @param PreRenderEvent $event
*/
public function setActiveThemeOnPreviewPreRender(PreRenderEvent $event): void
{
Expand Down
12 changes: 4 additions & 8 deletions StructureProvider/WebspaceStructureProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Doctrine\Common\Cache\Cache;
use Liip\ThemeBundle\ActiveTheme;
use Sulu\Component\Content\Compat\Structure\PageBridge;
use Sulu\Component\Content\Compat\StructureInterface;
use Sulu\Component\Content\Compat\StructureManagerInterface;
use Sulu\Component\Webspace\Manager\WebspaceManagerInterface;
use Sulu\Component\Webspace\StructureProvider\WebspaceStructureProvider as BaseWebspaceStructureProvider;
Expand All @@ -33,13 +34,6 @@ class WebspaceStructureProvider extends BaseWebspaceStructureProvider
*/
protected $activeTheme;

/**
* @param \Twig_Environment $twig
* @param StructureManagerInterface $structureManager
* @param Cache $cache
* @param WebspaceManagerInterface $webspaceManager
* @param ActiveTheme $activeTheme
*/
public function __construct(
\Twig_Environment $twig,
StructureManagerInterface $structureManager,
Expand All @@ -55,8 +49,10 @@ public function __construct(

/**
* {@inheritdoc}
*
* @return StructureInterface[]
*/
protected function loadStructures($webspaceKey)
protected function loadStructures($webspaceKey): array
{
$before = $this->activeTheme->getName();
$webspace = $this->webspaceManager->findWebspaceByKey($webspaceKey);
Expand Down
2 changes: 1 addition & 1 deletion SuluThemeBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

class SuluThemeBundle extends Bundle
{
public function build(ContainerBuilder $container)
public function build(ContainerBuilder $container): void
{
parent::build($container);

Expand Down
4 changes: 4 additions & 0 deletions Tests/Application/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
APP_ENV=test
DATABASE_URL=mysql://root:@127.0.0.1:3306/su_theme_test
DATABASE_CHARSET=utf8mb4
DATABASE_COLLATE=utf8mb4_unicode_ci
52 changes: 52 additions & 0 deletions Tests/Application/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ThemeBundle\Tests\Application;

use Liip\ThemeBundle\LiipThemeBundle;
use Sulu\Bundle\TestBundle\Kernel\SuluTestKernel;
use Sulu\Bundle\ThemeBundle\SuluThemeBundle;
use Symfony\Component\Config\Loader\LoaderInterface;

class Kernel extends SuluTestKernel
{
/**
* {@inheritdoc}
*/
public function __construct($environment, $debug, $suluContext = self::CONTEXT_ADMIN)
{
parent::__construct($environment, $debug, $suluContext);
}

/**
* {@inheritdoc}
*/
public function registerBundles()
{
return array_merge(
parent::registerBundles(),
[
new LiipThemeBundle(),
new SuluThemeBundle(),
]
);
}

/**
* {@inheritdoc}
*/
public function registerContainerConfiguration(LoaderInterface $loader): void
{
parent::registerContainerConfiguration($loader);

$loader->load(__DIR__ . '/config/config_' . $this->getContext() . '.yaml');
}
}
5 changes: 5 additions & 0 deletions Tests/Application/bin/adminconsole
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env php
<?php

$suluContext = 'admin';
include __DIR__ . DIRECTORY_SEPARATOR. 'console.php';
42 changes: 42 additions & 0 deletions Tests/Application/bin/console.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

// if you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);

set_time_limit(0);

require_once __DIR__ . '/../config/bootstrap.php';

use Sulu\Bundle\ThemeBundle\Tests\Application\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\ErrorHandler\Debug;

$input = new ArgvInput();
$env = $input->getParameterOption(['--env', '-e'], getenv('SYMFONY_ENV') ?: 'dev');
$debug = '0' !== getenv('SYMFONY_DEBUG') && !$input->hasParameterOption(['--no-debug', '']) && 'prod' !== $env;

if ($debug) {
// Clean up when sf 4.3 support is removed
if (class_exists(Debug::class)) {
Debug::enable();
} else {
\Symfony\Component\Debug\Debug::enable();
}
}

$kernel = new Kernel($env, $debug, $suluContext);
$application = new Application($kernel);
$application->run($input);
5 changes: 5 additions & 0 deletions Tests/Application/bin/websiteconsole
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env php
<?php

$suluContext = 'website';
include __DIR__ . DIRECTORY_SEPARATOR. 'console.php';
39 changes: 39 additions & 0 deletions Tests/Application/config/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

use Symfony\Component\Dotenv\Dotenv;

$file = __DIR__ . '/../../../vendor/autoload.php';

if (!file_exists($file)) {
throw new RuntimeException('Install dependencies to run test suite.');
}

require $file;

// Load cached env vars if the .env.local.php file exists
// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)
if (is_array($env = @include dirname(__DIR__) . '/.env.local.php')) {
$_SERVER += $env;
$_ENV += $env;
} elseif (!class_exists(Dotenv::class)) {
throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
} else {
$path = dirname(__DIR__) . '/.env';
$dotenv = new Dotenv();
$dotenv->loadEnv($path);
}

$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';
$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0';
12 changes: 12 additions & 0 deletions Tests/Application/config/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
doctrine:
orm:
mappings:
gedmo_tree:
type: xml
prefix: Gedmo\Tree\Entity
dir: "%kernel.project_dir%/../../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity"
alias: GedmoTree
is_bundle: false

massive_search:
adapter: test
5 changes: 5 additions & 0 deletions Tests/Application/config/config_admin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
imports:
- config.yaml

framework:
router: { resource: "%kernel.project_dir%/config/routing_admin.yaml" }
5 changes: 5 additions & 0 deletions Tests/Application/config/config_website.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
imports:
- config.yaml

framework:
router: { resource: "%kernel.project_dir%/config/routing_website.yml" }
3 changes: 3 additions & 0 deletions Tests/Application/config/routing_admin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sulu_admin:
resource: "@SuluAdminBundle/Resources/config/routing.yml"
prefix: /admin
1 change: 1 addition & 0 deletions Tests/Application/config/routing_website.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# no theme specific routes
58 changes: 58 additions & 0 deletions Tests/Application/config/webspaces/sulu.io.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<webspace xmlns="http://schemas.sulu.io/webspace/webspace"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.sulu.io/webspace/webspace http://schemas.sulu.io/webspace/webspace-1.1.xsd">

<name>Sulu CMF</name>
<key>sulu-io</key>

<security>
<system>Website</system>
</security>

<localizations>
<localization language="de" default="true"/>
</localizations>

<theme>default</theme>

<default-templates>
<default-template type="homepage">overview</default-template>
<default-template type="page">overview</default-template>
</default-templates>

<navigation>
<contexts>
<context key="main">
<meta>
<title lang="en">Mainnavigation</title>
</meta>
</context>
</contexts>
</navigation>

<portals>
<portal>
<name>Sulu CMF AT</name>
<key>sulucmf_at</key>

<environments>
<environment type="prod">
<urls>
<url language="de">{host}</url>
</urls>
</environment>
<environment type="dev">
<urls>
<url language="de">{host}</url>
</urls>
</environment>
<environment type="test">
<urls>
<url language="de">{host}</url>
</urls>
</environment>
</environments>
</portal>
</portals>
</webspace>
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,6 @@ public function testGetStructuresCached(): void
$this->assertEquals($structures[2]->getKey(), $result[1]->getKey());
}

/**
* @param string $key
* @param string $view
*
* @return StructureInterface
*/
private function generateStructure(string $key, string $view): StructureInterface
{
$mock = $this->prophesize('Sulu\Component\Content\Compat\Structure\PageBridge');
Expand Down
Loading