Skip to content

Commit dc5b5be

Browse files
Merge branch '12.3'
2 parents e4b6e97 + fc7d963 commit dc5b5be

File tree

11 files changed

+219
-3
lines changed

11 files changed

+219
-3
lines changed
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>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
phpunit --configuration ../_files/baseline/use-baseline-in-another-directory/phpunit.xml --generate-baseline
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
6+
$_SERVER['argv'][] = '--do-not-cache-result';
7+
$_SERVER['argv'][] = '--configuration';
8+
$_SERVER['argv'][] = __DIR__ . '/../_files/baseline/use-baseline-in-another-directory/phpunit.xml';
9+
10+
require_once __DIR__ . '/../../bootstrap.php';
11+
12+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
13+
14+
--EXPECTF--
15+
PHPUnit %s by Sebastian Bergmann and contributors.
16+
17+
Runtime: %s
18+
Configuration: %s
19+
20+
. 1 / 1 (100%)
21+
22+
Time: %s, Memory: %s
23+
24+
OK (1 test, 1 assertion)
25+
26+
1 issue was ignored by baseline.

0 commit comments

Comments
 (0)