Skip to content

Commit 71db4ef

Browse files
Add test
1 parent 4703d79 commit 71db4ef

File tree

6 files changed

+136
-0
lines changed

6 files changed

+136
-0
lines changed
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+
bootstrap="src/autoload.php"
5+
beStrictAboutCoverageMetadata="true">
6+
<testsuites>
7+
<testsuite name="default">
8+
<directory>tests</directory>
9+
</testsuite>
10+
</testsuites>
11+
12+
<source>
13+
<include>
14+
<directory>src</directory>
15+
</include>
16+
</source>
17+
</phpunit>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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\TestFixture\Event\RiskyCodeCoverage;
11+
12+
final class Bar
13+
{
14+
public function doSomethingElse(): bool
15+
{
16+
return true;
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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\TestFixture\Event\RiskyCodeCoverage;
11+
12+
final class Foo
13+
{
14+
public function doSomething(): bool
15+
{
16+
return (new Bar)->doSomethingElse();
17+
}
18+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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\TestFixture\Event\RiskyCodeCoverage;
11+
12+
require __DIR__ . '/Foo.php';
13+
14+
require __DIR__ . '/Bar.php';
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\TestFixture\Event\RiskyCodeCoverage;
11+
12+
use PHPUnit\Framework\Attributes\CoversClass;
13+
use PHPUnit\Framework\TestCase;
14+
15+
#[CoversClass(Foo::class)]
16+
final class FooTest extends TestCase
17+
{
18+
public function testSomething(): void
19+
{
20+
$this->assertTrue((new Foo)->doSomething());
21+
}
22+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--TEST--
2+
The right events are emitted in the right order for a test that is considered risky because it executed code that is not listed as code to be covered or used
3+
--SKIPIF--
4+
<?php declare(strict_types=1);
5+
if (!extension_loaded('xdebug')) {
6+
print 'skip: Extension Xdebug must be loaded.';
7+
}
8+
--INI--
9+
xdebug.mode=coverage
10+
--FILE--
11+
<?php declare(strict_types=1);
12+
$_SERVER['argv'][] = '--do-not-cache-result';
13+
$_SERVER['argv'][] = '--debug';
14+
$_SERVER['argv'][] = '--coverage-text';
15+
$_SERVER['argv'][] = '--configuration';
16+
$_SERVER['argv'][] = __DIR__ . '/_files/test-risky-code-coverage';
17+
18+
require __DIR__ . '/../../bootstrap.php';
19+
20+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
21+
--EXPECTF--
22+
PHPUnit Started (PHPUnit %s using %s)
23+
Test Runner Configured
24+
Bootstrap Finished (%sautoload.php)
25+
Test Suite Loaded (1 test)
26+
Event Facade Sealed
27+
Test Runner Started
28+
Test Suite Sorted
29+
Test Runner Execution Started (1 test)
30+
Test Suite Started (%sphpunit.xml, 1 test)
31+
Test Suite Started (default, 1 test)
32+
Test Suite Started (PHPUnit\TestFixture\Event\RiskyCodeCoverage\FooTest, 1 test)
33+
Test Preparation Started (PHPUnit\TestFixture\Event\RiskyCodeCoverage\FooTest::testSomething)
34+
Test Prepared (PHPUnit\TestFixture\Event\RiskyCodeCoverage\FooTest::testSomething)
35+
Assertion Succeeded (Constraint: is true, Value: true)
36+
Test Passed (PHPUnit\TestFixture\Event\RiskyCodeCoverage\FooTest::testSomething)
37+
Test Considered Risky (PHPUnit\TestFixture\Event\RiskyCodeCoverage\FooTest::testSomething)
38+
This test executed code that is not listed as code to be covered or used:
39+
- PHPUnit\TestFixture\Event\RiskyCodeCoverage\Bar
40+
41+
Test Finished (PHPUnit\TestFixture\Event\RiskyCodeCoverage\FooTest::testSomething)
42+
Test Suite Finished (PHPUnit\TestFixture\Event\RiskyCodeCoverage\FooTest, 1 test)
43+
Test Suite Finished (default, 1 test)
44+
Test Suite Finished (%sphpunit.xml, 1 test)
45+
Test Runner Execution Finished
46+
Test Runner Finished
47+
PHPUnit Finished (Shell Exit Code: 0)

0 commit comments

Comments
 (0)