Skip to content

Commit

Permalink
Merge pull request #28 from alleyinteractive/feature/pest-2-0
Browse files Browse the repository at this point in the history
Pest 2.0 Support
  • Loading branch information
srtfisher authored Dec 8, 2023
2 parents 70d43d8 + b97b746 commit 2957230
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 123 deletions.
37 changes: 9 additions & 28 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 4 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -36,7 +31,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -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
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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.
Expand All @@ -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
Expand Down
20 changes: 11 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -29,7 +28,7 @@
]
},
"require-dev": {
"pestphp/pest-dev-tools": "^1.0.0"
"pestphp/pest-dev-tools": "^2.9"
},
"extra": {
"branch-alias": {
Expand All @@ -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"
Expand Down
11 changes: 11 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -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
6 changes: 1 addition & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down
26 changes: 22 additions & 4 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/wordpress-autoload.php" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
backupGlobals="false"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
bootstrap="vendor/autoload.php"
cacheResult="false"
colors="true"
failOnRisky="true"
failOnWarning="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
>
<testsuites>
<testsuite name="default">
<directory suffix=".php">./tests</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
</source>
</phpunit>
27 changes: 27 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->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,
]);
};
2 changes: 1 addition & 1 deletion src/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

declare(strict_types=1);

require_once __DIR__ . '/Http.php';
require_once __DIR__.'/Http.php';
12 changes: 6 additions & 6 deletions src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Installation Command.
*/
class InstallCommand extends Command
final class InstallCommand extends Command
{
/**
* The console command name.
Expand All @@ -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
{
Expand All @@ -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.');
Expand Down
23 changes: 8 additions & 15 deletions src/Commands/MakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Installation Command.
*/
class MakeCommand extends Command
final class MakeCommand extends Command
{
/**
* The console command name.
Expand All @@ -31,24 +31,17 @@ class MakeCommand extends Command
*
* @var array<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");
Expand All @@ -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.");
}
Expand Down
Loading

0 comments on commit 2957230

Please sign in to comment.