Skip to content

Commit fc7d963

Browse files
Merge branch '11.5' into 12.3
2 parents 7f1b593 + cec04e4 commit fc7d963

File tree

12 files changed

+226
-3
lines changed

12 files changed

+226
-3
lines changed

ChangeLog-12.3.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes of the PHPUnit 12.3 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
44

5+
## [12.3.1] - 2025-MM-DD
6+
7+
### Fixed
8+
9+
* [#6160](https://github.com/sebastianbergmann/phpunit/issues/6160): Baseline file in a subdirectory contains absolute paths
10+
511
## [12.3.0] - 2025-08-01
612

713
### Added
@@ -24,4 +30,5 @@ All notable changes of the PHPUnit 12.3 release series are documented in this fi
2430
* [#6229](https://github.com/sebastianbergmann/phpunit/issues/6229): `Configuration::excludeTestSuite()`, use `Configuration::excludeTestSuites()` instead
2531
* [#6246](https://github.com/sebastianbergmann/phpunit/issues/6246): Using `#[CoversNothing]` on a test method
2632

33+
[12.3.1]: https://github.com/sebastianbergmann/phpunit/compare/12.3.0...12.3
2734
[12.3.0]: https://github.com/sebastianbergmann/phpunit/compare/12.2.9...12.3.0
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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\Runner\Baseline;
11+
12+
use PHPUnit\Runner\Exception;
13+
use RuntimeException;
14+
15+
/**
16+
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
17+
*
18+
* @internal This class is not covered by the backward compatibility promise for PHPUnit
19+
*/
20+
final class CannotWriteBaselineException extends RuntimeException implements Exception
21+
{
22+
}

src/Runner/Baseline/Writer.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
use function dirname;
1313
use function file_put_contents;
14+
use function is_dir;
15+
use function realpath;
16+
use function sprintf;
1417
use XMLWriter;
1518

1619
/**
@@ -22,10 +25,18 @@
2225
{
2326
/**
2427
* @param non-empty-string $baselineFile
28+
*
29+
* @throws CannotWriteBaselineException
2530
*/
2631
public function write(string $baselineFile, Baseline $baseline): void
2732
{
28-
$pathCalculator = new RelativePathCalculator(dirname($baselineFile));
33+
$normalizedBaselineFile = realpath(dirname($baselineFile));
34+
35+
if ($normalizedBaselineFile === false || !is_dir($normalizedBaselineFile)) {
36+
throw new CannotWriteBaselineException(sprintf('Cannot write baseline to "%s".', $baselineFile));
37+
}
38+
39+
$pathCalculator = new RelativePathCalculator($normalizedBaselineFile);
2940

3041
$writer = new XMLWriter;
3142

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
baseline.xml
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="../../../../../phpunit.xsd"
4+
cacheResult="false"
5+
>
6+
<testsuites>
7+
<testsuite name="default">
8+
<directory>tests</directory>
9+
</testsuite>
10+
</testsuites>
11+
12+
<source baseline="tests/baseline.xml">
13+
<include>
14+
<directory>src</directory>
15+
</include>
16+
</source>
17+
</phpunit>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
declare(strict_types=1);
3+
/*
4+
* This file is part of PHPUnit.
5+
*
6+
* (c) Sebastian Bergmann <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
namespace PHPUnit\TestFixture\Baseline;
12+
13+
use const E_USER_DEPRECATED;
14+
use function trigger_error;
15+
use PHPUnit\Framework\TestCase;
16+
17+
final class Test extends TestCase
18+
{
19+
public function testDeprecation(): void
20+
{
21+
trigger_error('deprecation', E_USER_DEPRECATED);
22+
23+
$this->assertTrue(true);
24+
}
25+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="../../../../../phpunit.xsd"
4+
cacheResult="false"
5+
>
6+
<testsuites>
7+
<testsuite name="default">
8+
<directory>tests</directory>
9+
</testsuite>
10+
</testsuites>
11+
12+
<source baseline="tests/baseline.xml">
13+
<include>
14+
<directory>src</directory>
15+
</include>
16+
</source>
17+
</phpunit>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
declare(strict_types=1);
3+
/*
4+
* This file is part of PHPUnit.
5+
*
6+
* (c) Sebastian Bergmann <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
namespace PHPUnit\TestFixture\Baseline;
12+
13+
use const E_USER_DEPRECATED;
14+
use function trigger_error;
15+
use PHPUnit\Framework\TestCase;
16+
17+
final class Test extends TestCase
18+
{
19+
public function testDeprecation(): void
20+
{
21+
trigger_error('deprecation', E_USER_DEPRECATED);
22+
23+
$this->assertTrue(true);
24+
}
25+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0"?>
2+
<files version="1">
3+
<file path="Test.php">
4+
<line number="21" hash="a1022fb62c4705938dd2c6df5ff35b2621f9e97d">
5+
<issue><![CDATA[deprecation]]></issue>
6+
</line>
7+
</file>
8+
</files>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
phpunit --configuration ../_files/baseline/generate-baseline-with-relative-directory/phpunit.xml --generate-baseline
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
6+
$baselineAbsolutePath = __DIR__ . '/../_files/baseline/generate-baseline-with-relative-directory/baseline.xml';
7+
$baseline = ltrim(str_replace(getcwd(), '', $baselineAbsolutePath), DIRECTORY_SEPARATOR);
8+
9+
$_SERVER['argv'][] = '--do-not-cache-result';
10+
$_SERVER['argv'][] = '--generate-baseline';
11+
$_SERVER['argv'][] = $baseline;
12+
$_SERVER['argv'][] = '--configuration';
13+
$_SERVER['argv'][] = __DIR__ . '/../_files/baseline/generate-baseline-with-relative-directory/phpunit.xml';
14+
15+
require_once __DIR__ . '/../../bootstrap.php';
16+
17+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
18+
19+
print file_get_contents($baseline);
20+
21+
@unlink($baselineAbsolutePath);
22+
--EXPECTF--
23+
PHPUnit %s by Sebastian Bergmann and contributors.
24+
25+
Runtime: %s
26+
Configuration: %s
27+
28+
D 1 / 1 (100%)
29+
30+
Time: %s, Memory: %s
31+
32+
OK, but there were issues!
33+
Tests: 1, Assertions: 1, Deprecations: 1.
34+
35+
Baseline written to %sbaseline.xml.
36+
<?xml version="1.0"?>
37+
<files version="1">
38+
<file path="tests/Test.php">
39+
<line number="21" hash="a1022fb62c4705938dd2c6df5ff35b2621f9e97d">
40+
<issue><![CDATA[deprecation]]></issue>
41+
</line>
42+
</file>
43+
</files>

0 commit comments

Comments
 (0)