Skip to content

Commit

Permalink
Fix the tests (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored Jan 1, 2022
1 parent 8d282d5 commit 021d448
Show file tree
Hide file tree
Showing 19 changed files with 104 additions and 159 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ on:
push:
branches: [ master ]

# this fixes the input device is not a TTY .. see https://github.com/docker/compose/issues/5696
env:
MYSQL_HOST: '127.0.0.1'
SHELL_VERBOSITY: 1

jobs:
Expand Down Expand Up @@ -36,7 +38,7 @@ jobs:
run: php-cs-fixer fix --dry-run --diff --ansi

phpunit:
name: PHPUnit (PHP ${{ matrix.php }})
name: PHPUnit (PHP ${{ matrix.php }}) ${{ matrix.variant }}
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down
2 changes: 1 addition & 1 deletion bin/clear_cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
# file that was distributed with this source code.
#

rm -rf fixtures/Functional/cache/*ch
rm -rf fixtures/Functional/cache/*
8 changes: 2 additions & 6 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,16 @@ set_time_limit(0);

require_once __DIR__.'/../vendor/autoload.php';

use Hautelook\AliceBundle\Functional\AppKernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug;

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

if ($debug) {
Debug::enable();
}

error_reporting(E_ALL & ~E_USER_DEPRECATED);

$kernel = new Hautelook\AliceBundle\Functional\AppKernel($env, $debug);
$kernel = new AppKernel($env, $debug);
$application = new Application($kernel);
$application->run($input);
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@
"doctrine/orm": "^2.10.0",
"doctrine/persistence": "^2.2",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"symfony/finder": "^5.4 || ^6.0",
"symfony/framework-bundle": "^5.4 || ^6.0",
"symfony/finder": "^5.4.2 || ^6.0",
"symfony/framework-bundle": "^5.4.2 || ^6.0",
"theofidry/alice-data-fixtures": "^1.5"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"phpspec/prophecy": "^1.7",
"symfony/phpunit-bridge": "^6.0"
"symfony/phpunit-bridge": "^6.0",
"phpspec/prophecy-phpunit": "^2.0"
},

"extra": {
Expand Down
22 changes: 4 additions & 18 deletions fixtures/Functional/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
Expand Down Expand Up @@ -64,22 +63,9 @@ public function build(ContainerBuilder $container)
return;
}

$container->addCompilerPass(new class() implements CompilerPassInterface {
public function process(ContainerBuilder $container)
{
foreach ($container->getDefinitions() as $id => $definition) {
if ('slugger' === $id) {
continue;
}
$definition->setPublic(true);
}
foreach ($container->getAliases() as $id => $definition) {
if ('Symfony\Component\String\Slugger\SluggerInterface' === $id) {
continue;
}
$definition->setPublic(true);
}
}
}, PassConfig::TYPE_OPTIMIZE);
$container->addCompilerPass(
new MakeServicesPublicCompilerPass(),
PassConfig::TYPE_OPTIMIZE,
);
}
}
56 changes: 56 additions & 0 deletions fixtures/Functional/MakeServicesPublicCompilerPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

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

declare(strict_types=1);

namespace Hautelook\AliceBundle\Functional;

use function array_flip;
use function array_key_exists;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\String\Slugger\SluggerInterface;

final class MakeServicesPublicCompilerPass implements CompilerPassInterface
{
private const IGNORED_SERVICE_IDS = [
'slugger',
SluggerInterface::class,
'test.private_services_locator',
];

public function process(ContainerBuilder $container): void
{
self::setDefinitionsAsPublic(
$container->getDefinitions(),
$container->getAliases(),
);
}

/**
* @param list<array<string, Definition|mixed>> $sources
*/
private static function setDefinitionsAsPublic(array $sources): void
{
$ignoredServiceIdsAsKeys = array_flip(self::IGNORED_SERVICE_IDS);

foreach ($sources as $source) {
foreach ($source as $id => $definition) {
if ($definition instanceof Definition
&& !array_key_exists($id, $ignoredServiceIdsAsKeys)
) {
$definition->setPublic(true);
}
}
}
}
}
32 changes: 2 additions & 30 deletions fixtures/Functional/SimpleKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
*/
class SimpleKernel extends Kernel
{
/**
* @var bool|null
*/
private $overrideFirst;

/**
* {@inheritdoc}
*/
Expand All @@ -37,31 +32,8 @@ public function registerBundles(): iterable
];
}

/**
* {@inheritdoc}
*/
public function registerContainerConfiguration(LoaderInterface $loader)
{
}

public function setLocateResourceFirst(bool $overrideFirst = null)
public function registerContainerConfiguration(LoaderInterface $loader): void
{
$this->overrideFirst = $overrideFirst;
}

/**
* {@inheritdoc}
*/
public function locateResource($name, $dir = null, $first = true): string
{
if (null !== $this->overrideFirst) {
$first = $this->overrideFirst;
}

if (Kernel::VERSION_ID >= 50000) {
return parent::locateResource($name);
}

return parent::locateResource($name, $dir, $first);
// Nothing to do
}
}
9 changes: 1 addition & 8 deletions fixtures/Functional/config/doctrine.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_mysql
dbname: hautelook_alice_bundle
port: 3307
user: root
password: password
url: 'mysql://root:[email protected]:3307/hautelook_alice_bundle?serverVersion=8.0'
orm:
auto_mapping: true
18 changes: 9 additions & 9 deletions fixtures/Logger/FakeLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,71 +26,71 @@ class FakeLogger implements LoggerInterface
/**
* {@inheritdoc}
*/
public function emergency($message, array $context = [])
public function emergency($message, array $context = []): void
{
$this->__call(__METHOD__, \func_get_args());
}

/**
* {@inheritdoc}
*/
public function alert($message, array $context = [])
public function alert($message, array $context = []): void
{
$this->__call(__METHOD__, \func_get_args());
}

/**
* {@inheritdoc}
*/
public function critical($message, array $context = [])
public function critical($message, array $context = []): void
{
$this->__call(__METHOD__, \func_get_args());
}

/**
* {@inheritdoc}
*/
public function error($message, array $context = [])
public function error($message, array $context = []): void
{
$this->__call(__METHOD__, \func_get_args());
}

/**
* {@inheritdoc}
*/
public function warning($message, array $context = [])
public function warning($message, array $context = []): void
{
$this->__call(__METHOD__, \func_get_args());
}

/**
* {@inheritdoc}
*/
public function notice($message, array $context = [])
public function notice($message, array $context = []): void
{
$this->__call(__METHOD__, \func_get_args());
}

/**
* {@inheritdoc}
*/
public function info($message, array $context = [])
public function info($message, array $context = []): void
{
$this->__call(__METHOD__, \func_get_args());
}

/**
* {@inheritdoc}
*/
public function debug($message, array $context = [])
public function debug($message, array $context = []): void
{
$this->__call(__METHOD__, \func_get_args());
}

/**
* {@inheritdoc}
*/
public function log($level, $message, array $context = [])
public function log($level, $message, array $context = []): void
{
$this->__call(__METHOD__, \func_get_args());
}
Expand Down
3 changes: 2 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
bootstrap="fixtures/Functional/bootstrap.php"
colors="true"
forceCoversAnnotation="true"
verbose="true">
verbose="true"
stopOnFailure="true">

<php>
<server name="APP_ENV" value="test" force="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected function configure()
->addOption(
'no-bundles',
null,
InputOption::VALUE_OPTIONAL,
InputOption::VALUE_NONE,
'Fixtures from bundles will not be loaded.'
)
->addOption(
Expand Down Expand Up @@ -140,7 +140,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}

$noBundles = $input->getOption('no-bundles') ?? true;
$noBundles = $input->getOption('no-bundles') ?? false;
if (!$noBundles) {
@trigger_error(
'The configuration parameter hautelook_alice.root_dirs should be used to specify the directories to include. If done or if you do not need to load bundle\'s fixtures, use the --no-bundles option',
Expand Down
2 changes: 1 addition & 1 deletion src/Locator/EnvDirectoryLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private function doLocateFiles(string $path, string $environment): array
// this sort helps to set an order with filename
// ( "001-root-level-fixtures.yml", "002-another-level-fixtures.yml", ... )
$files = $files->sort(function ($a, $b) {
return strcasecmp($a, $b);
return strcasecmp((string) $a, (string) $b);
});

$fixtureFiles = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Hautelook\AliceBundle\Console\Command\Doctrine;

use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Doctrine\DBAL\Sharding\PoolingShardConnection;
use Doctrine\ORM\EntityManagerInterface;
use Hautelook\AliceBundle\Functional\AppKernel;
Expand Down Expand Up @@ -56,10 +55,6 @@ class LoadDataFixturesCommandIntegrationTest extends TestCase
*/
protected function setUp(): void
{
if (false === class_exists(DoctrineBundle::class, true)) {
$this->markTestSkipped('DoctrineBundle is not installed.');
}

$this->kernel = new TestKernel('LoadDataFixturesCommandIntegrationTest', true);
$this->kernel->boot();
$this->application = new Application($this->kernel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Hautelook\AliceBundle\Persistence\ObjectMapper\FakeEntityManager;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Symfony\Bundle\FrameworkBundle\Console\Application as FrameworkBundleConsoleApplication;
use Symfony\Component\Console\Application as ConsoleApplication;
Expand All @@ -35,6 +36,8 @@
*/
class LoadDataFixturesCommandTest extends TestCase
{
use ProphecyTrait;

public function testIsACommand()
{
$this->assertTrue(is_a(DoctrineOrmLoadDataFixturesCommand::class, Command::class, true));
Expand Down Expand Up @@ -163,7 +166,7 @@ public function testCallCommandWithBundleAndNoBundlesFlags()
'--shard' => 'shard_id',
'--append' => null,
'--purge-with-truncate' => null,
'--no-bundles',
'--no-bundles' => null,
]);
$input->setInteractive(false);

Expand Down
Loading

0 comments on commit 021d448

Please sign in to comment.