Skip to content

Commit

Permalink
Fixes failing tests; reorganized test files (PHPUnit 10.x related) (#583
Browse files Browse the repository at this point in the history
)

* Fixes failing tests; reorganized test files (PHPUnit 10.x related)

Since version 10, PHPUnit complains about:

1) Your XML configuration validates against a deprecated schema. Migrate
your XML configuration using "--migrate-configuration"!

2) Class AltAutoloadTest cannot be found in
D:\a\pdfparser\pdfparser\tests\AltAutoloadTest.php

3) Class Tests\Smalot\PdfParser\Performance\Test\AbstractPerformanceTest
cannot be found in
D:\a\pdfparser\pdfparser\tests\Performance\Test\AbstractPerformanceTest.php

4) Class
Tests\Smalot\PdfParser\Performance\Test\DocumentDictionaryCacheTest
cannot be found in
D:\a\pdfparser\pdfparser\tests\Performance\Test\DocumentDictionaryCacheTest.php

The first one is easy to solve.

But the other 3 are confusing, because PHPUnit 9 did not complain at
all. Reason for these warnings is that since PHPUnit v10, it doesn't
like abstract Test classes or files (containing Test in the name), which
contain no class at all.

Source: sebastianbergmann/phpunit#4979

To mitigate these warnings and to make maintenance easier in the future,
I reorganized our test files and put them in different folders. PHPUnit
tests are separated from our other tests.

* fixed alt autoloading

* reverted name change for AbstractPerformanceTest

* migrated Windows-related PHPUnit config file

* dev-tools: restrict PHPUnit version in composer.json

* Update dev-tools/composer.json

Co-authored-by: Jérémy Benoist <[email protected]>

---------

Co-authored-by: Jérémy Benoist <[email protected]>
  • Loading branch information
k00ni and j0k3r authored Mar 10, 2023
1 parent 70433d1 commit 3ef8bc5
Show file tree
Hide file tree
Showing 38 changed files with 104 additions and 132 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ jobs:
coverage: "none"

- name: "Test alt-autoload"
run: "php tests/AltAutoloadTest.php"
run: "php tests/AltAutoloading/AltAutoloadCheck.php"

phpunit-lowest:
name: "PHPUnit lowest deps (PHP ${{ matrix.php }})"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
debug*
composer.lock
/.php-cs-fixer.cache
/.phpunit.cache
/.phpunit.result.cache
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
},
"autoload-dev": {
"psr-4": {
"Tests\\Smalot\\PdfParser\\": "tests/"
"PerformanceTests\\": "tests/Performance/",
"PHPUnitTests\\": "tests/PHPUnit/"
}
},
"config": {
Expand Down
2 changes: 1 addition & 1 deletion dev-tools/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"friendsofphp/php-cs-fixer": "^3",
"phpstan/phpstan": "^1",
"phpstan/phpstan-phpunit": "^1",
"phpunit/phpunit": ">=7.5"
"phpunit/phpunit": ">=7.5 <11.0"
}
}
51 changes: 18 additions & 33 deletions phpunit-windows.xml
Original file line number Diff line number Diff line change
@@ -1,36 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Only use this when running in Windows environment! -->

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor\autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
verbose="true"
>
<php>
<ini name="error_reporting" value="-1" />
<ini name="zend.enable_gc" value="0"/>
<ini name="error_reporting" value="-1"/>
<ini name="intl.error_level" value="0"/>
<ini name="display_errors" value="On"/>
</php>

<testsuites>
<testsuite name="all">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" backupGlobals="false" bootstrap="vendor\autoload.php" colors="true" processIsolation="false" stopOnFailure="false" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage>
<include>
<directory>src</directory>
</include>
</coverage>
<php>
<ini name="error_reporting" value="-1"/>
<ini name="zend.enable_gc" value="0"/>
<ini name="error_reporting" value="-1"/>
<ini name="intl.error_level" value="0"/>
<ini name="display_errors" value="On"/>
</php>
<testsuites>
<testsuite name="all">
<directory>tests/PHPUnit</directory>
</testsuite>
</testsuites>
</phpunit>
50 changes: 18 additions & 32 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
verbose="true"
>
<php>
<ini name="error_reporting" value="-1" />
<ini name="zend.enable_gc" value="0"/>
<ini name="error_reporting" value="-1"/>
<ini name="intl.error_level" value="0"/>
<ini name="display_errors" value="On"/>
</php>

<testsuites>
<testsuite name="all">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage>
<include>
<directory>src</directory>
</include>
</coverage>
<php>
<ini name="error_reporting" value="-1"/>
<ini name="zend.enable_gc" value="0"/>
<ini name="error_reporting" value="-1"/>
<ini name="intl.error_level" value="0"/>
<ini name="display_errors" value="On"/>
</php>
<testsuites>
<testsuite name="all">
<directory>tests/PHPUnit</directory>
</testsuite>
</testsuites>
</phpunit>
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
* along with this program.
* If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
*/
require __DIR__.'/../alt_autoload.php-dist';
require __DIR__.'/../../alt_autoload.php-dist';

$parser = new Smalot\PdfParser\Parser();

$filename = __DIR__.'/../samples/InternationalChars.pdf';
$filename = __DIR__.'/../../samples/InternationalChars.pdf';
$document = $parser->parseFile($filename);

$needle = 'Лорем ипсум долор сит амет, еу сед либрис долорем инцоррупте.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
* If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
*/

namespace Tests\Smalot\PdfParser\Integration;
namespace PHPUnitTests\Integration;

use PHPUnitTests\TestCase;
use Smalot\PdfParser\Config;
use Tests\Smalot\PdfParser\TestCase;

class ConfigTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
* If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
*/

namespace Tests\Smalot\PdfParser\Integration;
namespace PHPUnitTests\Integration;

use PHPUnitTests\TestCase;
use Smalot\PdfParser\Document;
use Smalot\PdfParser\Header;
use Smalot\PdfParser\Page;
use Smalot\PdfParser\Pages;
use Smalot\PdfParser\Parser;
use Smalot\PdfParser\PDFObject;
use Tests\Smalot\PdfParser\TestCase;

class DocumentTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
* If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
*/

namespace Tests\Smalot\PdfParser\Integration\Element;
namespace PHPUnitTests\Integration\Element;

use PHPUnitTests\TestCase;
use Smalot\PdfParser\Document;
use Smalot\PdfParser\Element\ElementArray;
use Smalot\PdfParser\Element\ElementNumeric;
use Smalot\PdfParser\Header;
use Smalot\PdfParser\Page;
use Tests\Smalot\PdfParser\TestCase;

class ElementArrayTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
* If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
*/

namespace Tests\Smalot\PdfParser\Integration\Element;
namespace PHPUnitTests\Integration\Element;

use PHPUnitTests\TestCase;
use Smalot\PdfParser\Element\ElementBoolean;
use Tests\Smalot\PdfParser\TestCase;

class ElementBooleanTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
* If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
*/

namespace Tests\Smalot\PdfParser\Integration\Element;
namespace PHPUnitTests\Integration\Element;

use PHPUnitTests\TestCase;
use Smalot\PdfParser\Element\ElementDate;
use Tests\Smalot\PdfParser\TestCase;

class ElementDateTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
* If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
*/

namespace Tests\Smalot\PdfParser\Integration\Element;
namespace PHPUnitTests\Integration\Element;

use PHPUnitTests\TestCase;
use Smalot\PdfParser\Element\ElementDate;
use Smalot\PdfParser\Element\ElementHexa;
use Smalot\PdfParser\Element\ElementString;
use Tests\Smalot\PdfParser\TestCase;

class ElementHexaTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
* If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
*/

namespace Tests\Smalot\PdfParser\Integration\Element;
namespace PHPUnitTests\Integration\Element;

use PHPUnitTests\TestCase;
use Smalot\PdfParser\Element\ElementMissing;
use Tests\Smalot\PdfParser\TestCase;

class ElementMissingTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
* If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
*/

namespace Tests\Smalot\PdfParser\Integration\Element;
namespace PHPUnitTests\Integration\Element;

use PHPUnitTests\TestCase;
use Smalot\PdfParser\Element\ElementName;
use Tests\Smalot\PdfParser\TestCase;

class ElementNameTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
* If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
*/

namespace Tests\Smalot\PdfParser\Integration\Element;
namespace PHPUnitTests\Integration\Element;

use PHPUnitTests\TestCase;
use Smalot\PdfParser\Element\ElementNull;
use Tests\Smalot\PdfParser\TestCase;

class ElementNullTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
* If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
*/

namespace Tests\Smalot\PdfParser\Integration\Element;
namespace PHPUnitTests\Integration\Element;

use PHPUnitTests\TestCase;
use Smalot\PdfParser\Element\ElementNumeric;
use Tests\Smalot\PdfParser\TestCase;

class ElementNumericTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
* If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
*/

namespace Tests\Smalot\PdfParser\Integration\Element;
namespace PHPUnitTests\Integration\Element;

use PHPUnitTests\TestCase;
use Smalot\PdfParser\Element\ElementString;
use Tests\Smalot\PdfParser\TestCase;

class ElementStringTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
* If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
*/

namespace Tests\Smalot\PdfParser\Integration\Element;
namespace PHPUnitTests\Integration\Element;

use PHPUnitTests\TestCase;
use Smalot\PdfParser\Element\ElementStruct;
use Smalot\PdfParser\Header;
use Tests\Smalot\PdfParser\TestCase;

class ElementStructTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
* If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
*/

namespace Tests\Smalot\PdfParser\Integration\Element;
namespace PHPUnitTests\Integration\Element;

use PHPUnitTests\TestCase;
use Smalot\PdfParser\Element\ElementXRef;
use Tests\Smalot\PdfParser\TestCase;

class ElementXRefTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
* If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
*/

namespace Tests\Smalot\PdfParser\Integration;
namespace PHPUnitTests\Integration;

use PHPUnitTests\TestCase;
use Smalot\PdfParser\Element;
use Smalot\PdfParser\Element\ElementArray;
use Smalot\PdfParser\Element\ElementBoolean;
Expand All @@ -45,7 +46,6 @@
use Smalot\PdfParser\Element\ElementString;
use Smalot\PdfParser\Element\ElementXRef;
use Smalot\PdfParser\Header;
use Tests\Smalot\PdfParser\TestCase;

class ElementTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@
* If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
*/

namespace Tests\Smalot\PdfParser\Integration;
namespace PHPUnitTests\Integration;

use Exception;
use PHPUnitTests\TestCase;
use Smalot\PdfParser\Document;
use Smalot\PdfParser\Element;
use Smalot\PdfParser\Encoding;
use Smalot\PdfParser\Encoding\StandardEncoding;
use Smalot\PdfParser\Exception\EncodingNotFoundException;
use Smalot\PdfParser\Header;
use Tests\Smalot\PdfParser\TestCase;

class EncodingTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@
* If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
*/

namespace Tests\Smalot\PdfParser\Integration;
namespace PHPUnitTests\Integration;

use PHPUnitTests\TestCase;
use Smalot\PdfParser\Config;
use Smalot\PdfParser\Document;
use Smalot\PdfParser\Element;
use Smalot\PdfParser\Encoding;
use Smalot\PdfParser\Font;
use Smalot\PdfParser\Header;
use Smalot\PdfParser\PDFObject;
use Tests\Smalot\PdfParser\TestCase;

class FontTest extends TestCase
{
Expand Down
Loading

0 comments on commit 3ef8bc5

Please sign in to comment.