Skip to content

Commit

Permalink
Upgrade to Laravel 10/11 + PHPUnit 10/11
Browse files Browse the repository at this point in the history
  • Loading branch information
pionl committed Apr 7, 2024
1 parent 0a40995 commit 3304f25
Show file tree
Hide file tree
Showing 77 changed files with 435 additions and 343 deletions.
19 changes: 4 additions & 15 deletions .github/workflows/check-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
strategy:
matrix:
phpVersion: [ "8.1", "8.2", "8.3" ]
uses: wrk-flow/reusable-workflows/.github/workflows/php-check.yml@09ffc469f54061cac1e9cebab2c5896676852b5d
uses: wrk-flow/reusable-workflows/.github/workflows/php-check.yml@c6b6e93c92bb9a2be67e5f6f3c3ca8dcb3bec433
with:
composerRequireDev: "laravel/framework:^10"
phpVersion: "${{ matrix.phpVersion }}"
Expand All @@ -37,29 +37,18 @@ jobs:
strategy:
matrix:
phpVersion: [ "8.2", "8.3" ]
uses: wrk-flow/reusable-workflows/.github/workflows/php-check.yml@09ffc469f54061cac1e9cebab2c5896676852b5d
uses: wrk-flow/reusable-workflows/.github/workflows/php-check.yml@c6b6e93c92bb9a2be67e5f6f3c3ca8dcb3bec433
with:
composerRequireDev: "laravel/framework:^11"
phpVersion: "${{ matrix.phpVersion }}"
secrets: inherit

tests_l9:
name: "Tests - Laravel 9"
strategy:
matrix:
phpVersion: [ "8.1", "8.2", "8.3" ]
uses: wrk-flow/reusable-workflows/.github/workflows/php-tests.yml@09ffc469f54061cac1e9cebab2c5896676852b5d
with:
composerRequireDev: "laravel/framework:^9"
phpVersion: "${{ matrix.phpVersion }}"
secrets: inherit

tests_l10:
name: "Tests - Laravel 10"
strategy:
matrix:
phpVersion: [ "8.1", "8.2", "8.3" ]
uses: wrk-flow/reusable-workflows/.github/workflows/php-tests.yml@09ffc469f54061cac1e9cebab2c5896676852b5d
uses: wrk-flow/reusable-workflows/.github/workflows/php-tests.yml@c6b6e93c92bb9a2be67e5f6f3c3ca8dcb3bec433
with:
composerRequireDev: "laravel/framework:^10"
phpVersion: "${{ matrix.phpVersion }}"
Expand All @@ -70,7 +59,7 @@ jobs:
strategy:
matrix:
phpVersion: [ "8.2", "8.3" ]
uses: wrk-flow/reusable-workflows/.github/workflows/php-tests.yml@09ffc469f54061cac1e9cebab2c5896676852b5d
uses: wrk-flow/reusable-workflows/.github/workflows/php-tests.yml@c6b6e93c92bb9a2be67e5f6f3c3ca8dcb3bec433
with:
composerRequireDev: "laravel/framework:^11"
phpVersion: "${{ matrix.phpVersion }}"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/composer.lock
/vendor
.phpunit.result.cache
.phpunit.cache
/docs/.nuxt
/docs/dist
/docs/node_modules
Expand Down
8 changes: 8 additions & 0 deletions CONTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,11 @@ For MakeExpectationCommand we are using stubs. If you want to generate the stub
## Fixes

- `nikic/php-parser` - on `v4.13.0` enum with value named Array fails to be parsed, `v4.14.0` works

## Maintaining multiple Laravel versions

- When dropping support for Laravel version, find any `Remove when dropping support for Laravel x` notes and remove the code.
- When you want to support lower Laravel version (PHPStan), you can copy the typehints (etc) to our implementation. Add `@todo Remove when dropping support for Laravel` comment, or you can update phpstan `
ignoreErrors:` and add same comment.
- Current local installation always install the highest version of the package. If you want to test lower version run `composer update --prefer-lowest`

13 changes: 13 additions & 0 deletions UPGRADE_1x.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Upgrade to 1.x version

Due to the test bench package we have dropped Laravel 9 and PHPUnit 9.

You need to upgrade your test cases to the new version. Data providers are now static methods.

You can use [rector](https://getrector.com/blog/how-to-upgrade-to-phpunit-10-in-diffs) with additional manual changes
like this:

- replace `protected function generateData(): array` with `protected static function generateData(): arrayt`
- replace `public function data(): array` with `public static function data(): array`

Please check the code changes for detailed information.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"psr/simple-cache": "^3.0"
},
"require-dev": {
"larastrict/conventions": "v0.1.1",
"larastrict/conventions": "v1.0.0",
"mockery/mockery": "^1.6",
"nette/php-generator": "^v4.1.4",
"orchestra/testbench": "^v8.22.2 | ^v9.0.3",
Expand Down
3 changes: 2 additions & 1 deletion ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use LaraStrict\Conventions\ExtensionFiles;
use PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer;
use PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
Expand All @@ -11,7 +12,7 @@
->withRootFiles()
->withPaths([__DIR__ . '/src', __DIR__ . '/tests'])
->withSets([
__DIR__ . '/vendor/larastrict/conventions/extension-ecs.php'
ExtensionFiles::Ecs
])
->withSkip([
// We want to leave the relative constant path usage
Expand Down
53 changes: 20 additions & 33 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,35 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="DB_CONNECTION" value="testing"/>
<env name="APP_KEY" value="base64:2fl+Ktvkfl+Fuz4Qp/A75G2RTiWVA/ZoKZvp6fiiM10="/>
<env name="APP_URL" value="https://testing" />
</php>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="DB_CONNECTION" value="testing"/>
<env name="APP_KEY" value="base64:2fl+Ktvkfl+Fuz4Qp/A75G2RTiWVA/ZoKZvp6fiiM10="/>
<env name="APP_URL" value="https://testing"/>
</php>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
35 changes: 35 additions & 0 deletions phpunit.xml.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="DB_CONNECTION" value="testing"/>
<env name="APP_KEY" value="base64:2fl+Ktvkfl+Fuz4Qp/A75G2RTiWVA/ZoKZvp6fiiM10="/>
<env name="APP_URL" value="https://testing" />
</php>
</phpunit>
4 changes: 3 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

declare(strict_types=1);

use LaraStrict\Conventions\ExtensionFiles;
use Rector\CodingStyle\Rector\ArrowFunction\StaticArrowFunctionRector;
use Rector\Config\RectorConfig;
use Rector\PHPUnit\Set\PHPUnitSetList;

// SKIP laravel
$laravelClasses = [
Expand All @@ -13,7 +15,7 @@
];

return RectorConfig::configure()
->withSets([__DIR__.'/vendor/larastrict/conventions/extension-rector.php'])
->withSets([ExtensionFiles::Rector])
->withRootFiles()
->withPaths([__DIR__ . '/src', __DIR__ . '/tests'])
->withSkip([
Expand Down
1 change: 0 additions & 1 deletion src/Cache/Enums/CacheDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
enum CacheDriver: string
{
case Array = 'array';
case Apc = 'apc';
case File = 'file';
case Memcached = 'memcached';
case null = 'null';
Expand Down
4 changes: 4 additions & 0 deletions src/Testing/Actions/TestRunAppServiceProviderAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class TestRunAppServiceProviderAction implements RunAppServiceProviderPipesActio
{
public bool $executed = false;

/**
* @param non-empty-string $expectedServiceName
* @param non-empty-string $expectServiceRootDirToEndWith
*/
public function __construct(
public readonly array $expectedPipes,
public readonly string $expectedServiceName,
Expand Down
17 changes: 7 additions & 10 deletions src/Testing/Concerns/AssertExpectations.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,24 @@
use LaraStrict\Testing\Assert\AbstractExpectationCallsMap;
use LaraStrict\Testing\Entities\AssertExpectationEntity;
use LogicException;
use PHPUnit\Framework\Attributes\DataProvider;

trait AssertExpectations
{
abstract public function expectException(string $exception): void;

abstract public function expectExceptionMessage(string $message): void;

/**
* @dataProvider data
*/
#[DataProvider('data')]
public function testEmpty(AssertExpectationEntity $expectation): void
{
$this->assertBadCall($expectation->methodName);
$assert = $this->createEmptyAssert();
$assert = self::createEmptyAssert();

$this->callExpectation($expectation, $assert);
}

/**
* @dataProvider data
*/
#[DataProvider('data')]
public function testCallsWithSecondFails(AssertExpectationEntity $expectation): void
{
/** @var AbstractExpectationCallsMap $assert */
Expand All @@ -44,10 +41,10 @@ public function testCallsWithSecondFails(AssertExpectationEntity $expectation):
$this->callExpectation($expectation, $assert);
}

public function data(): array
public static function data(): array
{
$data = [];
foreach ($this->generateData() as $index => $test) {
foreach (self::generateData() as $index => $test) {
$data[$test->methodName . ' #' . $index] = [$test];
}

Expand All @@ -57,7 +54,7 @@ public function data(): array
/**
* @return array<AssertExpectationEntity>
*/
abstract protected function generateData(): array;
abstract static protected function generateData(): array;

abstract protected function createEmptyAssert(): AbstractExpectationCallsMap;

Expand Down
7 changes: 3 additions & 4 deletions src/Testing/Concerns/TestData.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace LaraStrict\Testing\Concerns;

use Closure;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* Create simple test case with data set and their assert closure TODO: deprecate
Expand All @@ -14,11 +15,9 @@ trait TestData
/**
* @return array<string|int, array{0: Closure(static):void}>
*/
abstract public function data(): array;
abstract static public function data(): array;

/**
* @dataProvider data
*/
#[DataProvider('data')]
public function test(Closure $assert): void
{
$assert($this);
Expand Down
5 changes: 5 additions & 0 deletions src/Testing/Laravel/Contracts/Auth/GuardAssert.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ public function hasUser()

/**
* Set the current user.
*
* @todo remove typehint (Remove when dropping support for Laravel 10)
* @return self
*/
public function setUser(Authenticatable $user)
{
Expand All @@ -151,5 +154,7 @@ public function setUser(Authenticatable $user)
if (is_callable($expectation->hook)) {
call_user_func($expectation->hook, $user, $expectation);
}

return $this;
}
}
43 changes: 43 additions & 0 deletions src/Testing/Laravel/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use Illuminate\Contracts\Filesystem\Cloud;
use Illuminate\Contracts\Filesystem\Filesystem as FilesystemContract;
use Illuminate\Http\File;
use Illuminate\Http\UploadedFile;

class Filesystem implements FilesystemContract, Cloud
{
Expand Down Expand Up @@ -125,4 +127,45 @@ public function url($path)
{
return 'http://localhost/' . $path;
}

/**
* @todo Remove when dropping support for Laravel 10
* Get the full path to the file that exists at the given relative path.
*
* @param string $path
*
* @return string
*/
public function path($path)
{
return $path;
}

/**
* @todo Remove when dropping support for Laravel 10
* Store the uploaded file on the disk.
*
* @param File|UploadedFile|string $path
* @param File|UploadedFile|string|array|null $file
*
* @return string|false
*/
public function putFile($path, $file = null, mixed $options = [])
{
return 'the-file';
}

/**
* @todo Remove when dropping support for Laravel 10
* Store the uploaded file on the disk with a given name.
*
* @param File|UploadedFile|string $path
* @param File|UploadedFile|string|array|null $file
* @param string|array|null $name
* @return string|false
*/
public function putFileAs($path, $file, $name = null, mixed $options = [])
{
return 'the-file';
}
}
Loading

0 comments on commit 3304f25

Please sign in to comment.