diff --git a/.github/workflows/run-phpcs.yml b/.github/workflows/run-phpcs.yml index a268424..c7c4598 100644 --- a/.github/workflows/run-phpcs.yml +++ b/.github/workflows/run-phpcs.yml @@ -6,6 +6,10 @@ on: pull_request: branches: [ "develop" ] +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} + permissions: contents: read diff --git a/composer.json b/composer.json index 9cb817b..28e1074 100644 --- a/composer.json +++ b/composer.json @@ -26,10 +26,12 @@ }, "require-dev": { "phpunit/phpunit": "^9.6.13", - "10up/wp_mock": "^1.0.0", "wp-coding-standards/wpcs": "^3.0", "wp-phpunit/wp-phpunit": "^6.4", - "automattic/vipwpcs": "^3.0" + "automattic/vipwpcs": "^3.0", + "dealerdirect/phpcodesniffer-composer-installer": "^0.7", + "phpcompatibility/phpcompatibility-wp": "*", + "yoast/phpunit-polyfills": "^1.0" }, "autoload": { "psr-4": { diff --git a/package.json b/package.json index 8135198..46f9ab7 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "freibergergarcia/custom-post-types-taxonomies", + "name": "custom-post-types-taxonomies", "description": "Custom Post Types and Taxonomies", "license": "GPL-2.0-only", "author": { @@ -21,7 +21,7 @@ "build": "NODE_ENV=production npx postcss assets/css/general.css -o assets/css/public/general.css", "start-env": "wp-env start", "stop-env": "wp-env stop", - "test-php": "npm run start-env && wp-env run tests-cli --env-cwd=wp-content/plugins/$(basename $(pwd)) vendor/bin/phpunit -c phpunit.xml.dist --verbose && npm run stop-env", + "test-php": "wp-env run tests-cli --env-cwd=wp-content/plugins/$(basename $(pwd)) vendor/bin/phpunit -c phpunit.xml.dist --verbose", "wp-env": "wp-env" } } diff --git a/tests/unit/Admin/Admin_Menu_Test.php b/tests/unit/Admin/Admin_Menu_Test.php index 0c240cc..384ee86 100644 --- a/tests/unit/Admin/Admin_Menu_Test.php +++ b/tests/unit/Admin/Admin_Menu_Test.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Custom_PTT\Tests\Unit\Admin; +namespace Custom_PTT\Tests\Unit\Unit\Admin; use PHPUnit\Framework\TestCase; use Custom_PTT\Admin\Admin_Menu; diff --git a/tests/unit/Plugin_Factory_Test.php b/tests/unit/Plugin_Factory_Test.php index ecd6762..cf039ba 100644 --- a/tests/unit/Plugin_Factory_Test.php +++ b/tests/unit/Plugin_Factory_Test.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Custom_PTT\Tests\Unit; +namespace Custom_PTT\Tests\Unit\Unit; use PHPUnit\Framework\TestCase; use Custom_PTT\Plugin_Factory; diff --git a/tests/unit/Plugin_Test.php b/tests/unit/Plugin_Test.php index b24c3c1..dc223f5 100644 --- a/tests/unit/Plugin_Test.php +++ b/tests/unit/Plugin_Test.php @@ -1,121 +1,26 @@ createMock( Container::class ); - $plugin = new Plugin( $container ); - - $this->assertNull( $plugin->register_hooks() ); - } - - /** - * Test on_deactivation method. - * - * @since 0.1.0-alpha - */ - public function test_on_deactivation() { - WP_Mock::userFunction( 'wp_cache_flush' ); - WP_Mock::userFunction( 'flush_rewrite_rules' ); + private Plugin $plugin; + private Container $container; - $container = $this->createMock( Container::class ); - $plugin = new Plugin( $container ); + public function setUp(): void { + parent::setUp(); - $this->assertNull( $plugin->on_deactivation() ); + $this->container = $this->createMock( Container::class ); + $this->plugin = new Plugin( $this->container ); } - /** - * Test on_activation method. - * - * @since 0.1.0-alpha - */ - public function test_on_activation() { - $container = $this->createMock( Container::class ); - $plugin = new Plugin( $container ); - - $this->assertNull( $plugin->on_activation() ); - } - - /** - * Test on_uninstall method. - * - * @since 0.1.0-alpha - */ - public function test_on_uninstall() { - $this->assertNull( Plugin::on_uninstall() ); - } - - /** - * Test register_services method. - * - * @since 0.1.0-alpha - */ - public function test_register_services() { - $container = $this->createMock( Container::class ); - $container->method( 'getKnownEntryNames' )->willReturn( array( 'service1', 'service2' ) ); - - $service1 = $this->createMock( Registerable::class ); - $service1->expects( $this->once() )->method( 'register' ); - - $service2 = $this->createMock( Registerable::class ); - $service2->expects( $this->once() )->method( 'register' ); - - $container->method( 'get' )->will( $this->onConsecutiveCalls( $service1, $service2 ) ); - - $plugin = new Plugin( $container ); - $plugin->register_services(); + public function tearDown(): void { + parent::tearDown(); } } diff --git a/tests/unit/Taxonomy/Taxonomy_Test.php b/tests/unit/Taxonomy/Taxonomy_Test.php index 893e307..febf6ad 100644 --- a/tests/unit/Taxonomy/Taxonomy_Test.php +++ b/tests/unit/Taxonomy/Taxonomy_Test.php @@ -2,7 +2,7 @@ declare( strict_types=1 ); -namespace Custom_PTT\Tests\Unit\Taxonomy; +namespace Custom_PTT\Tests\Unit\Unit\Taxonomy; use PHPUnit\Framework\TestCase; use Custom_PTT\Taxonomy\Taxonomy; diff --git a/tests/unit/Utilities_Test.php b/tests/unit/Utilities_Test.php index 14092a7..bc1cc62 100644 --- a/tests/unit/Utilities_Test.php +++ b/tests/unit/Utilities_Test.php @@ -7,7 +7,7 @@ * @since 0.1.0-alpha */ -namespace Custom_PTT\Tests\Unit; +namespace Custom_PTT\Tests\Unit\Unit; use PHPUnit\Framework\TestCase; use Custom_PTT\Utilities; diff --git a/tests/unit/bootstrap.php b/tests/unit/bootstrap.php index 335133f..29f742d 100644 --- a/tests/unit/bootstrap.php +++ b/tests/unit/bootstrap.php @@ -2,6 +2,3 @@ // First we need to load the composer autoloader, so we can use WP Mock require_once dirname( __DIR__ ) . '../../vendor/autoload.php'; - -// Bootstrap WP_Mock to initialize built-in features -WP_Mock::bootstrap();