Skip to content

Commit 097acaf

Browse files
Add test
1 parent f2ebdc5 commit 097acaf

File tree

6 files changed

+138
-0
lines changed

6 files changed

+138
-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="vendor/autoload.php"
5+
>
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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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\SelfDirectIndirect;
11+
12+
use function trigger_error;
13+
14+
final class FirstPartyClass
15+
{
16+
public function method(): true
17+
{
18+
(new ThirdPartyClass)->method();
19+
20+
@trigger_error('deprecation in first-party code', E_USER_DEPRECATED);
21+
22+
return true;
23+
}
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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\SelfDirectIndirect;
11+
12+
use PHPUnit\Framework\TestCase;
13+
14+
final class FirstPartyClassTest extends TestCase
15+
{
16+
public function testOne(): void
17+
{
18+
$this->assertTrue((new FirstPartyClass)->method());
19+
}
20+
21+
public function testTwo(): void
22+
{
23+
$this->assertTrue((new ThirdPartyClass)->anotherMethod());
24+
}
25+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php declare(strict_types=1);
2+
namespace PHPUnit\TestFixture\SelfDirectIndirect;
3+
4+
final class ThirdPartyClass
5+
{
6+
public function method(): void
7+
{
8+
@trigger_error('deprecation in third-party code', E_USER_DEPRECATED);
9+
}
10+
11+
public function anotherMethod(): true
12+
{
13+
return (new FirstPartyClass)->method();
14+
}
15+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php declare(strict_types=1);
2+
require __DIR__ . '/../src/FirstPartyClass.php';
3+
require __DIR__ . '/ThirdPartyClass.php';
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
--TEST--
2+
The right events are emitted in the right order for a test that runs code which triggers E_USER_DEPRECATED
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$traceFile = tempnam(sys_get_temp_dir(), __FILE__);
6+
7+
$_SERVER['argv'][] = '--do-not-cache-result';
8+
$_SERVER['argv'][] = '--no-output';
9+
$_SERVER['argv'][] = '--log-events-text';
10+
$_SERVER['argv'][] = $traceFile;
11+
$_SERVER['argv'][] = '--configuration';
12+
$_SERVER['argv'][] = __DIR__ . '/_files/self-direct-indirect';
13+
14+
require __DIR__ . '/../../bootstrap.php';
15+
16+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
17+
18+
print file_get_contents($traceFile);
19+
20+
unlink($traceFile);
21+
--EXPECTF--
22+
PHPUnit Started (PHPUnit %s using %s)
23+
Test Runner Configured
24+
Bootstrap Finished (%sautoload.php)
25+
Test Suite Loaded (2 tests)
26+
Event Facade Sealed
27+
Test Runner Started
28+
Test Suite Sorted
29+
Test Runner Execution Started (2 tests)
30+
Test Suite Started (%sphpunit.xml, 2 tests)
31+
Test Suite Started (default, 2 tests)
32+
Test Suite Started (PHPUnit\TestFixture\SelfDirectIndirect\FirstPartyClassTest, 2 tests)
33+
Test Preparation Started (PHPUnit\TestFixture\SelfDirectIndirect\FirstPartyClassTest::testOne)
34+
Test Prepared (PHPUnit\TestFixture\SelfDirectIndirect\FirstPartyClassTest::testOne)
35+
Test Triggered Deprecation (PHPUnit\TestFixture\SelfDirectIndirect\FirstPartyClassTest::testOne, issue triggered by first-party code calling into third-party code, suppressed using operator)
36+
deprecation in third-party code
37+
Test Triggered Deprecation (PHPUnit\TestFixture\SelfDirectIndirect\FirstPartyClassTest::testOne, issue triggered by first-party code calling into first-party code, suppressed using operator)
38+
deprecation in first-party code
39+
Test Passed (PHPUnit\TestFixture\SelfDirectIndirect\FirstPartyClassTest::testOne)
40+
Test Finished (PHPUnit\TestFixture\SelfDirectIndirect\FirstPartyClassTest::testOne)
41+
Test Preparation Started (PHPUnit\TestFixture\SelfDirectIndirect\FirstPartyClassTest::testTwo)
42+
Test Prepared (PHPUnit\TestFixture\SelfDirectIndirect\FirstPartyClassTest::testTwo)
43+
Test Triggered Deprecation (PHPUnit\TestFixture\SelfDirectIndirect\FirstPartyClassTest::testTwo, issue triggered by first-party code calling into third-party code, suppressed using operator)
44+
deprecation in third-party code
45+
Test Triggered Deprecation (PHPUnit\TestFixture\SelfDirectIndirect\FirstPartyClassTest::testTwo, issue triggered by third-party code, suppressed using operator)
46+
deprecation in first-party code
47+
Test Passed (PHPUnit\TestFixture\SelfDirectIndirect\FirstPartyClassTest::testTwo)
48+
Test Finished (PHPUnit\TestFixture\SelfDirectIndirect\FirstPartyClassTest::testTwo)
49+
Test Suite Finished (PHPUnit\TestFixture\SelfDirectIndirect\FirstPartyClassTest, 2 tests)
50+
Test Suite Finished (default, 2 tests)
51+
Test Suite Finished (%sphpunit.xml, 2 tests)
52+
Test Runner Execution Finished
53+
Test Runner Finished
54+
PHPUnit Finished (Shell Exit Code: 0)

0 commit comments

Comments
 (0)