Skip to content
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
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@
"phpstan/phpstan": "*",
"phpstan/phpstan-symfony": "*",
"phpunit/phpunit": "^10.5|^11|^12|^13",
"psr/log": "^2|^3",
"rector/rector": "*",
"roave/security-advisories": "dev-latest",
"symfony/filesystem": "^6.4|^7.4|^8",
"symfony/framework-bundle": "^6.4|^7.4|^8",
"symfony/test-pack": "^1.1"
},
"config": {
Expand Down
8 changes: 5 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.0/phpunit.xsd"
bootstrap="vendor/autoload.php"
bootstrap="tests/bootstrap.php"
cacheDirectory=".phpunit.cache"
executionOrder="defects"
requireCoverageMetadata="true"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
failOnWarning="true">
failOnWarning="true"
failOnDeprecation="true"
displayDetailsOnTestsThatTriggerDeprecations="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<source ignoreSuppressionOfDeprecations="true">
<include>
<directory suffix=".php">src</directory>
</include>
Expand Down
5 changes: 5 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector;
use Rector\Symfony\Set\SymfonySetList;
use Rector\ValueObject\PhpVersion;

Expand All @@ -20,4 +21,8 @@
->withSets([
SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION,
])
->withSkip([
// Conditions on the Symfony version: always true with the installed version only
RemoveAlwaysTrueIfConditionRector::class => [__DIR__.'/tests/App/TestKernel.php'],
])
;
98 changes: 98 additions & 0 deletions tests/App/TestKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

declare(strict_types=1);

/*
* This file is part of the CleverAge/ArchiveProcessBundle package.
*
* Copyright (c) Clever-Age
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CleverAge\ArchiveProcessBundle\Tests\App;

use CleverAge\ArchiveProcessBundle\CleverAgeArchiveProcessBundle;
use CleverAge\ProcessBundle\CleverAgeProcessBundle;
use CleverAge\ProcessBundle\Registry\ProcessConfigurationRegistry;
use CleverAge\ProcessBundle\Registry\TaskRegistry;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Kernel;

/**
* Application used by the integration tests: process-bundle and this bundle, in a temporary directory of its own (per
* PHP process).
*/
final class TestKernel extends Kernel
{
use MicroKernelTrait;

public function registerBundles(): iterable
{
yield new FrameworkBundle();
yield new CleverAgeProcessBundle();
yield new CleverAgeArchiveProcessBundle();
}

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

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

public function getLogDir(): string
{
return $this->getRunDir().'/logs';
}

protected function configureContainer(ContainerConfigurator $container): void
{
$container->extension('framework', [
'secret' => 'test',
'test' => true,
'http_method_override' => false,
'handle_all_throwables' => true,
'php_errors' => ['log' => true],
'validation' => ['email_validation_mode' => 'html5'],
]);
if (Kernel::VERSION_ID >= 70300) {
// Not setting it is deprecated since Symfony 7.3: its default value changes in 8.0
$container->extension('framework', ['property_info' => ['with_constructor_extractor' => true]]);
}

// Tasks referenced by code (task: <code>): process-bundle 5.4 or later
if (class_exists(TaskRegistry::class)) {
$container->extension('clever_age_process', [
'configurations' => [
'test.archive' => [
'tasks' => [
'zip' => [
'task' => 'archive_zip',
'options' => ['filename' => 'archive.zip', 'files' => [], 'files_base_path' => '/tmp'],
],
'unzip' => [
'task' => 'archive_unzip',
'options' => ['filename' => 'archive.zip', 'destination' => '/tmp'],
],
],
],
],
]);
$services = $container->services();
$services->alias('test.task_registry', TaskRegistry::class)->public();
$services->alias('test.process_configuration_registry', ProcessConfigurationRegistry::class)->public();
}
}

private function getRunDir(): string
{
return sys_get_temp_dir().'/archive_process_bundle_tests_'.getmypid();
}
}
82 changes: 82 additions & 0 deletions tests/Functional/KernelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

declare(strict_types=1);

/*
* This file is part of the CleverAge/ArchiveProcessBundle package.
*
* Copyright (c) Clever-Age
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CleverAge\ArchiveProcessBundle\Tests\Functional;

use CleverAge\ArchiveProcessBundle\Task\UnzipTask;
use CleverAge\ArchiveProcessBundle\Task\ZipTask;
use CleverAge\ArchiveProcessBundle\Tests\App\TestKernel;
use CleverAge\ProcessBundle\Registry\ProcessConfigurationRegistry;
use CleverAge\ProcessBundle\Registry\TaskRegistry;
use PHPUnit\Framework\Attributes\CoversNothing;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

/**
* The bundle in an application with process-bundle (see TestKernel): the container compiles, the services of the
* bundle are resolved with their dependencies.
*/
#[CoversNothing]
class KernelTest extends KernelTestCase
{
private mixed $exceptionHandler;

protected function setUp(): void
{
$this->exceptionHandler = $this->getExceptionHandler();
}

protected function tearDown(): void
{
parent::tearDown();
// The ErrorHandler registered when the kernel boots is not removed by the first Symfony 6.4 versions
if ($this->getExceptionHandler() !== $this->exceptionHandler) {
restore_exception_handler();
}
}

public function testTasksAreRegistered(): void
{
$container = self::getContainer();

self::assertTrue($container->has(ZipTask::class));
self::assertTrue($container->has(UnzipTask::class));
}

public function testTasksAreResolvedByCode(): void
{
if (!class_exists(TaskRegistry::class)) {
self::markTestSkipped('The tasks are referenced by code since cleverage/process-bundle 5.4.');
}
$processConfigurationRegistry = self::getContainer()->get('test.process_configuration_registry');
self::assertInstanceOf(ProcessConfigurationRegistry::class, $processConfigurationRegistry);
$taskRegistry = self::getContainer()->get('test.task_registry');
self::assertInstanceOf(TaskRegistry::class, $taskRegistry);

$processConfiguration = $processConfigurationRegistry->getProcessConfiguration('test.archive');
self::assertInstanceOf(ZipTask::class, $taskRegistry->getTask($processConfiguration->getTaskConfiguration('zip')));
self::assertInstanceOf(UnzipTask::class, $taskRegistry->getTask($processConfiguration->getTaskConfiguration('unzip')));
}

private function getExceptionHandler(): mixed
{
$handler = set_exception_handler(null);
restore_exception_handler();

return $handler;
}

protected static function getKernelClass(): string
{
return TestKernel::class;
}
}
19 changes: 19 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

/*
* This file is part of the CleverAge/ArchiveProcessBundle package.
*
* Copyright (c) Clever-Age
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Symfony\Component\ErrorHandler\DebugClassLoader;

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

// Deprecations of the class loading: extending a class marked @final or @internal, missing return types...
DebugClassLoader::enable();
Loading