Skip to content

Commit 9a97e9b

Browse files
committed
test(bundle): repair the configuration assertions on current PHPUnit
The 38 bundle configuration tests all failed with `exception message '' contains ...`, whatever the configuration actually reported. `ConfigurationValuesAreInvalidConstraint` hands the caught exception object to PHPUnit's `ExceptionMessageIsOrContains`, but since PHPUnit 10.0.15 that constraint matches against the message string instead. `is_string($other)` is false for an exception, so every expectation failed and the reported message was always empty. v6.2.0 of matthiasnoback/symfony-config-test is the latest release and still does this, so there is nothing to upgrade to. `ConfigurationAssertionsTrait` keeps the upstream assertions and replaces only `assertConfigurationIsInvalid()`, comparing the message itself. The 38 call sites are unchanged; the twelve test classes swap which trait they use. Also removes the `Ergebnis\PHPUnit\SlowTestDetector\Extension` bootstrap. The package is not a dependency, so PHPUnit reported a runner warning and exited 1 on every run, even with no failing test. The suite now passes: 777 tests, 0 failures.
1 parent 6c2bdcf commit 9a97e9b

14 files changed

Lines changed: 75 additions & 27 deletions

.ci-tools/phpunit.xml.dist

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,4 @@
2727
<directory>./../tests</directory>
2828
</exclude>
2929
</source>
30-
<extensions>
31-
<bootstrap class="Ergebnis\PHPUnit\SlowTestDetector\Extension"/>
32-
</extensions>
3330
</phpunit>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Jose\Tests\Bundle\JoseFramework;
6+
7+
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
8+
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
9+
use Symfony\Component\Config\Definition\Processor;
10+
11+
/**
12+
* Keeps the upstream configuration assertions and replaces only the invalid-configuration one.
13+
*
14+
* `ConfigurationValuesAreInvalidConstraint` hands the caught exception to PHPUnit's
15+
* `ExceptionMessageIsOrContains`, which since PHPUnit 10.0.15 matches against the message string instead of
16+
* the exception object. Every expectation therefore fails with an empty message, whatever the configuration
17+
* actually reported. matthiasnoback/symfony-config-test v6.2.0 is the latest release and still does this.
18+
*/
19+
trait ConfigurationAssertionsTrait
20+
{
21+
use ConfigurationTestCaseTrait;
22+
23+
/**
24+
* @param array<array-key, mixed> $configurationValues
25+
*/
26+
protected function assertConfigurationIsInvalid(
27+
array $configurationValues,
28+
$expectedMessage = null,
29+
$useRegExp = false
30+
): void {
31+
try {
32+
(new Processor())->processConfiguration($this->getConfiguration(), $configurationValues);
33+
} catch (InvalidConfigurationException $exception) {
34+
if ($expectedMessage === null) {
35+
static::assertTrue(true);
36+
37+
return;
38+
}
39+
if ($useRegExp === true) {
40+
static::assertMatchesRegularExpression($expectedMessage, $exception->getMessage());
41+
42+
return;
43+
}
44+
static::assertStringContainsString($expectedMessage, $exception->getMessage());
45+
46+
return;
47+
}
48+
49+
static::fail('The configuration should have been considered invalid.');
50+
}
51+
}

tests/Bundle/JoseFramework/Functional/Checker/ConfigurationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Jose\Bundle\JoseFramework\DependencyInjection\Configuration;
88
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Checker\CheckerSource;
99
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Core\CoreSource;
10-
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
10+
use Jose\Tests\Bundle\JoseFramework\ConfigurationAssertionsTrait;
1111
use PHPUnit\Framework\Attributes\Test;
1212
use PHPUnit\Framework\TestCase;
1313

@@ -16,7 +16,7 @@
1616
*/
1717
final class ConfigurationTest extends TestCase
1818
{
19-
use ConfigurationTestCaseTrait;
19+
use ConfigurationAssertionsTrait;
2020

2121
#[Test]
2222
public function theConfigurationIsValidIfNoConfigurationIsSet(): void

tests/Bundle/JoseFramework/Functional/Encryption/JweBuilderConfigurationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Jose\Bundle\JoseFramework\DependencyInjection\Configuration;
88
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Core\CoreSource;
99
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Encryption\EncryptionSource;
10-
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
10+
use Jose\Tests\Bundle\JoseFramework\ConfigurationAssertionsTrait;
1111
use PHPUnit\Framework\Attributes\Test;
1212
use PHPUnit\Framework\TestCase;
1313

@@ -16,7 +16,7 @@
1616
*/
1717
final class JweBuilderConfigurationTest extends TestCase
1818
{
19-
use ConfigurationTestCaseTrait;
19+
use ConfigurationAssertionsTrait;
2020

2121
#[Test]
2222
public function theConfigurationIsValidIfNoConfigurationIsSet(): void

tests/Bundle/JoseFramework/Functional/Encryption/JweDecrypterConfigurationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Jose\Bundle\JoseFramework\DependencyInjection\Configuration;
88
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Core\CoreSource;
99
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Encryption\EncryptionSource;
10-
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
10+
use Jose\Tests\Bundle\JoseFramework\ConfigurationAssertionsTrait;
1111
use PHPUnit\Framework\Attributes\Test;
1212
use PHPUnit\Framework\TestCase;
1313

@@ -16,7 +16,7 @@
1616
*/
1717
final class JweDecrypterConfigurationTest extends TestCase
1818
{
19-
use ConfigurationTestCaseTrait;
19+
use ConfigurationAssertionsTrait;
2020

2121
#[Test]
2222
public function theConfigurationIsValidIfNoConfigurationIsSet(): void

tests/Bundle/JoseFramework/Functional/Encryption/SerializerConfigurationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Jose\Bundle\JoseFramework\DependencyInjection\Configuration;
88
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Core\CoreSource;
99
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Encryption\EncryptionSource;
10-
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
10+
use Jose\Tests\Bundle\JoseFramework\ConfigurationAssertionsTrait;
1111
use PHPUnit\Framework\Attributes\Test;
1212
use PHPUnit\Framework\TestCase;
1313

@@ -16,7 +16,7 @@
1616
*/
1717
final class SerializerConfigurationTest extends TestCase
1818
{
19-
use ConfigurationTestCaseTrait;
19+
use ConfigurationAssertionsTrait;
2020

2121
#[Test]
2222
public function theConfigurationIsValidIfNoConfigurationIsSet(): void

tests/Bundle/JoseFramework/Functional/KeyManagement/JwkUriConfigurationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Jose\Bundle\JoseFramework\DependencyInjection\Configuration;
88
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Core\CoreSource;
99
use Jose\Bundle\JoseFramework\DependencyInjection\Source\KeyManagement\KeyManagementSource;
10-
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
10+
use Jose\Tests\Bundle\JoseFramework\ConfigurationAssertionsTrait;
1111
use PHPUnit\Framework\Attributes\Test;
1212
use PHPUnit\Framework\TestCase;
1313

@@ -16,7 +16,7 @@
1616
*/
1717
final class JwkUriConfigurationTest extends TestCase
1818
{
19-
use ConfigurationTestCaseTrait;
19+
use ConfigurationAssertionsTrait;
2020

2121
#[Test]
2222
public function theConfigurationIsValidIfNoConfigurationIsSet(): void

tests/Bundle/JoseFramework/Functional/KeyManagement/KeyConfigurationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Jose\Bundle\JoseFramework\DependencyInjection\Configuration;
88
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Core\CoreSource;
99
use Jose\Bundle\JoseFramework\DependencyInjection\Source\KeyManagement\KeyManagementSource;
10-
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
10+
use Jose\Tests\Bundle\JoseFramework\ConfigurationAssertionsTrait;
1111
use PHPUnit\Framework\Attributes\Test;
1212
use PHPUnit\Framework\TestCase;
1313

@@ -16,7 +16,7 @@
1616
*/
1717
final class KeyConfigurationTest extends TestCase
1818
{
19-
use ConfigurationTestCaseTrait;
19+
use ConfigurationAssertionsTrait;
2020

2121
#[Test]
2222
public function theConfigurationIsValidIfNoConfigurationIsSet(): void

tests/Bundle/JoseFramework/Functional/KeyManagement/KeySetConfigurationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Jose\Bundle\JoseFramework\DependencyInjection\Configuration;
88
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Core\CoreSource;
99
use Jose\Bundle\JoseFramework\DependencyInjection\Source\KeyManagement\KeyManagementSource;
10-
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
10+
use Jose\Tests\Bundle\JoseFramework\ConfigurationAssertionsTrait;
1111
use PHPUnit\Framework\Attributes\Test;
1212
use PHPUnit\Framework\TestCase;
1313

@@ -16,7 +16,7 @@
1616
*/
1717
final class KeySetConfigurationTest extends TestCase
1818
{
19-
use ConfigurationTestCaseTrait;
19+
use ConfigurationAssertionsTrait;
2020

2121
#[Test]
2222
public function theConfigurationIsValidIfNoConfigurationIsSet(): void

tests/Bundle/JoseFramework/Functional/NestedToken/NestedTokenBuilderConfigurationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Encryption\EncryptionSource;
1111
use Jose\Bundle\JoseFramework\DependencyInjection\Source\NestedToken\NestedToken;
1212
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Signature\SignatureSource;
13-
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
13+
use Jose\Tests\Bundle\JoseFramework\ConfigurationAssertionsTrait;
1414
use PHPUnit\Framework\Attributes\Test;
1515
use PHPUnit\Framework\TestCase;
1616

@@ -19,7 +19,7 @@
1919
*/
2020
final class NestedTokenBuilderConfigurationTest extends TestCase
2121
{
22-
use ConfigurationTestCaseTrait;
22+
use ConfigurationAssertionsTrait;
2323

2424
#[Test]
2525
public function theConfigurationIsValidIfNoConfigurationIsSet(): void

0 commit comments

Comments
 (0)