From fa8961d9fad8d45a31264753b0f24ffd6c2b8f68 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 5 Feb 2025 10:53:39 +0100 Subject: [PATCH] Test error_log() in tests --- tests/end-to-end/regression/2155.phpt | 25 ++++++++++++++ .../regression/2155/Issue2155Test.php | 34 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 tests/end-to-end/regression/2155.phpt create mode 100644 tests/end-to-end/regression/2155/Issue2155Test.php diff --git a/tests/end-to-end/regression/2155.phpt b/tests/end-to-end/regression/2155.phpt new file mode 100644 index 0000000000..4809f2b664 --- /dev/null +++ b/tests/end-to-end/regression/2155.phpt @@ -0,0 +1,25 @@ +--TEST-- +https://github.com/sebastianbergmann/phpunit/issues/2155 +--FILE-- +run($_SERVER['argv']); +--EXPECTF-- +PHPUnit %s by Sebastian Bergmann and contributors. + +Runtime: %s + +. 1 / 1 (100%) + +Time: %s, Memory: %s + +Issue2155 (PHPUnit\TestFixture\Issue2155\Issue2155) + ✔ One + +OK (1 test, 2 assertions) diff --git a/tests/end-to-end/regression/2155/Issue2155Test.php b/tests/end-to-end/regression/2155/Issue2155Test.php new file mode 100644 index 0000000000..40c379d4f4 --- /dev/null +++ b/tests/end-to-end/regression/2155/Issue2155Test.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\TestFixture\Issue2155; + +use function error_log; +use PHPUnit\Framework\TestCase; + +class Foo +{ + public function doFoo() + { + error_log('logged a side effect'); + + return ''; + } +} + +final class Issue2155Test extends TestCase +{ + public function testOne(): void + { + $foo = new Foo; + + $this->assertSame('', $foo->doFoo()); + self::expectErrorOutputRegex('/logged a side effect/'); + } +}