diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 0b97d31..eb2596e 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -3,49 +3,30 @@ name: Static Analysis on: ['push', 'pull_request'] jobs: - cs: - runs-on: ubuntu-latest - - name: Code Style - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: 8.0 - tools: composer:v2 - coverage: none - - - name: Install Dependencies - run: composer update --no-interaction --no-progress --ansi - - - name: Run PHP-CS-Fixer - run: vendor/bin/php-cs-fixer fix -v --allow-risky=yes --dry-run --ansi + static: + name: Static Tests - phpstan: runs-on: ubuntu-latest strategy: matrix: dependency-version: [prefer-lowest, prefer-stable] - name: PHPStan ${{ matrix.dependency-version }} - steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v2 - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.0 + php-version: 8.1 tools: composer:v2 coverage: none - name: Install Dependencies run: composer update --prefer-stable --no-interaction --no-progress --ansi - - name: Run PHPStan - run: vendor/bin/phpstan analyse --no-progress --ansi + - name: Types + run: composer test:types + + - name: Style + run: composer test:lint diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 59ea1fe..e7069bd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,15 +13,10 @@ jobs: ports: - 3306:3306 options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 - redis: - image: redis:5.0 - ports: - - 6379:6379 - options: --entrypoint redis-server strategy: matrix: - os: [ubuntu-latest] - php: ['8.0'] + os: [ubuntu-latest] # (macos-latest, windows-latest) 2.x-dev is under development + php: ['8.1', '8.2', '8.3'] dependency-version: [prefer-lowest, prefer-stable] wp_version: ["latest"] env: @@ -36,7 +31,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v2 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -54,5 +49,4 @@ jobs: run: composer update --${{ matrix.dependency-version }} --no-interaction --no-progress --ansi - name: Unit Tests - shell: bash - run: ./vendor/bin/pest --colors=always + run: composer test:unit diff --git a/CHANGELOG.md b/CHANGELOG.md index 83a0bad..ddd7b12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). -## 0.3.0 +## v0.4.0 + +- Upgraded to Pest 2.0. +- Removed `FrameworkTestCase` in favor of using `Mantle\Testkit\Test_Case` directly. + +## v0.3.0 - Switching to Mantle Testkit -## 0.2.0 +## v0.2.0 - Bump for Mantle dependencies and autoloading. diff --git a/README.md b/README.md index 690ef17..49bf4c2 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ Open up the `tests/Pest.php` file in your project the above command created for Replace that with the following: ```php -uses(\Pest\PestPluginWordPress\FrameworkTestCase::class)->in(__DIR__); +uses(\Mantle\Testkit\Test_Case::class)->in(__DIR__); // Install WordPress via Mantle. \Mantle\Testing\install(); @@ -93,7 +93,7 @@ You can now use the [Mantle Testing Framework](https://mantle.alley.co/testing/test-framework/) with Pest to test your WordPress plugin with ease and simplicity. Your IDE will be able to type-hint you as well to allow you to use the testing framework. -# Using With the Mantle Framework +# Using with the Mantle Framework Requiring the WordPress Pest Plugin on an existing Mantle project will allow you to install Pest with a few commands. @@ -106,7 +106,7 @@ composer require alleyinteractive/pest-plugin-wordpress --dev wp mantle pest:install ``` -That's it! Pest is installed successfully on you Mantle project. You can run +That's it! Pest is installed successfully on your Mantle project. You can run your pest tests through Pest now: ```bash diff --git a/composer.json b/composer.json index 1405fdd..2a2928b 100644 --- a/composer.json +++ b/composer.json @@ -13,12 +13,11 @@ ], "license": "MIT", "require": { - "php": "^8.0", - "alleyinteractive/composer-wordpress-autoloader": "^1.0", - "mantle-framework/testkit": "^0.12", - "pestphp/pest-plugin": "^1.1.0", - "pestphp/pest": "^1.22.1", - "symfony/var-dumper": "6.0.11 as 6.1.3" + "php": "^8.1", + "mantle-framework/testkit": "^1.0", + "pestphp/pest-plugin": "^2.0.1", + "pestphp/pest": "^2.5", + "symfony/var-dumper": "^6.4" }, "autoload": { "psr-4": { @@ -29,7 +28,7 @@ ] }, "require-dev": { - "pestphp/pest-dev-tools": "^1.0.0" + "pestphp/pest-dev-tools": "^2.9" }, "extra": { "branch-alias": { @@ -54,11 +53,14 @@ } }, "scripts": { - "lint": "php-cs-fixer fix -v", - "test:lint": "php-cs-fixer fix -v --dry-run", + "refacto": "rector", + "lint": "pint", + "test:refacto": "rector --dry-run", + "test:lint": "pint --test", "test:types": "phpstan analyse --ansi", "test:unit": "pest --colors=always", "test": [ + "@test:refacto", "@test:lint", "@test:types", "@test:unit" diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..78dc6d9 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,11 @@ +parameters: + ignoreErrors: + - + message: "#^Call to an undefined method Pest\\\\PendingCalls\\\\TestCall\\|Pest\\\\Support\\\\HigherOrderTapProxy\\:\\:get\\(\\)\\.$#" + count: 1 + path: src/Http.php + + - + message: "#^Call to an undefined method Pest\\\\PendingCalls\\\\TestCall\\|Pest\\\\Support\\\\HigherOrderTapProxy\\:\\:with_header\\(\\)\\.$#" + count: 2 + path: src/Http.php diff --git a/phpstan.neon b/phpstan.neon index 0678d28..a7dfcfe 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,4 +1,5 @@ includes: + - phpstan-baseline.neon - vendor/phpstan/phpstan-strict-rules/rules.neon - vendor/ergebnis/phpstan-rules/rules.neon - vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon @@ -8,17 +9,12 @@ parameters: paths: - src - bootstrapFiles: - - vendor/wordpress-autoload.php - checkMissingIterableValueType: true checkGenericClassInNonGenericObjectType: false reportUnmatchedIgnoredErrors: true ignoreErrors: - "#is not allowed to extend#" - - "#is neither abstract nor final#" - - "#on mixed#" excludePaths: analyseAndScan: diff --git a/phpunit.xml b/phpunit.xml index 67e29cb..c9fd75e 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,16 +1,34 @@ - ./tests - + ./src - + diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..589b8cd --- /dev/null +++ b/rector.php @@ -0,0 +1,27 @@ +paths([ + __DIR__.'/src', + ]); + + $rectorConfig->rules([ + InlineConstructorDefaultToPropertyRector::class, + ]); + + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_81, + SetList::CODE_QUALITY, + SetList::DEAD_CODE, + SetList::EARLY_RETURN, + SetList::TYPE_DECLARATION, + SetList::PRIVATIZATION, + ]); +}; diff --git a/src/Autoload.php b/src/Autoload.php index 9eda447..d3f560a 100644 --- a/src/Autoload.php +++ b/src/Autoload.php @@ -2,4 +2,4 @@ declare(strict_types=1); -require_once __DIR__ . '/Http.php'; +require_once __DIR__.'/Http.php'; diff --git a/src/Commands/InstallCommand.php b/src/Commands/InstallCommand.php index f577364..8bd307e 100644 --- a/src/Commands/InstallCommand.php +++ b/src/Commands/InstallCommand.php @@ -10,7 +10,7 @@ /** * Installation Command. */ -class InstallCommand extends Command +final class InstallCommand extends Command { /** * The console command name. @@ -29,8 +29,8 @@ class InstallCommand extends Command /** * Callback for the command. * - * @param array $args command Arguments - * @param array $assoc_args command flags + * @param array $args command Arguments + * @param array $assoc_args command flags */ public function handle(array $args, array $assoc_args = []): void { @@ -43,13 +43,13 @@ public function handle(array $args, array $assoc_args = []): void $this->error(sprintf('%s already exists', $pestFile), true); } - $files->copy(__DIR__ . '/../stubs/Pest.php', $pestFile); + $files->copy(__DIR__.'/../stubs/Pest.php', $pestFile); // Copy an example test. $exampleTestFile = base_path('tests/feature/test-example-pest.php'); - if (!$files->exists($exampleTestFile)) { - $files->copy(__DIR__ . '/../stubs/ExampleTest.php', $exampleTestFile); + if (! $files->exists($exampleTestFile)) { + $files->copy(__DIR__.'/../stubs/ExampleTest.php', $exampleTestFile); } $this->log('Pest installed successfully.'); diff --git a/src/Commands/MakeCommand.php b/src/Commands/MakeCommand.php index ff92709..6f441ed 100644 --- a/src/Commands/MakeCommand.php +++ b/src/Commands/MakeCommand.php @@ -10,7 +10,7 @@ /** * Installation Command. */ -class MakeCommand extends Command +final class MakeCommand extends Command { /** * The console command name. @@ -31,24 +31,17 @@ class MakeCommand extends Command * * @var array */ - protected $synopsis = [ - [ - 'description' => 'Test name', - 'name' => 'name', - 'optional' => false, - 'type' => 'positional', - ], - ]; + protected $signature = '{name}'; /** * Callback for the command. * - * @param array $args command Arguments - * @param array $assoc_args command flags + * @param array $args command Arguments + * @param array $assoc_args command flags */ public function handle(array $args, array $assoc_args = []): void { - $name = $this->argument('name'); + $name = $this->argument('name'); $files = new Filesystem(); $pestFile = base_path("tests/{$name}.php"); @@ -58,11 +51,11 @@ public function handle(array $args, array $assoc_args = []): void } // Ensure the directory exists. - if (!$files->is_directory(dirname($pestFile))) { - $files->make_directory(dirname($pestFile), 0777, true); + if (! $files->is_directory(dirname((string) $pestFile))) { + $files->make_directory(dirname((string) $pestFile), 0777, true); } - $files->copy(__DIR__ . '/../stubs/ExampleTest.php', $pestFile); + $files->copy(__DIR__.'/../stubs/ExampleTest.php', $pestFile); $this->log("{$pestFile} test generated."); } diff --git a/src/FrameworkTestCase.php b/src/FrameworkTestCase.php deleted file mode 100644 index 90d4ef0..0000000 --- a/src/FrameworkTestCase.php +++ /dev/null @@ -1,18 +0,0 @@ - $headers request Headers to load + * @param mixed $uri request URI + * @param array $headers request Headers to load */ -function get($uri, array $headers = []): Test_Response +function get(mixed $uri, array $headers = []): Test_Response { return test()->get($uri, $headers); } diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 9b822fa..1675d0a 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -7,7 +7,7 @@ /** * Mantle Service Provider to register commands. */ -class ServiceProvider extends \Mantle\Support\Service_Provider +final class ServiceProvider extends \Mantle\Support\Service_Provider { public function register(): void { diff --git a/src/stubs/ExampleTest.php b/src/stubs/ExampleTest.php index 24875d8..1ea2a4e 100644 --- a/src/stubs/ExampleTest.php +++ b/src/stubs/ExampleTest.php @@ -2,10 +2,10 @@ use function Pest\PestPluginWordPress\get; -test( 'example', function () { +test('example', function (): void { expect(true)->toBeTrue(); -} ); +}); -test( 'make a request', function () { +test('make a request', function (): void { get('/')->assertOk(); -} ); +}); diff --git a/src/stubs/Pest.php b/src/stubs/Pest.php index 659bddf..2fd8f19 100644 --- a/src/stubs/Pest.php +++ b/src/stubs/Pest.php @@ -1,7 +1,6 @@ in(__DIR__); +uses(\App\Tests\TestCase::class, Refresh_Database::class)->in(__DIR__); // Install WordPress via Mantle. \Mantle\Testing\install(); @@ -30,9 +29,7 @@ | */ -expect()->extend('toBeOne', function () { - return $this->toBe(1); -}); +expect()->extend('toBeOne', fn () => $this->toBe(1)); /* |-------------------------------------------------------------------------- @@ -45,7 +42,7 @@ | */ -function something() +function something(): void { // .. } diff --git a/tests/Pest.php b/tests/Pest.php index 945db4e..cf1fd6d 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -4,10 +4,9 @@ */ use Mantle\Testing\Concerns\Refresh_Database; -use Pest\PestPluginWordPress\FrameworkTestCase; // Use the given test case for all tests in the plugin. -uses(FrameworkTestCase::class, Refresh_Database::class)->in(__DIR__); +uses(\Mantle\Testkit\Test_Case::class, Refresh_Database::class)->in(__DIR__); // Install WordPress via Mantle. -\Mantle\Testing\install(); +\Mantle\Testing\manager()->with_sqlite()->install();