Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change to support PHPUnit 10 #473

Merged
merged 27 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6f56941
Changes to support PHPunit 10
srtfisher Nov 17, 2023
9c9b1a7
More changes
srtfisher Nov 17, 2023
5dabc55
More changes for 10 and WP 6.4
srtfisher Nov 17, 2023
5344085
Last changes for phpunit 10
srtfisher Nov 17, 2023
2c4cd48
Merge branch 'phpunit-10' into phpunit-10-changes
srtfisher Nov 17, 2023
f823f93
Bump asset manager
srtfisher Nov 17, 2023
7c7dc41
Require the wp autoloader
srtfisher Nov 17, 2023
ad565f6
Require once the test case
srtfisher Nov 17, 2023
b8b7f0a
Another adjust
srtfisher Nov 17, 2023
d2be9c6
Enable debug
srtfisher Nov 17, 2023
06103d5
Removing slash
srtfisher Nov 17, 2023
6506aa3
Attempt to include in parent autoload
srtfisher Nov 17, 2023
09b9fbb
Revert "Attempt to include in parent autoload"
srtfisher Nov 20, 2023
4b930f5
Adding slash
srtfisher Nov 20, 2023
221c29a
Switching to hotfix/composer-cache
srtfisher Nov 20, 2023
693cf2a
Switch back
srtfisher Nov 20, 2023
732bbe2
Adding debug for Mantle\Tests\Assets\TestCase
srtfisher Nov 20, 2023
5ad9c36
Debugging vendor/composer/autoload_psr4.php
srtfisher Nov 20, 2023
6faa102
Debug autoload_static.php
srtfisher Nov 20, 2023
6f191dc
Move to tests/Assets
srtfisher Nov 20, 2023
4a8bc75
Remove debug code
srtfisher Nov 20, 2023
e98b853
Move folders to PSR-4
srtfisher Nov 20, 2023
0e914c2
Fix fixtures
srtfisher Nov 20, 2023
0af848e
Removing blocks
srtfisher Nov 20, 2023
a2adb46
PHPstan fixes
srtfisher Nov 20, 2023
6716f29
Ensure the class is loaded
srtfisher Nov 20, 2023
3de3e77
Lock in 3.6.9
srtfisher Nov 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions bin/convert-psr4-dir.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Helper script to convert the tests/ folder to a PSR-4 folder structure.
*
* Moves tests/example/sub/File.php to tests/Example/Sub/FileTest.php. Only
* convert the sub-part of the path (ignore anything before and including
* tests/).
*
* phpcs:disable
*/

use Mantle\Support\Str;
use Symfony\Component\Finder\Finder;

use function Mantle\Support\Helpers\str;

require_once __DIR__ . '/../vendor/autoload.php';

$finder = ( new Finder() )
->in( realpath( __DIR__ . '/../tests' ) )
->directories()
->notPath( '#fixtures|__snapshots__|template-parts#' );

$base = Str::trailing_slash( realpath( __DIR__ . '/../tests/' ) );

foreach ( $finder as $dir ) {
$old_dir = $dir->getRealPath();

if ( ! is_dir( $old_dir ) ) {
continue;
}

$parts = str( $old_dir )->after( $base )->explode( '/' );

$parts = $parts->map(
fn ( string $part ) => str( $part )->studly()->value(),
);

$new_dir = $base . $parts->implode( '/' );

dump( "Moving {$old_dir} to {$new_dir}" );

shell_exec( "git mv {$old_dir} {$old_dir}-tmp" );
shell_exec( "git mv {$old_dir}-tmp {$new_dir}" );
}

echo "\nDONE!\n";

exit( 0 );
File renamed without changes.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"require": {
"php": "^8.0",
"alleyinteractive/composer-wordpress-autoloader": "^1.0",
"alleyinteractive/wp-asset-manager": "^1.3.3",
"alleyinteractive/wp-asset-manager": "^1.3.4",
"alleyinteractive/wp-caper": "^2.0.1",
"alleyinteractive/wp-concurrent-remote-requests": "^1.0.2",
"alleyinteractive/wp-filter-side-effects": "^2.0",
Expand All @@ -27,7 +27,7 @@
"league/flysystem-cached-adapter": "^1.1",
"monolog/monolog": "^2.9.1",
"nesbot/carbon": "^2.68.1",
"nette/php-generator": "^3.6",
"nette/php-generator": "^3.6.9",
"nunomaduro/collision": "^6.0 || ^7.0",
"nunomaduro/termwind": "^1.15.1",
"psr/container": "^1.1.1 || ^2.0.2",
Expand Down
3 changes: 1 addition & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
backupGlobals="false"
colors="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
cacheDirectory=".phpunit.cache"
>
<testsuites>
<testsuite name="mantle-framework">
<directory prefix="test-" suffix=".php">./tests/</directory>
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
2 changes: 1 addition & 1 deletion src/mantle/assets/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"require": {
"php": "^8.0",
"alleyinteractive/composer-wordpress-autoloader": "^1.0",
"alleyinteractive/wp-asset-manager": "^1.3.3",
"alleyinteractive/wp-asset-manager": "^1.3.4",
"mantle-framework/contracts": "^0.12",
"mantle-framework/support": "^0.12"
},
Expand Down
54 changes: 0 additions & 54 deletions src/mantle/testing/class-assert.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/mantle/testing/concerns/trait-reads-annotations.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public function get_annotations_for_method(): array {
}

// Use the PHPUnit ^9.5 method if available.
if ( method_exists( Test::class, 'parseTestMethodAnnotations' ) ) {
if ( method_exists( Test::class, 'parseTestMethodAnnotations' ) ) { // @phpstan-ignore-line
return Test::parseTestMethodAnnotations(
static::class,
$this->getName()
$this->getName(), // @phpstan-ignore-line
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Mantle\Assets\Asset_Loader;
use Mantle\Assets\Exception\Asset_Not_Found;

class Test_Asset_Loader extends Test_Case {
class AssetLoaderTest extends TestCase {
public string $build_dir = '';

public Asset_Loader $loader;
Expand Down Expand Up @@ -84,7 +84,7 @@ public function test_asset_enqueue_from_asset_path() {
$head = $this->get_wp_head();

$this->assertStringContainsString(
"<script async src='https://example.org/base/app.js?id=8c5b220bf6f482881a90' id='app-js-js'></script>",
'<script async src="https://example.org/base/app.js?id=8c5b220bf6f482881a90" id="app-js-js"></script>',
$head,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* @group assets
*/
class Test_Asset_Manager extends Test_Case {
class AssetManagerTest extends TestCase {
public function test_register_script() {
$manager = new Asset_Manager();
$manager
Expand All @@ -22,7 +22,7 @@ public function test_register_script() {
);

$this->assertStringContainsString(
"<script src='https://example.org/script.js' id='script-handle-js'></script>",
'<script src="https://example.org/script.js" id="script-handle-js"></script>',
$this->get_wp_head(),
);
}
Expand All @@ -37,7 +37,7 @@ public function test_register_style() {
);

$this->assertStringContainsString(
"<link rel='stylesheet' id='style-handle-css' href='https://example.org/style.css' media='all' />",
'<link rel=\'stylesheet\' id=\'style-handle-css\' href=\'https://example.org/style.css\' media=\'all\' />',
$this->get_wp_head(),
);
}
Expand All @@ -53,7 +53,7 @@ public function test_async_script() {
$manager->async( 'testsync-script-handle' );

$this->assertStringContainsString(
"<script async src='https://example.org/example-script.js' id='testsync-script-handle-js'></script>",
'<script async src="https://example.org/example-script.js" id="testsync-script-handle-js"></script>',
$this->get_wp_head(),
);
}
Expand All @@ -66,7 +66,7 @@ public function test_fluent_script() {
->async();

$this->assertStringContainsString(
"<script async src='https://example.org/example-fluent.js' id='example-fluent-js'></script>",
'<script async src="https://example.org/example-fluent.js" id="example-fluent-js"></script>',
$this->get_wp_head(),
);
}
Expand All @@ -78,7 +78,7 @@ public function test_fluent_script_helper() {
->async();

$this->assertStringContainsString(
"<script async src='https://example.org/example-helper.js' id='example-helper-js'></script>",
'<script async src="https://example.org/example-helper.js" id="example-helper-js"></script>',
$this->get_wp_head(),
);
}
Expand All @@ -89,7 +89,6 @@ public function test_core_dependency() {
// Prevent a failing test if this is removed in the future.
if ( ! isset( $wp_scripts->registered['swfobject'] ) ) {
$this->markTestSkipped( 'swfobject is not registered in core, should change the dependency tested against' );
return;
}

$version = $wp_scripts->registered['swfobject']->ver;
Expand All @@ -101,7 +100,7 @@ public function test_core_dependency() {
->async();

$this->assertStringContainsString(
"<script async src='http://example.org/wp-includes/js/swfobject.js?ver={$version}' id='swfobject-js'></script>",
'<script async src="http://example.org/wp-includes/js/swfobject.js?ver=' . $version . '" id="swfobject-js"></script>',
$this->get_wp_head(),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Mantle\Testing\Framework_Test_Case;
use WP_Scripts;

abstract class Test_Case extends Framework_Test_Case {
abstract class TestCase extends Framework_Test_Case {
protected function setUp(): void {
parent::setUp();

Expand Down Expand Up @@ -48,6 +48,7 @@ function() {
protected function get_wp_head(): string {
ob_start();
do_action( 'wp_head' );
// do_action( 'wp_footer' );
return ob_get_clean();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Mantle\Testing\Framework_Test_Case;
use Predis\Connection\ConnectionException;

class Test_Cache_Manager extends Framework_Test_Case {
class CacheManagerTest extends Framework_Test_Case {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I like the Pascal case... I must be getting old. New things 😨

public function test_unconfigured_store() {
$this->expectException( InvalidArgumentException::class );
$this->expectExceptionMessage( 'Driver not specified for [invalid-store].' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Mantle\Config\Repository;
use PHPUnit\Framework\TestCase;

class Test_Repository extends TestCase {
class RepositoryTest extends TestCase {
/**
* @var Repository
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;

class Test_Command extends TestCase {
class CommandTest extends TestCase {

public function test_registering_command_with_just_name() {
$command = new class extends Command {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Mantle\Framework\Console\Generators\Stub_Generator_Command;
use Mockery as m;

class Test_Generator_Command extends \Mockery\Adapter\Phpunit\MockeryTestCase {
class GeneratorCommandTest extends \Mockery\Adapter\Phpunit\MockeryTestCase {
/**
* @var Application
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Mantle\Testing\Framework_Test_Case;

// Disabling until command testing is reimplimented.
// class Test_Hook_Usage_Command extends Framework_Test_Case {
// class HookUsageCommandTest extends Framework_Test_Case {

// public function test_do_action() {
// $usage = $this->run_command( 'init' )->all();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;

class Test_Parser extends TestCase {
class ParserTest extends TestCase {

public function testBasicParameterParsing() {
$results = Parser::parse( 'command:name' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PHP_CodeSniffer\Runner;
use PHPUnit\Framework\TestCase;

class Test_Printer extends TestCase {
class PrinterTest extends TestCase {
protected static $temp_dir;
protected static $argv;

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use ReflectionException;
use stdClass;

class Test_Container_Call extends TestCase {
class ContainerCallTest extends TestCase {

public function testCallWithAtSignBasedClassReferencesWithoutMethodThrowsException() {
$this->expectException( Error::class );
Expand Down Expand Up @@ -188,7 +188,7 @@ public function testCallWithoutRequiredParamsThrowsException() {

public function testCallWithoutRequiredParamsOnClosureThrowsException() {
$this->expectException( Binding_Resolution_Exception::class );
$this->expectExceptionMessage( 'Unable to resolve dependency [Parameter #0 [ <required> $foo ]] in class Mantle\Tests\Container\Test_Container_Call' );
$this->expectExceptionMessage( 'Unable to resolve dependency [Parameter #0 [ <required> $foo ]] in class Mantle\Tests\Container\ContainerCallTest' );

$container = new Container();
$foo = $container->call(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Psr\Container\ContainerExceptionInterface;
use stdClass;

class Test_Container extends TestCase {
class ContainerTest extends TestCase {
protected function tearDown(): void {
Container::set_instance( null );
}
Expand Down Expand Up @@ -443,7 +443,7 @@ function () {

public function testMakeWithMethodIsAnAliasForMakeMethod() {
$mock = $this->getMockBuilder( Container::class )
->setMethods( [ 'make' ] )
->onlyMethods( [ 'make' ] )
->getMock();

$mock->expects( $this->once() )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* @group factory
*/
class Test_Factory extends Framework_Test_Case {
class FactoryTest extends Framework_Test_Case {
public function test_create_basic_model() {
$factory = Testable_Post::factory();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* @group factory
*/
class Test_Unit_Testing_Factory extends Framework_Test_Case {
class UnitTestingFactoryTest extends Framework_Test_Case {
use With_Faker;

public function test_post_factory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Mantle\Database\Model\Attachment;
use Mantle\Testing\Framework_Test_Case;

class Test_Attachment extends Framework_Test_Case {
class AttachmentTest extends Framework_Test_Case {
/**
* @var int
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Mantle\Testing\Framework_Test_Case;


class Test_Comment_Object extends Framework_Test_Case {
class CommentObjectTest extends Framework_Test_Case {
public function test_comment_object() {
$comment = $this->factory->comment->create_and_get();
$object = Comment::find( $comment );
Expand Down
Loading