Skip to content

Commit 3deeb03

Browse files
author
Ian Jenkins
committed
Update for PHP8 support.
* Updates PHPUnit to ^9. * Remove phpunit_extensions due to lack of php8 support and implements assertion in a trait.
1 parent fe56d8b commit 3deeb03

12 files changed

+81
-38
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/vendor
22
composer.lock
33
clover.xml
4+
.phpunit.result.cache
5+
phpunit.xml.bak

composer.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
],
1212
"minimum-stability": "stable",
1313
"require": {
14-
"php": ">=5.6,<8.0-DEV"
14+
"php": ">=7.4",
15+
"composer-plugin-api": "^1.0.0 || ^2.0.0"
1516
},
1617
"require-dev": {
17-
"composer/composer": "~1.1",
18-
"phpunit/phpunit": "~5.3",
19-
"etsy/phpunit-extensions": "0.7.*"
18+
"composer/composer": "^2",
19+
"phpunit/phpunit": "^9"
2020
},
2121
"scripts": {
2222
"post-package-install": [

phpunit.xml

+19-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
bootstrap="./vendor/autoload.php"
44
colors="true"
55
convertErrorsToExceptions="true"
@@ -9,26 +9,27 @@
99
stopOnFailure="false"
1010
processIsolation="false"
1111
backupGlobals="false"
12-
syntaxCheck="true"
12+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
1313
>
14+
<coverage includeUncoveredFiles="true">
15+
<include>
16+
<directory suffix=".php">./src</directory>
17+
</include>
18+
<exclude>
19+
<directory>./vendor</directory>
20+
<directory>./tests</directory>
21+
<directory>./template</directory>
22+
<directory>./bin</directory>
23+
</exclude>
24+
<report>
25+
<clover outputFile="./clover.xml"/>
26+
<text outputFile="php://stdout" showUncoveredFiles="false"/>
27+
</report>
28+
</coverage>
1429
<testsuites>
1530
<testsuite name="Tests">
1631
<directory>./tests</directory>
1732
</testsuite>
1833
</testsuites>
19-
<filter>
20-
<whitelist addUncoveredFilesFromWhitelist="true">
21-
<directory suffix=".php">./src</directory>
22-
<exclude>
23-
<directory>./vendor</directory>
24-
<directory>./tests</directory>
25-
<directory>./template</directory>
26-
<directory>./bin</directory>
27-
</exclude>
28-
</whitelist>
29-
</filter>
30-
<logging>
31-
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
32-
<log type="coverage-clover" target="./clover.xml"/>
33-
</logging>
34-
</phpunit>
34+
<logging/>
35+
</phpunit>

tests/CustomAssertionsTrait.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Jenko\Sunscreen\Tests;
4+
5+
trait CustomAssertionsTrait
6+
{
7+
public static function assertStringMatchIgnoreWhitespace( string $expecting, string $actual )
8+
{
9+
$expected = preg_replace('#\&. #', '', implode(' ', preg_split('/\s+/', trim($expecting))));
10+
$actual = preg_replace('#\&. #', '', implode(' ', preg_split('/\s+/', trim($actual))));
11+
12+
return self::assertEquals(
13+
$expected,
14+
$actual
15+
);
16+
}
17+
}

tests/Guesser/AbstractClassGuesserTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
use Composer\Package\Package;
66
use Jenko\Sunscreen\Guesser\AbstractClassGuesser;
77
use Jenko\Sunscreen\Util;
8+
use PHPUnit\Framework\TestCase;
89

9-
class AbstractClassGuesserTest extends \PHPUnit_Framework_TestCase
10+
class AbstractClassGuesserTest extends TestCase
1011
{
1112
/**
1213
* @dataProvider getAutoloadsAndExpectedClasses
@@ -33,4 +34,4 @@ public function getAutoloadsAndExpectedClasses()
3334
[['psr-9999' => ['Foo\\Bar\\' => 'foo/bar/src/']], []],
3435
];
3536
}
36-
}
37+
}

tests/Guesser/InterfaceClassGuesserTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
use Composer\Package\Package;
66
use Jenko\Sunscreen\Guesser\InterfaceGuesser;
77
use Jenko\Sunscreen\Util;
8+
use PHPUnit\Framework\TestCase;
89

9-
class InterfaceGuesserTest extends \PHPUnit_Framework_TestCase
10+
class InterfaceGuesserTest extends TestCase
1011
{
1112
/**
1213
* @dataProvider getAutoloadsAndExpectedClasses
@@ -33,4 +34,4 @@ public function getAutoloadsAndExpectedClasses()
3334
[['psr-9999' => ['Foo\\Bar\\' => 'foo/bar/src/']], []],
3435
];
3536
}
36-
}
37+
}

tests/Processor/AdapterMethodsProcessorTest.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
namespace Jenko\Sunscreen\Tests\Processor;
44

55
use Jenko\Sunscreen\Processor\AdapterMethodsProcessor;
6+
use Jenko\Sunscreen\Tests\CustomAssertionsTrait;
67
use Jenko\Sunscreen\Tests\Fixtures\Foo;
8+
use PHPUnit\Framework\TestCase;
79

8-
class AdapterMethodsProcessorTest extends \PHPUnit_Framework_TestCase
10+
class AdapterMethodsProcessorTest extends TestCase
911
{
12+
use CustomAssertionsTrait;
13+
1014
/**
1115
* @dataProvider getMethodsAndExpectedStrings
1216
* @param array $methods
@@ -16,7 +20,7 @@ public function testProcessGeneratesExpectedMethodsString($methods, $expectedMet
1620
{
1721
$processor = new AdapterMethodsProcessor($methods, 'myInterface');
1822

19-
\PHPUnit_Extensions_Assert_More::assertStringMatchIgnoreWhitespace(
23+
self::assertStringMatchIgnoreWhitespace(
2024
$expectedMethodsString,
2125
$processor->process(true)
2226
);

tests/Processor/AdapterProcessorTest.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
namespace Jenko\Sunscreen\Tests\Processor;
44

55
use Jenko\Sunscreen\Processor\AdapterProcessor;
6+
use Jenko\Sunscreen\Tests\CustomAssertionsTrait;
67
use Jenko\Sunscreen\Util;
8+
use PHPUnit\Framework\TestCase;
79

8-
class AdapterProcessorTest extends \PHPUnit_Framework_TestCase
10+
class AdapterProcessorTest extends TestCase
911
{
12+
use CustomAssertionsTrait;
13+
1014
/**
1115
* @dataProvider getInterfaceAndExpectedStrings
1216
*
@@ -20,7 +24,7 @@ public function testProcessGeneratesExpectedAdapterString($interfaceFqn, $expect
2024

2125
$processor = new AdapterProcessor($interfaceFqn, $namespace, $fileLocation);
2226

23-
\PHPUnit_Extensions_Assert_More::assertStringMatchIgnoreWhitespace($expectedAdapterString, $processor->process(true));
27+
self::assertStringMatchIgnoreWhitespace($expectedAdapterString, $processor->process(true));
2428
}
2529

2630
public function getInterfaceAndExpectedStrings()

tests/Processor/ClassProcessorTest.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
namespace Jenko\Sunscreen\Tests\Processor;
44

55
use Jenko\Sunscreen\Processor\ClassProcessor;
6+
use Jenko\Sunscreen\Tests\CustomAssertionsTrait;
67
use Jenko\Sunscreen\Util;
8+
use PHPUnit\Framework\TestCase;
79

8-
class ClassProcessorTest extends \PHPUnit_Framework_TestCase
10+
class ClassProcessorTest extends TestCase
911
{
12+
use CustomAssertionsTrait;
13+
1014
/**
1115
* @dataProvider getClassAndExpectedStrings
1216
*
@@ -20,7 +24,7 @@ public function testProcessGeneratesExpectedClassString($classFqn, $expectedClas
2024

2125
$processor = new ClassProcessor($classFqn, $namespace, $fileLocation);
2226

23-
\PHPUnit_Extensions_Assert_More::assertStringMatchIgnoreWhitespace(
27+
self::assertStringMatchIgnoreWhitespace(
2428
$expectedClassString,
2529
$processor->process(true)
2630
);

tests/Processor/InterfaceMethodsProcessorTest.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
namespace Jenko\Sunscreen\Tests\Processor;
44

55
use Jenko\Sunscreen\Processor\InterfaceMethodsProcessor;
6+
use Jenko\Sunscreen\Tests\CustomAssertionsTrait;
7+
use PHPUnit\Framework\TestCase;
68

7-
class InterfaceMethodsProcessorTest extends \PHPUnit_Framework_TestCase
9+
class InterfaceMethodsProcessorTest extends TestCase
810
{
11+
use CustomAssertionsTrait;
12+
913
/**
1014
* @dataProvider getMethodsAndExpectedStrings
1115
* @param array $methods
@@ -15,7 +19,7 @@ public function testProcessGeneratesExpectedMethodsString($methods, $expectedMet
1519
{
1620
$processor = new InterfaceMethodsProcessor($methods);
1721

18-
\PHPUnit_Extensions_Assert_More::assertStringMatchIgnoreWhitespace(
22+
self::assertStringMatchIgnoreWhitespace(
1923
$expectedMethodsString,
2024
$processor->process(true)
2125
);

tests/Processor/InterfaceProcessorTest.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
namespace Jenko\Sunscreen\Tests\Processor;
44

55
use Jenko\Sunscreen\Processor\InterfaceProcessor;
6+
use Jenko\Sunscreen\Tests\CustomAssertionsTrait;
67
use Jenko\Sunscreen\Util;
8+
use PHPUnit\Framework\TestCase;
79

8-
class InterfaceProcessorTest extends \PHPUnit_Framework_TestCase
10+
class InterfaceProcessorTest extends TestCase
911
{
12+
use CustomAssertionsTrait;
13+
1014
/**
1115
* @dataProvider getInterfaceAndExpectedStrings
1216
*
@@ -20,7 +24,7 @@ public function testProcessGeneratesExpectedInterfaceString($interfaceFqn, $expe
2024

2125
$processor = new InterfaceProcessor($interfaceFqn, $namespace, $fileLocation);
2226

23-
\PHPUnit_Extensions_Assert_More::assertStringMatchIgnoreWhitespace(
27+
self::assertStringMatchIgnoreWhitespace(
2428
$expectedClassString,
2529
$processor->process(true)
2630
);

tests/UtilTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
use Composer\Package\Package;
66
use Jenko\Sunscreen\Util;
7+
use PHPUnit\Framework\TestCase;
78

8-
class UtilTest extends \PHPUnit_Framework_TestCase
9+
class UtilTest extends TestCase
910
{
1011
/**
1112
* @dataProvider getAutoloadsAndExpectedNamespaces
@@ -77,4 +78,4 @@ public function getInterfaceFqnAndExpectedClassName()
7778
['Jenko\Sunscreen\Tests\Fixtures\BazInterface', 'JenkoBaz']
7879
];
7980
}
80-
}
81+
}

0 commit comments

Comments
 (0)