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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"phpunit/phpunit": "^10.5|^11|^12|^13",
"rector/rector": "*",
"roave/security-advisories": "dev-latest",
"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'],
])
;
110 changes: 110 additions & 0 deletions tests/App/TestKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

declare(strict_types=1);

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

use CleverAge\ProcessBundle\CleverAgeProcessBundle;
use CleverAge\ProcessBundle\Registry\ProcessConfigurationRegistry;
use CleverAge\ProcessBundle\Registry\TaskRegistry;
use CleverAge\SoapProcessBundle\CleverAgeSoapProcessBundle;
use CleverAge\SoapProcessBundle\Client\Client;
use CleverAge\SoapProcessBundle\Registry\ClientRegistry;
use CleverAge\SoapProcessBundle\Tests\Fixtures\AttributedClient;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Kernel;

use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

/**
* Application used by the integration tests: process-bundle and this bundle, with a client declared by tag and one by
* attribute, in a temporary directory of its own (per PHP process). The SOAP clients are built lazily (first call),
* so their WSDL is never fetched.
*/
final class TestKernel extends Kernel
{
use MicroKernelTrait;

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

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]]);
}

$services = $container->services();
$services->set('app.soap_client', Client::class)
->args([service('logger'), 'app_tagged', 'https://example.com/service?wsdl'])
->tag('cleverage.soap.client', ['code' => 'app_tagged']);
$services->set(AttributedClient::class)
->autoconfigure()
->args([service('logger'), 'app_attributed', 'https://example.com/service?wsdl']);
// Exposed to the tests
$services->alias('test.client_registry', ClientRegistry::class)->public();
$services->alias('test.transformer_registry', 'cleverage_process.registry.transformer')->public();

// Tasks referenced by code (task: <code>): process-bundle 5.4 or later
if (class_exists(TaskRegistry::class)) {
$container->extension('clever_age_process', [
'configurations' => [
'test.soap' => [
'tasks' => [
'request' => [
'task' => 'soap_request',
'options' => ['client' => 'app_tagged', 'method' => 'Test'],
],
],
],
],
]);
$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().'/soap_process_bundle_tests_'.getmypid();
}
}
2 changes: 1 addition & 1 deletion tests/CleverAgeSoapProcessBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testTaggedClientsAreRegistered(): void
$container->setDefinition('cleverage_soap_process.registry.client', new Definition(ClientRegistry::class))
->setPublic(true);
$container->setDefinition('app.client', new Definition(Client::class, [new Definition(NullLogger::class), 'test', null]))
->addTag('cleverage.soap.client');
->addTag('cleverage.soap.client', ['code' => 'test']);
$container->compile(true);

/** @var ClientRegistry $registry */
Expand Down
94 changes: 94 additions & 0 deletions tests/Functional/KernelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

declare(strict_types=1);

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

use CleverAge\ProcessBundle\Registry\ProcessConfigurationRegistry;
use CleverAge\ProcessBundle\Registry\TaskRegistry;
use CleverAge\ProcessBundle\Registry\TransformerRegistry;
use CleverAge\SoapProcessBundle\Client\Client;
use CleverAge\SoapProcessBundle\Registry\ClientRegistry;
use CleverAge\SoapProcessBundle\Task\RequestTask;
use CleverAge\SoapProcessBundle\Tests\App\TestKernel;
use CleverAge\SoapProcessBundle\Tests\Fixtures\AttributedClient;
use CleverAge\SoapProcessBundle\Transformer\RequestTransformer;
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 testClientsAreResolvedByCode(): void
{
$registry = self::getContainer()->get('test.client_registry');
self::assertInstanceOf(ClientRegistry::class, $registry);

self::assertInstanceOf(Client::class, $registry->getClient('app_tagged'));
self::assertInstanceOf(AttributedClient::class, $registry->getClient('app_attributed'));
}

public function testTransformerIsResolvedByCode(): void
{
$registry = self::getContainer()->get('test.transformer_registry');
self::assertInstanceOf(TransformerRegistry::class, $registry);

self::assertInstanceOf(RequestTransformer::class, $registry->getTransformer('soap_request'));
}

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);

$taskConfiguration = $processConfigurationRegistry->getProcessConfiguration('test.soap')->getTaskConfiguration('request');
self::assertInstanceOf(RequestTask::class, $taskRegistry->getTask($taskConfiguration));
}

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