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 @@ -64,6 +64,7 @@
},
"require-dev": {
"friendsofphp/php-cs-fixer": "*",
"league/flysystem-bundle": "^3.2",
"league/flysystem-local": "^3.0",
"phpstan/extension-installer": "*",
"phpstan/phpstan": "*",
Expand All @@ -72,6 +73,7 @@
"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'],
])
;
114 changes: 114 additions & 0 deletions tests/App/TestKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

declare(strict_types=1);

/*
* This file is part of the CleverAge/FlysystemProcessBundle 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\FlysystemProcessBundle\Tests\App;

use CleverAge\FlysystemProcessBundle\CleverAgeFlysystemProcessBundle;
use CleverAge\ProcessBundle\CleverAgeProcessBundle;
use CleverAge\ProcessBundle\Registry\ProcessConfigurationRegistry;
use CleverAge\ProcessBundle\Registry\TaskRegistry;
use League\FlysystemBundle\Adapter\Builder\LocalAdapterDefinitionBuilder;
use League\FlysystemBundle\FlysystemBundle;
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, FlysystemBundle with a local storage 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 FlysystemBundle();
yield new CleverAgeProcessBundle();
yield new CleverAgeFlysystemProcessBundle();
}

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]]);
}
$directory = '%kernel.cache_dir%/storage';
$container->extension('flysystem', [
'storages' => [
// Configuration format of league/flysystem-bundle 3.5, the former one is deprecated there
'test.storage' => method_exists(LocalAdapterDefinitionBuilder::class, 'addConfiguration') // @phpstan-ignore function.alreadyNarrowedType (false before 3.5)
? ['local' => ['directory' => $directory]]
: ['adapter' => 'local', 'options' => ['directory' => $directory]],
],
]);

// Tasks referenced by code (task: <code>): process-bundle 5.4 or later
if (class_exists(TaskRegistry::class)) {
$container->extension('clever_age_process', [
'configurations' => [
'test.flysystem' => [
'tasks' => [
'file_fetch' => [
'task' => 'flysystem_file_fetch',
'options' => ['source_filesystem' => 'test.storage', 'destination_filesystem' => 'test.storage'],
],
'list_content' => [
'task' => 'flysystem_list_content',
'options' => ['filesystem' => 'test.storage'],
],
'remove_file' => [
'task' => 'flysystem_remove_file',
'options' => ['filesystem' => 'test.storage'],
],
],
],
],
]);
$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().'/flysystem_process_bundle_tests_'.getmypid();
}
}
87 changes: 87 additions & 0 deletions tests/Functional/KernelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

declare(strict_types=1);

/*
* This file is part of the CleverAge/FlysystemProcessBundle 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\FlysystemProcessBundle\Tests\Functional;

use CleverAge\FlysystemProcessBundle\Task\FileFetchTask;
use CleverAge\FlysystemProcessBundle\Task\ListContentTask;
use CleverAge\FlysystemProcessBundle\Task\RemoveFileTask;
use CleverAge\FlysystemProcessBundle\Tests\App\TestKernel;
use CleverAge\ProcessBundle\Registry\ProcessConfigurationRegistry;
use CleverAge\ProcessBundle\Registry\TaskRegistry;
use League\Flysystem\FilesystemOperator;
use PHPUnit\Framework\Attributes\CoversNothing;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

/**
* The bundle in an application with process-bundle and FlysystemBundle (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 testTasksAndStorageAreRegistered(): void
{
$container = self::getContainer();

self::assertTrue($container->has(FileFetchTask::class));
self::assertTrue($container->has(ListContentTask::class));
self::assertTrue($container->has(RemoveFileTask::class));
self::assertInstanceOf(FilesystemOperator::class, $container->get('test.storage'));
}

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.flysystem');
self::assertInstanceOf(FileFetchTask::class, $taskRegistry->getTask($processConfiguration->getTaskConfiguration('file_fetch')));
self::assertInstanceOf(ListContentTask::class, $taskRegistry->getTask($processConfiguration->getTaskConfiguration('list_content')));
self::assertInstanceOf(RemoveFileTask::class, $taskRegistry->getTask($processConfiguration->getTaskConfiguration('remove_file')));
}

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/FlysystemProcessBundle 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