-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
306 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--TEST-- | ||
https://github.com/sebastianbergmann/phpunit/issues/5884 | ||
--FILE-- | ||
<?php declare(strict_types=1); | ||
$_SERVER['argv'][] = '--do-not-cache-result'; | ||
$_SERVER['argv'][] = '--configuration'; | ||
$_SERVER['argv'][] = __DIR__ . '/5884'; | ||
$_SERVER['argv'][] = '--no-progress'; | ||
$_SERVER['argv'][] = '--testdox'; | ||
|
||
require_once __DIR__ . '/../../bootstrap.php'; | ||
|
||
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']); | ||
--EXPECTF-- | ||
PHPUnit %s by Sebastian Bergmann and contributors. | ||
|
||
Runtime: %s | ||
Configuration: %s | ||
|
||
Time: %s, Memory: %s | ||
|
||
Foo (PHPUnit\TestFixture\Issue5884\Foo) | ||
⚠ Expect user deprecation message n o t ignoring deprecations | ||
✔ Expect user deprecation message a n d ignoring deprecations | ||
✔ Pcre has utf 8 support | ||
✔ Stream to non writable file with p h p unit error handler | ||
✔ Stream to non writable file without p h p unit error handler | ||
✔ Stream to invalid file | ||
|
||
1 test triggered 1 deprecation: | ||
|
||
1) %sFooTest.php:33 | ||
foo | ||
|
||
Triggered by: | ||
|
||
* PHPUnit\TestFixture\Issue5884\FooTest::testExpectUserDeprecationMessageNOTIgnoringDeprecations | ||
%sFooTest.php:29 | ||
|
||
OK, but there were issues! | ||
Tests: 6, Assertions: 7, Deprecations: 1. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="../../../../phpunit.xsd" | ||
bootstrap="src/Foo.php" | ||
displayDetailsOnTestsThatTriggerErrors="true" | ||
displayDetailsOnTestsThatTriggerWarnings="true" | ||
displayDetailsOnTestsThatTriggerNotices="true" | ||
displayDetailsOnTestsThatTriggerDeprecations="true" | ||
displayDetailsOnIncompleteTests="true" | ||
displayDetailsOnSkippedTests="true" | ||
failOnWarning="true" | ||
failOnNotice="true" | ||
failOnDeprecation="true" | ||
> | ||
<testsuites> | ||
<testsuite name="default"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of PHPUnit. | ||
* | ||
* (c) Sebastian Bergmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace PHPUnit\TestFixture\Issue5884; | ||
|
||
use function error_get_last; | ||
use function fopen; | ||
use function is_array; | ||
use function preg_match; | ||
use Exception; | ||
|
||
final class Foo | ||
{ | ||
public static function pcreHasUtf8Support() | ||
{ | ||
// This regex deliberately has a compile error to demonstrate the issue. | ||
return (bool) @preg_match('/^.[/u', 'a'); | ||
} | ||
|
||
public static function openFile($filename): void | ||
{ | ||
// Silenced the PHP native warning in favour of throwing an exception. | ||
$download = @fopen($filename, 'wb'); | ||
|
||
if ($download === false) { | ||
$error = error_get_last(); | ||
|
||
if (!is_array($error)) { | ||
// Shouldn't be possible, but can happen in test situations. | ||
$error = ['message' => 'Failed to open stream']; | ||
} | ||
|
||
throw new Exception($error['message']); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of PHPUnit. | ||
* | ||
* (c) Sebastian Bergmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace PHPUnit\TestFixture\Issue5884; | ||
|
||
use const E_USER_DEPRECATED; | ||
use function chmod; | ||
use function file_get_contents; | ||
use function file_put_contents; | ||
use function sys_get_temp_dir; | ||
use function tempnam; | ||
use function trigger_error; | ||
use function unlink; | ||
use Exception; | ||
use PHPUnit\Framework\Attributes\IgnoreDeprecations; | ||
use PHPUnit\Framework\Attributes\RequiresPhpunit; | ||
use PHPUnit\Framework\Attributes\WithoutErrorHandler; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class FooTest extends TestCase | ||
{ | ||
#[RequiresPhpunit('^11.0')] | ||
public function testExpectUserDeprecationMessageNOTIgnoringDeprecations(): void | ||
{ | ||
$this->expectUserDeprecationMessage('foo'); | ||
|
||
trigger_error('foo', E_USER_DEPRECATED); | ||
} | ||
|
||
#[RequiresPhpunit('^11.0')] | ||
#[IgnoreDeprecations] | ||
public function testExpectUserDeprecationMessageANDIgnoringDeprecations(): void | ||
{ | ||
$this->expectUserDeprecationMessage('foo'); | ||
|
||
trigger_error('foo', E_USER_DEPRECATED); | ||
} | ||
|
||
public function testPcreHasUtf8Support(): void | ||
{ | ||
$this->assertIsBool(Foo::pcreHasUtf8Support()); | ||
} | ||
|
||
public function testStreamToNonWritableFileWithPHPUnitErrorHandler(): void | ||
{ | ||
// Create an unwritable file. | ||
$filename = tempnam(sys_get_temp_dir(), 'RLT'); | ||
|
||
if (file_put_contents($filename, 'foo')) { | ||
chmod($filename, 0o444); | ||
} | ||
|
||
try { | ||
Foo::openFile($filename); | ||
} catch (Exception $e) { | ||
// This "Failed to open stream" exception is expected. | ||
} | ||
|
||
// Now verify the original file is unchanged. | ||
$contents = file_get_contents($filename); | ||
$this->assertSame('foo', $contents); | ||
|
||
chmod($filename, 0o755); | ||
unlink($filename); | ||
} | ||
|
||
#[WithoutErrorHandler] | ||
public function testStreamToNonWritableFileWithoutPHPUnitErrorHandler(): void | ||
{ | ||
// Create an unwritable file. | ||
$filename = tempnam(sys_get_temp_dir(), 'RLT'); | ||
|
||
if (file_put_contents($filename, 'foo')) { | ||
chmod($filename, 0o444); | ||
} | ||
|
||
try { | ||
Foo::openFile($filename); | ||
} catch (Exception $e) { | ||
// This "Failed to open stream" exception is expected. | ||
} | ||
|
||
// Now verify the original file is unchanged. | ||
$contents = file_get_contents($filename); | ||
$this->assertSame('foo', $contents); | ||
|
||
chmod($filename, 0o755); | ||
unlink($filename); | ||
} | ||
|
||
public function testStreamToInvalidFile(): void | ||
{ | ||
$filename = tempnam(sys_get_temp_dir(), 'RLT') . '/missing/directory'; | ||
|
||
$this->expectException(Exception::class); | ||
// First character (F) can be upper or lowercase depending on PHP version. | ||
$this->expectExceptionMessage('ailed to open stream'); | ||
|
||
Foo::openFile($filename); | ||
} | ||
} |