Skip to content

Commit 9a4d0fb

Browse files
Merge branch '10.5' into 11.0
2 parents 19ff5ee + 7eec044 commit 9a4d0fb

File tree

9 files changed

+261
-0
lines changed

9 files changed

+261
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
Add tests for code coverage attributes for class, method, function
3+
--INI--
4+
pcov.directory=tests/end-to-end/code-coverage/code-coverage
5+
--SKIPIF--
6+
<?php declare(strict_types=1);
7+
require __DIR__ . '/../../_files/skip-if-requires-code-coverage-driver.php';
8+
--FILE--
9+
<?php declare(strict_types=1);
10+
$_SERVER['argv'][] = '--do-not-cache-result';
11+
$_SERVER['argv'][] = '--colors=never';
12+
$_SERVER['argv'][] = '--coverage-text';
13+
$_SERVER['argv'][] = '--configuration';
14+
$_SERVER['argv'][] = __DIR__ . '/code-coverage/phpunit.xml';
15+
16+
require_once __DIR__ . '/../../bootstrap.php';
17+
18+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
19+
--EXPECTF--
20+
PHPUnit %s by Sebastian Bergmann and contributors.
21+
22+
Runtime: %s
23+
Configuration: %s
24+
25+
... 3 / 3 (100%)
26+
27+
Time: %s, Memory: %s MB
28+
29+
OK (3 tests, 3 assertions)
30+
31+
32+
Code Coverage Report:
33+
%s
34+
35+
Summary:
36+
Classes: 50.00% (1/2)
37+
Methods: 50.00% (2/4)
38+
Lines: 50.00% (3/6)
39+
40+
PHPUnit\TestFixture\CodeCoverage\FullyTestedClass
41+
Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 1/ 1)
42+
PHPUnit\TestFixture\CodeCoverage\Method
43+
Methods: 33.33% ( 1/ 3) Lines: 33.33% ( 1/ 3)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/*
5+
* This file is part of PHPUnit.
6+
*
7+
* (c) Sebastian Bergmann <[email protected]>
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*/
12+
require_once __DIR__ . '/src/Method.php';
13+
14+
require_once __DIR__ . '/src/FullyTestedClass.php';
15+
16+
require_once __DIR__ . '/src/functions.php';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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="bootstrap.php"
5+
executionOrder="depends,defects"
6+
requireCoverageMetadata="true"
7+
beStrictAboutCoverageMetadata="true"
8+
beStrictAboutOutputDuringTests="true"
9+
failOnRisky="true"
10+
failOnWarning="true">
11+
<testsuites>
12+
<testsuite name="default">
13+
<directory>tests</directory>
14+
</testsuite>
15+
</testsuites>
16+
17+
<source restrictDeprecations="true" restrictNotices="true" restrictWarnings="true">
18+
<include>
19+
<directory>src</directory>
20+
</include>
21+
</source>
22+
</phpunit>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/*
5+
* This file is part of PHPUnit.
6+
*
7+
* (c) Sebastian Bergmann <[email protected]>
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*/
12+
namespace PHPUnit\TestFixture\CodeCoverage;
13+
14+
/*
15+
* This file is part of PHPUnit.
16+
*
17+
* (c) Sebastian Bergmann <[email protected]>
18+
*
19+
* For the full copyright and license information, please view the LICENSE
20+
* file that was distributed with this source code.
21+
*/
22+
23+
class FullyTestedClass
24+
{
25+
public function method(): bool
26+
{
27+
return true;
28+
}
29+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/*
5+
* This file is part of PHPUnit.
6+
*
7+
* (c) Sebastian Bergmann <[email protected]>
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*/
12+
namespace PHPUnit\TestFixture\CodeCoverage;
13+
14+
final class Method
15+
{
16+
public function greet(): string
17+
{
18+
return $this->internalMethod();
19+
}
20+
21+
public function unusedPublicMethod(): string
22+
{
23+
return 'never returned';
24+
}
25+
26+
private function internalMethod(): string
27+
{
28+
return 'Hello, World!';
29+
}
30+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/*
5+
* This file is part of PHPUnit.
6+
*
7+
* (c) Sebastian Bergmann <[email protected]>
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*/
12+
namespace PHPUnit\TestFixture\CodeCoverage;
13+
14+
/*
15+
* This file is part of PHPUnit.
16+
*
17+
* (c) Sebastian Bergmann <[email protected]>
18+
*
19+
* For the full copyright and license information, please view the LICENSE
20+
* file that was distributed with this source code.
21+
*/
22+
23+
function fixture_for_phpunit_code_coverage(): bool
24+
{
25+
return true;
26+
}
27+
28+
function fixture_for_phpunit_code_coverage_not_called(): bool
29+
{
30+
return false;
31+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/*
5+
* This file is part of PHPUnit.
6+
*
7+
* (c) Sebastian Bergmann <[email protected]>
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*/
12+
namespace PHPUnit\TestFixture\CodeCoverage;
13+
14+
/*
15+
* This file is part of PHPUnit.
16+
*
17+
* (c) Sebastian Bergmann <[email protected]>
18+
*
19+
* For the full copyright and license information, please view the LICENSE
20+
* file that was distributed with this source code.
21+
*/
22+
23+
use PHPUnit\Framework\Attributes\CoversClass;
24+
use PHPUnit\Framework\TestCase;
25+
26+
#[CoversClass(FullyTestedClass::class)]
27+
class FullyTestedClassTest extends TestCase
28+
{
29+
public function testMethod(): void
30+
{
31+
$this->assertTrue((new FullyTestedClass)->method());
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/*
5+
* This file is part of PHPUnit.
6+
*
7+
* (c) Sebastian Bergmann <[email protected]>
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*/
12+
namespace PHPUnit\TestFixture\CodeCoverage;
13+
14+
/*
15+
* This file is part of PHPUnit.
16+
*
17+
* (c) Sebastian Bergmann <[email protected]>
18+
*
19+
* For the full copyright and license information, please view the LICENSE
20+
* file that was distributed with this source code.
21+
*/
22+
23+
use PHPUnit\Framework\Attributes\CoversFunction;
24+
use PHPUnit\Framework\TestCase;
25+
26+
#[CoversFunction('\PHPUnit\TestFixture\CodeCoverage\fixture_for_phpunit_code_coverage')]
27+
class FunctionTest extends TestCase
28+
{
29+
public function testFunction(): void
30+
{
31+
$this->assertTrue(fixture_for_phpunit_code_coverage());
32+
}
33+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/*
5+
* This file is part of PHPUnit.
6+
*
7+
* (c) Sebastian Bergmann <[email protected]>
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*/
12+
namespace PHPUnit\TestFixture\CodeCoverage;
13+
14+
use PHPUnit\Framework\Attributes\CoversClass;
15+
use PHPUnit\Framework\TestCase;
16+
17+
#[CoversClass(Method::class)]
18+
final class MethodTest extends TestCase
19+
{
20+
public function testMethod(): void
21+
{
22+
$this->assertSame('Hello, World!', (new Method)->greet());
23+
}
24+
}

0 commit comments

Comments
 (0)