Skip to content

Commit

Permalink
PHPUnit 10 (#927)
Browse files Browse the repository at this point in the history
* Static PHPUnit dataProviders
* Add expectExceptionMessage instead of expectErrorMessage
* Add addMethods instead of setMethods
* Fix tests with required name in the constructor
* Remove ok function
* Remove usage PHPUnit Error
* Fix EventsTest
* Replace withConsecutive with willReturnCallback
* Migrate phpunit config
* Add coverage config
* Fix issue with abstract classes
* Update PHP version in scrutinizer; add test groups to exclude some tests from scrutinizer testing
* Replace `group` annotations with attributes

---------

Co-authored-by: roxblnfk <roxblnfk@ya.ru>
  • Loading branch information
msmakouz and roxblnfk committed Apr 25, 2023
1 parent 865ea9f commit f5a1ef4
Show file tree
Hide file tree
Showing 349 changed files with 1,140 additions and 1,434 deletions.
4 changes: 2 additions & 2 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ build:

environment:
php:
version: 8.1.2
version: 8.1.18
ini:
"xdebug.mode": coverage

Expand All @@ -24,7 +24,7 @@ build:
phpunit:
tests:
override:
- command: "./vendor/bin/phpunit --coverage-clover ./coverage.xml"
- command: "./vendor/bin/phpunit --exclude-group scrutinizer-ignore --coverage-clover ./coverage.xml"
on_node: 1
coverage:
file: coverage.xml
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<p align="center">
<a href="https://packagist.org/packages/spiral/framework"><img src="https://poser.pugx.org/spiral/framework/require/php"></a>
<a href="https://packagist.org/packages/spiral/framework"><img src="https://poser.pugx.org/spiral/framework/version"></a>
Expand Down Expand Up @@ -69,6 +68,6 @@ the PHP code of your application stays in memory permanently (anti-memory leak t
> **Note**:
> You can find more community packages in [spiral-packages](https://github.com/spiral-packages/) organization.
License:
--------
## License:

MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information. Maintained by [Spiral Scout](https://spiralscout.com).
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@
"league/flysystem-aws-s3-v3": "^2.0",
"mikey179/vfsstream": "^1.6",
"mockery/mockery": "^1.5",
"phpunit/phpunit": "^9.5.20",
"phpunit/phpunit": "^10.1",
"ramsey/collection": "^1.2",
"ramsey/uuid": "^4.2.3",
"rector/rector": "0.15.23",
"spiral/code-style": "^1.1",
"spiral/nyholm-bridge": "^1.2",
"spiral/testing": "^2.2",
"spiral/testing": "^2.3",
"spiral/validator": "^1.2",
"symplify/monorepo-builder": "^10.2.7",
"vimeo/psalm": "^5.9"
Expand Down
2 changes: 1 addition & 1 deletion monorepo-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
],
],
'require-dev' => [
'phpunit/phpunit' => '^9.5.20',
'phpunit/phpunit' => '^10.1',
'mockery/mockery' => '^1.5',
'spiral/code-style' => '^1.1',
'symplify/monorepo-builder' => '^10.2.7',
Expand Down
38 changes: 22 additions & 16 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,27 @@
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
failOnRisky="false"
stopOnFailure="false"
stopOnError="false"
stderr="true">
stderr="true"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false">
<coverage>
<include>
<directory>src</directory>
<directory>src/*/src</directory>
</include>
<exclude>
<directory>src/*/tests</directory>
<directory>tests</directory>
</exclude>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<testsuites>
<testsuite name="Components Test Suite">
<directory>src/*/tests</directory>
<directory suffix="TestCase.php">src/*/tests</directory>
<directory suffix="Test.php">src/*/tests</directory>
</testsuite>
<testsuite name="Framework Test Suite">
<directory>tests</directory>
Expand All @@ -37,4 +33,14 @@
<ini name="error_reporting" value="-1"/>
<ini name="memory_limit" value="-1"/>
</php>
<source>
<include>
<directory>src</directory>
<directory>src/*/src</directory>
</include>
<exclude>
<directory>src/*/tests</directory>
<directory>tests</directory>
</exclude>
</source>
</phpunit>
2 changes: 1 addition & 1 deletion src/AnnotatedRoutes/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"require-dev": {
"mockery/mockery": "^1.5",
"phpunit/phpunit": "^9.5.20",
"phpunit/phpunit": "^10.1",
"spiral/framework": "^3.1",
"spiral/nyholm-bridge": "^1.2",
"vimeo/psalm": "^5.9"
Expand Down
2 changes: 1 addition & 1 deletion src/Auth/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"psr/event-dispatcher": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5.20",
"phpunit/phpunit": "^10.1",
"vimeo/psalm": "^5.9"
},
"autoload": {
Expand Down
2 changes: 1 addition & 1 deletion src/AuthHttp/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"psr/event-dispatcher": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5.20",
"phpunit/phpunit": "^10.1",
"spiral/cookies": "^3.8",
"spiral/http": "^3.8",
"spiral/debug": "^3.8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Spiral\Telemetry\NullTracer;
use Spiral\Telemetry\TracerInterface;

abstract class BaseTest extends TestCase
abstract class BaseTestCase extends TestCase
{
protected Container $container;

Expand Down
2 changes: 1 addition & 1 deletion src/AuthHttp/tests/CookieTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Spiral\Tests\Auth\Stub\TestAuthHttpStorage;
use Spiral\Tests\Auth\Stub\TestAuthHttpToken;

class CookieTransportTest extends BaseTest
class CookieTransportTest extends BaseTestCase
{
public function testCookieToken(): void
{
Expand Down
4 changes: 2 additions & 2 deletions src/AuthHttp/tests/Middleware/AuthMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
use Spiral\Http\Config\HttpConfig;
use Spiral\Http\Http;
use Spiral\Http\Pipeline;
use Spiral\Tests\Auth\BaseTest;
use Spiral\Tests\Auth\BaseTestCase;
use Spiral\Tests\Auth\Diactoros\ResponseFactory;
use Nyholm\Psr7\ServerRequest;
use Spiral\Tests\Auth\Stub\TestAuthHttpProvider;
use Spiral\Tests\Auth\Stub\TestAuthHttpStorage;

class AuthMiddlewareTest extends BaseTest
class AuthMiddlewareTest extends BaseTestCase
{
public function testAttributeRead(): void
{
Expand Down
4 changes: 2 additions & 2 deletions src/AuthHttp/tests/Middleware/AuthTransportMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
use Spiral\Auth\TransportRegistry;
use Spiral\Core\Container\Autowire;
use Spiral\Core\ScopeInterface;
use Spiral\Tests\Auth\BaseTest;
use Spiral\Tests\Auth\BaseTestCase;
use Spiral\Tests\Auth\Stub\TestAuthHttpProvider;
use Spiral\Tests\Auth\Stub\TestAuthHttpStorage;

final class AuthTransportMiddlewareTest extends BaseTest
final class AuthTransportMiddlewareTest extends BaseTestCase
{
protected function setUp(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
use Spiral\Http\Config\HttpConfig;
use Spiral\Http\Http;
use Spiral\Http\Pipeline;
use Spiral\Tests\Auth\BaseTest;
use Spiral\Tests\Auth\BaseTestCase;
use Spiral\Tests\Auth\Diactoros\ResponseFactory;
use Spiral\Tests\Auth\Stub\TestAuthHttpProvider;
use Spiral\Tests\Auth\Stub\TestAuthHttpStorage;

abstract class BaseFirewallTest extends BaseTest
abstract class BaseFirewallTestCase extends BaseTestCase
{
protected function getCore(AbstractFirewall $firewall, HttpTransportInterface $transport): Http
{
Expand Down Expand Up @@ -50,13 +50,13 @@ protected function getCore(AbstractFirewall $firewall, HttpTransportInterface $t
return $http;
}

public function successTokensDataProvider(): \Traversable
public static function successTokensDataProvider(): \Traversable
{
// ok
yield ['ok'];
}

public function failTokensDataProvider(): \Traversable
public static function failTokensDataProvider(): \Traversable
{
// Actor not found
yield ['no-actor'];
Expand Down
11 changes: 4 additions & 7 deletions src/AuthHttp/tests/Middleware/Firewall/ExceptionFirewallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
namespace Spiral\Tests\Auth\Middleware\Firewall;

use Nyholm\Psr7\ServerRequest;
use PHPUnit\Framework\Attributes\DataProvider;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Spiral\Auth\Exception\AuthException;
use Spiral\Auth\Middleware\Firewall\ExceptionFirewall;
use Spiral\Auth\Transport\HeaderTransport;

final class ExceptionFirewallTest extends BaseFirewallTest
final class ExceptionFirewallTest extends BaseFirewallTestCase
{
/**
* @dataProvider successTokensDataProvider
*/
#[DataProvider('successTokensDataProvider')]
public function testExceptionFirewallNotThrowException(string $token): void
{
$http = $this->getCore(
Expand All @@ -35,9 +34,7 @@ static function (ServerRequestInterface $request, ResponseInterface $response):
$this->assertSame('OK', (string) $response->getBody());
}

/**
* @dataProvider failTokensDataProvider
*/
#[DataProvider('failTokensDataProvider')]
public function testExceptionFirewallThrowException(string $token): void
{
$http = $this->getCore(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@

use Nyholm\Psr7\ServerRequest;
use Nyholm\Psr7\Uri;
use PHPUnit\Framework\Attributes\DataProvider;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Spiral\Auth\Middleware\Firewall\OverwriteFirewall;
use Spiral\Auth\Transport\HeaderTransport;

final class OverwriteFirewallTest extends BaseFirewallTest
final class OverwriteFirewallTest extends BaseFirewallTestCase
{
/**
* @dataProvider successTokensDataProvider
* @dataProvider failTokensDataProvider
*/
#[DataProvider('successTokensDataProvider')]
#[DataProvider('failTokensDataProvider')]
public function testOverwriteFirewall(string $token): void
{
$http = $this->getCore(
Expand Down
15 changes: 5 additions & 10 deletions src/AuthHttp/tests/Middleware/Firewall/RedirectFirewallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
use Nyholm\Psr7\Factory\Psr17Factory;
use Nyholm\Psr7\ServerRequest;
use Nyholm\Psr7\Uri;
use PHPUnit\Framework\Attributes\DataProvider;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Spiral\Auth\Middleware\Firewall\RedirectFirewall;
use Spiral\Auth\Transport\HeaderTransport;

final class RedirectFirewallTest extends BaseFirewallTest
final class RedirectFirewallTest extends BaseFirewallTestCase
{
/**
* @dataProvider successTokensDataProvider
*/
#[DataProvider('successTokensDataProvider')]
public function testRedirectFirewallWithoutRedirect(string $token): void
{
$http = $this->getCore(
Expand All @@ -38,9 +37,7 @@ static function (ServerRequestInterface $request, ResponseInterface $response):
$this->assertSame('success login', (string)$response->getBody());
}

/**
* @dataProvider failTokensDataProvider
*/
#[DataProvider('failTokensDataProvider')]
public function testRedirectFirewallWithRedirect(string $token): void
{
$http = $this->getCore(
Expand All @@ -63,9 +60,7 @@ static function (ServerRequestInterface $request, ResponseInterface $response):
$this->assertSame('', (string) $response->getBody());
}

/**
* @dataProvider failTokensDataProvider
*/
#[DataProvider('failTokensDataProvider')]
public function testRedirectFirewallWithRedirectAndCode(string $token): void
{
$http = $this->getCore(
Expand Down
2 changes: 1 addition & 1 deletion src/AuthHttp/tests/TransportRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Spiral\Auth\Transport\CookieTransport;
use Spiral\Auth\TransportRegistry;

class TransportRegistryTest extends BaseTest
class TransportRegistryTest extends BaseTestCase
{
public function testGetTransports(): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Boot/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"spiral/events": "^3.8"
},
"require-dev": {
"phpunit/phpunit": "^9.5.20",
"phpunit/phpunit": "^10.1",
"mockery/mockery": "^1.5",
"vimeo/psalm": "^5.9"
},
Expand Down
2 changes: 1 addition & 1 deletion src/Boot/tests/BootloadManager/BootloadersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function boot(BinderInterface $binder): void
public function testException(): void
{
$this->expectException(\Spiral\Boot\Exception\ClassNotFoundException::class);
$this->expectErrorMessage('Bootloader class `Foo\Bar\Invalid` is not exist.');
$this->expectExceptionMessage('Bootloader class `Foo\Bar\Invalid` is not exist.');

$bootloader = $this->getBootloadManager();
$bootloader->bootload(['Foo\Bar\Invalid']);
Expand Down
17 changes: 8 additions & 9 deletions src/Boot/tests/Environment/AppEnvironmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Spiral\Tests\Boot\Environment;

use Mockery as m;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Spiral\Boot\Environment\AppEnvironment;
use Spiral\Boot\EnvironmentInterface;
Expand All @@ -22,7 +23,7 @@ public function testDetectWithoutEnvironmentVariable(): void
$this->assertSame(AppEnvironment::Local, $enum);
}

/** @dataProvider envVariablesDataProvider */
#[DataProvider('envVariablesDataProvider')]
public function testDetectWithWrongEnvironmentVariable($name, AppEnvironment $expected): void
{
$env = m::mock(EnvironmentInterface::class);
Expand All @@ -34,15 +35,13 @@ public function testDetectWithWrongEnvironmentVariable($name, AppEnvironment $ex
$this->assertSame($expected, $enum);
}

public function envVariablesDataProvider()
public static function envVariablesDataProvider(): \Traversable
{
return [
['wrong', AppEnvironment::Local],
['prod', AppEnvironment::Production],
['stage', AppEnvironment::Stage],
['local', AppEnvironment::Local],
['testing', AppEnvironment::Testing]
];
yield ['wrong', AppEnvironment::Local];
yield ['prod', AppEnvironment::Production];
yield ['stage', AppEnvironment::Stage];
yield ['local', AppEnvironment::Local];
yield ['testing', AppEnvironment::Testing];
}

public function testClassMethods(): void
Expand Down
Loading

0 comments on commit f5a1ef4

Please sign in to comment.