Skip to content

Commit 636823e

Browse files
Implement migration from restrictDeprecations="true" to ignoreIndirectDeprecations="true"
1 parent fc1f49b commit 636823e

File tree

5 files changed

+92
-0
lines changed

5 files changed

+92
-0
lines changed

.psalm/baseline.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,11 @@
921921
<code><![CDATA[removeChild]]></code>
922922
</PossiblyNullReference>
923923
</file>
924+
<file src="src/TextUI/Configuration/Xml/Migration/Migrations/ReplaceRestrictDeprecationsWithIgnoreDeprecations.php">
925+
<RedundantConditionGivenDocblockType>
926+
<code><![CDATA[assert($source instanceof DOMElement)]]></code>
927+
</RedundantConditionGivenDocblockType>
928+
</file>
924929
<file src="src/TextUI/Configuration/Xml/SchemaFinder.php">
925930
<LessSpecificReturnStatement>
926931
<code><![CDATA[$result]]></code>

src/TextUI/Configuration/Xml/Migration/MigrationBuilder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@
6565
'10.5' => [
6666
RemoveRegisterMockObjectsFromTestArgumentsRecursivelyAttribute::class,
6767
],
68+
69+
'11.0' => [
70+
ReplaceRestrictDeprecationsWithIgnoreDeprecations::class,
71+
],
6872
];
6973

7074
/**
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TextUI\XmlConfiguration;
11+
12+
use function assert;
13+
use DOMDocument;
14+
use DOMElement;
15+
16+
/**
17+
* @internal This class is not covered by the backward compatibility promise for PHPUnit
18+
*/
19+
final readonly class ReplaceRestrictDeprecationsWithIgnoreDeprecations implements Migration
20+
{
21+
/**
22+
* @throws MigrationException
23+
*/
24+
public function migrate(DOMDocument $document): void
25+
{
26+
$source = $document->getElementsByTagName('source')->item(0);
27+
28+
if ($source === null) {
29+
return;
30+
}
31+
32+
assert($source instanceof DOMElement);
33+
34+
if (!$source->hasAttribute('restrictDeprecations')) {
35+
return;
36+
}
37+
38+
$restrictDeprecations = $source->getAttribute('restrictDeprecations') === 'true';
39+
40+
$source->removeAttribute('restrictDeprecations');
41+
42+
if (!$restrictDeprecations ||
43+
$source->hasAttribute('ignoreIndirectDeprecations')) {
44+
return;
45+
}
46+
47+
$source->setAttribute('ignoreIndirectDeprecations', 'true');
48+
}
49+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd"
4+
bootstrap="src/Greeter.php">
5+
<testsuites>
6+
<testsuite name="default">
7+
<directory>tests</directory>
8+
</testsuite>
9+
</testsuites>
10+
11+
<source restrictDeprecations="true"/>
12+
</phpunit>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Configuration migration from PHPUnit 11.0 format works
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--migrate-configuration';
7+
8+
chdir(sys_get_temp_dir());
9+
copy(__DIR__ . '/_files/migration-from-110/phpunit-11.0.xml', 'phpunit.xml');
10+
11+
require_once __DIR__ . '/../../bootstrap.php';
12+
13+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
14+
--EXPECTF--
15+
PHPUnit %s by Sebastian Bergmann and contributors.
16+
17+
Created backup: %sphpunit.xml.bak
18+
Migrated configuration: %sphpunit.xml
19+
--CLEAN--
20+
<?php declare(strict_types=1);
21+
unlink(sys_get_temp_dir() . '/phpunit.xml');
22+
unlink(sys_get_temp_dir() . '/phpunit.xml.bak');

0 commit comments

Comments
 (0)