-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PhpUnit 10 Compatibility Part 3 (Last) (#3530)
* PhpUnit 10 Compatibility Part 3 (Last) Final changes for PhpUnit 10, including enabling it for testing. This finishes the work of PR #3523 and PR #3526. The major remaining problem with PhpUnit 10 is that earlier releases converted notices and warnings to exceptions, and 10 does not. Not having the information provided by the messages seems risky to me. Fortunately, it appears that you can add an error handler to the test bootstrap for 10 and make it act like earlier versions; I have done so. In order to demonstrate the effectiveness of this handler, a new otherwise unused class Helper/Handler and tests for that class are added. As part of the testing of this change, it became apparent that the fopen in OLE::getStream attempts to create a dynamic property $context in Shared/OLE/ChainedBlockStream, and that action is deprecated in Php8.2. Adding the property to the class eliminates that problem. No executable code is added, and this is the only change to source code. There also seems to have been a change in assertXmlStringEqualsXmlString in PhpUnit 10. The only test which uses that method is Chart/Issue589Test, and both the places which use that method could just as easily and effectively use assertSame. They are changed to do so. * Remove Phpunit Verbose Option Not supported in PhpUnit 10. I'm not at all sure that this is the correct solution for this problem. * Try Changing Phpunit Command for Different Php Releases Not sure how to test this locally. We'll see if it works on github. * Another main.yml attempt We shall see. * Eliminate One Test Not sure why testDeprecated is not working in Github; it works locally. Disable it for now and continue to research. * Show Incomplete and Other Messages in PhpUnit 10 6 new command line args to replace the 1 they got rid of. * Restore Disabled Test Deprecated messages are suppressed by default setting for error_reporting. Switch that to E_ALL in bootstrap and restore original test. * Add Deprecation Tests for PhpUnit 9- Default configuration option caused deprecation messages to be suppressed. Change the option.
- Loading branch information
Showing
9 changed files
with
184 additions
and
5 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,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd" bootstrap="./tests/bootstrap.php" backupGlobals="true" colors="true" cacheResultFile="/tmp/.phpspreadsheet.phpunit.result.cache"> | ||
<coverage/> | ||
<php> | ||
<ini name="memory_limit" value="2048M"/> | ||
</php> | ||
<testsuite name="PhpSpreadsheet Unit Test Suite"> | ||
<directory>./tests/PhpSpreadsheetTests</directory> | ||
</testsuite> | ||
<source> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</source> | ||
</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,46 @@ | ||
<?php | ||
|
||
namespace PhpOffice\PhpSpreadsheet\Helper; | ||
|
||
class Handler | ||
{ | ||
/** @var string */ | ||
private static $invalidHex = 'Y'; | ||
|
||
// A bunch of methods to show that we continue | ||
// to capture messages even using PhpUnit 10. | ||
public static function suppressed(): bool | ||
{ | ||
return @trigger_error('hello'); | ||
} | ||
|
||
public static function deprecated(): string | ||
{ | ||
return (string) hexdec(self::$invalidHex); | ||
} | ||
|
||
public static function notice(string $value): void | ||
{ | ||
date_default_timezone_set($value); | ||
} | ||
|
||
public static function warning(): bool | ||
{ | ||
return file_get_contents(__FILE__ . 'noexist') !== false; | ||
} | ||
|
||
public static function userDeprecated(): bool | ||
{ | ||
return trigger_error('hello', E_USER_DEPRECATED); | ||
} | ||
|
||
public static function userNotice(): bool | ||
{ | ||
return trigger_error('userNotice', E_USER_NOTICE); | ||
} | ||
|
||
public static function userWarning(): bool | ||
{ | ||
return trigger_error('userWarning', E_USER_WARNING); | ||
} | ||
} |
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,75 @@ | ||
<?php | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Helper; | ||
|
||
use PhpOffice\PhpSpreadsheet\Helper\Handler; | ||
use PHPUnit\Framework\TestCase; | ||
use Throwable; | ||
|
||
class HandlerTest extends TestCase | ||
{ | ||
public function testSuppressed(): void | ||
{ | ||
self::assertTrue(Handler::suppressed()); | ||
} | ||
|
||
public function testDeprecated(): void | ||
{ | ||
try { | ||
Handler::deprecated(); | ||
self::fail('Expected error/exception did not happen'); | ||
} catch (Throwable $e) { | ||
self::assertStringContainsString('Invalid characters', $e->getMessage()); | ||
} | ||
} | ||
|
||
public function testNotice(): void | ||
{ | ||
try { | ||
Handler::notice('invalidtz'); | ||
self::fail('Expected error/exception did not happen'); | ||
} catch (Throwable $e) { | ||
self::assertStringContainsString('Timezone', $e->getMessage()); | ||
} | ||
} | ||
|
||
public function testWarning(): void | ||
{ | ||
try { | ||
Handler::warning(); | ||
self::fail('Expected error/exception did not happen'); | ||
} catch (Throwable $e) { | ||
self::assertStringContainsString('ailed to open stream', $e->getMessage()); | ||
} | ||
} | ||
|
||
public function testUserDeprecated(): void | ||
{ | ||
try { | ||
Handler::userDeprecated(); | ||
self::fail('Expected error/exception did not happen'); | ||
} catch (Throwable $e) { | ||
self::assertStringContainsString('hello', $e->getMessage()); | ||
} | ||
} | ||
|
||
public function testUserNotice(): void | ||
{ | ||
try { | ||
Handler::userNotice(); | ||
self::fail('Expected error/exception did not happen'); | ||
} catch (Throwable $e) { | ||
self::assertStringContainsString('userNotice', $e->getMessage()); | ||
} | ||
} | ||
|
||
public function testUserWarning(): void | ||
{ | ||
try { | ||
Handler::userWarning(); | ||
self::fail('Expected error/exception did not happen'); | ||
} catch (Throwable $e) { | ||
self::assertStringContainsString('userWarning', $e->getMessage()); | ||
} | ||
} | ||
} |
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