Skip to content

Commit

Permalink
Test error_log() in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Feb 7, 2025
1 parent 9f2ebaf commit 1507fae
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/end-to-end/regression/2155.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/2155
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--testdox';
$_SERVER['argv'][] = __DIR__ . '/2155/Issue2155Test.php';

require_once __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->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)
33 changes: 33 additions & 0 deletions tests/end-to-end/regression/2155/Issue2155Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture\Issue2155;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\TestDox;
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();

self::assertSame('', $foo->doFoo());
self::expectErrorOutputRegex('/logged a side effect/');
}
}

0 comments on commit 1507fae

Please sign in to comment.