Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PhpUnit 10 Compatibility Part 3 (Last) #3530

Merged
merged 8 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,18 @@ jobs:
- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: "Run PHPUnit tests (Experimental: ${{ matrix.experimental }})"
- name: "Run PHPUnit tests 1 (Experimental: ${{ matrix.experimental }})"
env:
FAILURE_ACTION: "${{ matrix.experimental == true }}"
if: ${{ matrix.php-version == '7.4' || matrix.php-version == '8.0' }}
run: vendor/bin/phpunit --verbose || $FAILURE_ACTION

- name: "Run PHPUnit tests 2 (Experimental: ${{ matrix.experimental }})"
env:
FAILURE_ACTION: "${{ matrix.experimental == true }}"
if: ${{ matrix.php-version == '8.1' || matrix.php-version == '8.2' || matrix.php-version == 'nightly' }}
run: vendor/bin/phpunit -c phpunit10.xml.dist --display-incomplete --display-skipped --display-deprecations --display-errors --display-notices --display-warnings || $FAILURE_ACTION

php-cs-fixer:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"phpcompatibility/php-compatibility": "^9.3",
"phpstan/phpstan": "^1.1",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^8.5 || ^9.0",
"phpunit/phpunit": "^8.5 || ^9.0 || ^10.0",
"squizlabs/php_codesniffer": "^3.7",
"tecnickcom/tcpdf": "^6.5"
},
Expand Down
3 changes: 2 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="./tests/bootstrap.php" backupGlobals="true" colors="true" cacheResultFile="/tmp/.phpspreadsheet.phpunit.result.cache">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="./tests/bootstrap.php" backupGlobals="true" colors="true" cacheResultFile="/tmp/.phpspreadsheet.phpunit.result.cache" convertDeprecationsToExceptions="true">
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<php>
<ini name="memory_limit" value="2048M"/>
<ini name="error_reporting" value="E_ALL"/>
</php>
<testsuite name="PhpSpreadsheet Unit Test Suite">
<directory>./tests/PhpSpreadsheetTests</directory>
Expand Down
15 changes: 15 additions & 0 deletions phpunit10.xml.dist
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>
46 changes: 46 additions & 0 deletions src/PhpSpreadsheet/Helper/Handler.php
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);
}
}
3 changes: 3 additions & 0 deletions src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

class ChainedBlockStream
{
/** @var mixed */
public $context;

/**
* The OLE container of the file that is being read.
*
Expand Down
4 changes: 2 additions & 2 deletions tests/PhpSpreadsheetTests/Chart/Issue589Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function testLineChartFill(): void
if ($actualXml === false) {
self::fail('Failure saving the spPr element as xml string!');
} else {
self::assertXmlStringEqualsXmlString('<c:spPr><a:ln><a:solidFill><a:srgbClr val="98B954"/></a:solidFill></a:ln></c:spPr>', $actualXml);
self::assertSame('<c:spPr><a:ln><a:solidFill><a:srgbClr val="98B954"/></a:solidFill></a:ln></c:spPr>', $actualXml);
}
}
}
Expand Down Expand Up @@ -153,7 +153,7 @@ public function testLineChartFillIgnoresColorArray(): void
if ($actualXml === false) {
self::fail('Failure saving the spPr element as xml string!');
} else {
self::assertXmlStringEqualsXmlString('<c:spPr><a:ln/></c:spPr>', $actualXml);
self::assertSame('<c:spPr><a:ln/></c:spPr>', $actualXml);
}
}
}
Expand Down
75 changes: 75 additions & 0 deletions tests/PhpSpreadsheetTests/Helper/HandlerTest.php
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());
}
}
}
32 changes: 32 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,35 @@

// PHP 5.3 Compat
//date_default_timezone_set('Europe/London');

function phpunit10ErrorHandler(int $errno, string $errstr, string $filename, int $lineno): bool
{
$x = error_reporting() & $errno;
if (
in_array(
$errno,
[
E_DEPRECATED,
E_WARNING,
E_NOTICE,
E_USER_DEPRECATED,
E_USER_NOTICE,
E_USER_WARNING,
],
true
)
) {
if (0 === $x) {
return true; // message suppressed - stop error handling
}

throw new \Exception("$errstr $filename $lineno");
}

return false; // continue error handling
}

if (!method_exists(\PHPUnit\Framework\TestCase::class, 'setOutputCallback')) {
ini_set('error_reporting', E_ALL);
set_error_handler('phpunit10ErrorHandler');
}