Skip to content

Commit

Permalink
[1.1] Adding support for PHPUnit 11 (#557)
Browse files Browse the repository at this point in the history
* Adding support for PHPUnit 12

* CHANGELOG

* Adding phpunit 11 support to testkit
  • Loading branch information
srtfisher committed Jun 7, 2024
1 parent 9859dfb commit c85ff59
Show file tree
Hide file tree
Showing 29 changed files with 322 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added a `classname`/`the_classname` helper to generate complex class names.
- Added support for installing the Redis `object-cache.php` drop-in during
testing with `with_object_cache()`.
- Added support for PHPUnit 11.

## Fixed

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"phpstan/extension-installer": "^1.3",
"phpstan/phpdoc-parser": "^1.23.1",
"phpstan/phpstan": "1.10.67",
"phpunit/phpunit": "^9.3.3 || ^10.0.7",
"phpunit/phpunit": "^9.3.3 || ^10.0.7 || ^11.0",
"predis/predis": "^2.2.0",
"rector/rector": "^1.0",
"squizlabs/php_codesniffer": "^3.7",
Expand Down
2 changes: 1 addition & 1 deletion monorepo-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
],
ComposerJsonSection::REQUIRE_DEV => [
'alleyinteractive/alley-coding-standards' => '^1.0',
'phpunit/phpunit' => '^9.3.3|^10.0.7',
'phpunit/phpunit' => '^9.3.3 || ^10.0.7 || ^11.0',
],
],
);
Expand Down
2 changes: 1 addition & 1 deletion src/mantle/testkit/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"mantle-framework/support": "^1.0",
"mantle-framework/testing": "^1.0",
"nunomaduro/collision": "^6.0 || ^7.0",
"phpunit/phpunit": "^9.3.3|^10.0.7",
"phpunit/phpunit": "^9.3.3 || ^10.0.7 || ^11.0",
"symfony/http-foundation": "^6.0"
},
"extra": {
Expand Down
2 changes: 2 additions & 0 deletions tests/Assets/AssetManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
namespace Mantle\Tests\Assets;

use Mantle\Assets\Asset_Manager;
use PHPUnit\Framework\Attributes\Group;

/**
* @group assets
*/
#[Group( 'assets' )]
class AssetManagerTest extends TestCase {
public function test_register_script() {
$manager = new Asset_Manager();
Expand Down
5 changes: 5 additions & 0 deletions tests/Database/Factory/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
use Mantle\Database\Factory\Post_Factory;
use Mantle\Database\Model;
use Mantle\Testing\Framework_Test_Case;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;

/**
* @group factory
*/
#[Group( 'factory' )]
class FactoryTest extends Framework_Test_Case {
public function test_create_basic_model() {
$factory = Testable_Post::factory();
Expand Down Expand Up @@ -43,6 +46,7 @@ public function test_create_model_with_scope() {
/**
* @dataProvider factory_resolve_custom_names
*/
#[DataProvider( 'factory_resolve_custom_names' )]
public function test_resolve_custom_names( string $model, string $expected ) {
$this->assertEquals( $expected, Factory\Factory::resolve_custom_factory_name( $model ) );
}
Expand All @@ -59,6 +63,7 @@ public static function factory_resolve_custom_names(): array {
/**
* @dataProvider factory_resolve_default
*/
#[DataProvider( 'factory_resolve_default' )]
public function test_resolve_default( string $model, string $expected ) {
$this->assertEquals( $expected, Factory\Factory::default_factory_name( $model ) );
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Database/Factory/UnitTestingFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Mantle\Database\Model\Term;
use Mantle\Testing\Concerns\With_Faker;
use Mantle\Testing\Framework_Test_Case;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;

use function Mantle\Support\Helpers\collect;

Expand All @@ -17,6 +19,7 @@
*
* @group factory
*/
#[Group( 'factory' )]
class UnitTestingFactoryTest extends Framework_Test_Case {
use With_Faker;

Expand Down Expand Up @@ -287,6 +290,7 @@ protected function shim_test( string $class_name, string $property ) {
/**
* @dataProvider dataprovider_factory
*/
#[DataProvider( 'dataprovider_factory' )]
public function test_dataprovider_factory( $post ) {
$this->assertInstanceOf( \WP_Post::class, $post );
$this->assertStringContainsString(
Expand Down
2 changes: 2 additions & 0 deletions tests/Database/Query/PostQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Mantle\Testing\Concerns\Refresh_Database;
use Mantle\Testing\Framework_Test_Case;
use Mantle\Testing\Utils;
use PHPUnit\Framework\Attributes\DataProvider;

use function Mantle\Support\Helpers\collect;

Expand Down Expand Up @@ -644,6 +645,7 @@ public function test_post_by_modified_date() {
/**
* @dataProvider date_comparison_provider
*/
#[DataProvider( 'date_comparison_provider' )]
public function test_date_comparisons( int $expected, string $method, array $args ) {
$start = Carbon::now( wp_timezone() )->subMonth()->startOfDay();

Expand Down
2 changes: 2 additions & 0 deletions tests/Events/EventDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
use Mantle\Events\Dispatcher;
use Mantle\Container\Container;
use Mockery as m;
use PHPUnit\Framework\Attributes\Group;

/**
* @group events
*/
#[Group( 'events' )]
class EventDispatcherTest extends \Mockery\Adapter\Phpunit\MockeryTestCase {
public function setUp(): void {
parent::setUp();
Expand Down
2 changes: 2 additions & 0 deletions tests/Events/WordPressActionDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Mantle\Events\Dispatcher;
use Mantle\Support\Collection;
use Mantle\Testing\Framework_Test_Case;
use PHPUnit\Framework\Attributes\Group;

use function Mantle\Support\Helpers\add_action;
use function Mantle\Support\Helpers\add_filter;
Expand All @@ -12,6 +13,7 @@
/**
* @group events
*/
#[Group( 'events' )]
class WordPressActionDispatcherTest extends Framework_Test_Case {
public function test_action_handler() {
$_SERVER['__action_fired'] = false;
Expand Down
6 changes: 6 additions & 0 deletions tests/Filesystem/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use Mantle\Filesystem\Filesystem;
use Mantle\Testing\Assert;
use Mockery as m;
use PHPUnit\Framework\Attributes\AfterClass;
use PHPUnit\Framework\Attributes\BeforeClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use PHPUnit\Framework\TestCase;
use SplFileInfo;

Expand All @@ -16,6 +19,7 @@ class FilesystemTest extends TestCase {
/**
* @beforeClass
*/
#[BeforeClass]
public static function setUptemp_dir() {
static::$temp_dir = get_temp_dir() . '/mantle-fs';

Expand All @@ -27,6 +31,7 @@ public static function setUptemp_dir() {
/**
* @afterClass
*/
#[AfterClass]
public static function tearDowntemp_dir() {
$files = new Filesystem();
$files->delete_directory( static::$temp_dir );
Expand Down Expand Up @@ -352,6 +357,7 @@ public function testSizeOutputsSize() {
/**
* @requires extension fileinfo
*/
#[RequiresPhpExtension( 'fileinfo' )]
public function testMimeTypeOutputsMimeType() {
file_put_contents( static::$temp_dir . '/foo.txt', 'foo' );
$files = new Filesystem();
Expand Down
2 changes: 2 additions & 0 deletions tests/Helpers/HelpersGeneralTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Mantle\Tests\Helpers;

use Mockery as m;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use RuntimeException;
use stdClass;
Expand Down Expand Up @@ -202,6 +203,7 @@ public static function providesPregReplaceArrayData() {
}

/** @dataProvider providesPregReplaceArrayData */
#[DataProvider( 'providesPregReplaceArrayData' )]
public function testPregReplaceArray( $pattern, $replacements, $subject, $expectedOutput ) {
$this->assertSame(
$expectedOutput,
Expand Down
2 changes: 2 additions & 0 deletions tests/Http/UrlGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Mantle\Http\Routing\Router;
use Mantle\Http\Routing\Url_Generator;
use Mantle\Testing\Framework_Test_Case;
use PHPUnit\Framework\Attributes\DataProvider;

class UrlGeneratorTest extends Framework_Test_Case {
protected Router $router;
Expand Down Expand Up @@ -39,6 +40,7 @@ public function test_home_url_check() {
/**
* @dataProvider urlGenerationProvider
*/
#[DataProvider( 'urlGenerationProvider' )]
public function test_basic_generation( $expected, $args ) {
$this->assertEquals( home_url( $expected ), $this->url->to( ...$args ) );
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Queue/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
use Mantle\Queue\Dispatcher;
use Mantle\Queue\Queue_Manager;
use Mockery as m;
use PHPUnit\Framework\Attributes\Group;

/**
* @group queue
*/
#[Group( 'queue' )]
class DispatcherTest extends \Mockery\Adapter\Phpunit\MockeryTestCase {
/**
* Provider instance.
Expand Down
2 changes: 2 additions & 0 deletions tests/Queue/QueueManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
use Mantle\Contracts\Queue\Provider;
use Mantle\Queue\Queue_Manager;
use Mockery as m;
use PHPUnit\Framework\Attributes\Group;

/**
* @group queue
*/
#[Group( 'queue' )]
class QueueManagerTest extends \Mockery\Adapter\Phpunit\MockeryTestCase {
public function test_default_connection() {
$provider = m::mock( Provider::class );
Expand Down
2 changes: 2 additions & 0 deletions tests/Queue/WorkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
use Mantle\Support\Collection;
use Mockery as m;
use Mockery\Adapter\Phpunit\MockeryTestCase;
use PHPUnit\Framework\Attributes\Group;

use function Mantle\Support\Helpers\collect;

/**
* @group queue
*/
#[Group( 'queue' )]
class WorkerTest extends MockeryTestCase {

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/Queue/providers/WordPressCronQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Mantle\Testing\Concerns\Refresh_Database;
use Mantle\Testing\Framework_Test_Case;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\Attributes\Group;
use RuntimeException;

use function Mantle\Queue\dispatch;
Expand All @@ -25,6 +26,8 @@
* @group queue
* @group wordpress-queue
*/
#[Group( 'queue' )]
#[Group( 'wordpress-queue' )]
class WordPressCronQueueTest extends Framework_Test_Case {
use Refresh_Database;

Expand Down
Loading

0 comments on commit c85ff59

Please sign in to comment.