Skip to content

Commit

Permalink
Merge pull request #334 from Yoast/JRF/tests-use-psr4
Browse files Browse the repository at this point in the history
Jrf/tests use psr4
  • Loading branch information
jrfnl authored Nov 20, 2023
2 parents 9081aa2 + 97eceea commit c010070
Show file tree
Hide file tree
Showing 34 changed files with 47 additions and 35 deletions.
8 changes: 8 additions & 0 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,12 @@
<exclude-pattern>/src/watchers/republished-post-watcher\.php$</exclude-pattern>
</rule>

<!-- The below two issues will be fixed in YoastCS 3.0, after which these excludes can be removed. -->
<rule ref="Yoast.Commenting.FileComment.Unnecessary">
<exclude-pattern>/tests/*/bootstrap\.php$</exclude-pattern>
</rule>
<rule ref="Yoast.Files.FileName.InvalidClassFileName">
<exclude-pattern>/tests/*\.php$</exclude-pattern>
</rule>

</ruleset>
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
]
},
"autoload-dev": {
"classmap": [
"tests/"
]
"psr-4": {
"Yoast\\WP\\Duplicate_Post\\Tests\\": "tests/"
}
},
"config": {
"allow-plugins": {
Expand Down
4 changes: 2 additions & 2 deletions phpunit-wp.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/wp/bootstrap.php"
bootstrap="tests/WP/bootstrap.php"
colors="true"
convertDeprecationsToExceptions="true"
convertErrorsToExceptions="true"
Expand All @@ -20,7 +20,7 @@
>
<testsuites>
<testsuite name="duplicatepost">
<directory suffix="-test.php">./tests/wp</directory>
<directory suffix="Test.php">./tests/WP</directory>
</testsuite>
</testsuites>

Expand Down
4 changes: 2 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/unit/bootstrap.php"
bootstrap="tests/Unit/bootstrap.php"
colors="true"
convertDeprecationsToExceptions="true"
convertErrorsToExceptions="true"
Expand All @@ -20,7 +20,7 @@
>
<testsuites>
<testsuite name="duplicatepost">
<directory suffix="-test.php">./tests/unit</directory>
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions tests/Unit/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* PHPUnit bootstrap file
*
* @package Yoast\WP\Duplicate_Post\Tests
*/

namespace Yoast\WP\Duplicate_Post\Tests\Unit;

\define( 'OBJECT', 'OBJECT' );
\define( 'ARRAY_A', 'ARRAY_A' );
\define( 'ARRAY_N', 'ARRAY_N' );

\define( 'DUPLICATE_POST_FILE', '/var/www/html/wp-content/plugins/duplicate-post/duplicate-post.php' );
\define( 'DUPLICATE_POST_CURRENT_VERSION', '4.0' );

if ( \file_exists( \dirname( __DIR__, 2 ) . '/vendor/autoload.php' ) === false ) {
echo \PHP_EOL, 'ERROR: Run `composer install` to generate the autoload files before running the unit tests.', \PHP_EOL;
exit( 1 );
}

require_once __DIR__ . '/../../vendor/yoast/wp-test-utils/src/BrainMonkey/bootstrap.php';
require_once __DIR__ . '/../../vendor/autoload.php';
File renamed without changes.
16 changes: 9 additions & 7 deletions tests/wp/bootstrap.php → tests/WP/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,30 @@
* @package Yoast\WP\Duplicate_Post\Tests
*/

namespace Yoast\WP\Duplicate_Post\Tests\WP;

use Yoast\WPTestUtils\WPIntegration;

// Disable xdebug backtrace.
if ( function_exists( 'xdebug_disable' ) ) {
xdebug_disable();
if ( \function_exists( 'xdebug_disable' ) ) {
\xdebug_disable();
}

echo 'Welcome to the Duplicate Post Test Suite' . PHP_EOL;
echo 'Version: 1.0' . PHP_EOL . PHP_EOL;
echo 'Welcome to the Duplicate Post Test Suite' . \PHP_EOL;
echo 'Version: 1.0' . \PHP_EOL . \PHP_EOL;

/*
* Load the plugin(s).
*/
require_once dirname( __DIR__, 2 ) . '/vendor/yoast/wp-test-utils/src/WPIntegration/bootstrap-functions.php';
require_once \dirname( __DIR__, 2 ) . '/vendor/yoast/wp-test-utils/src/WPIntegration/bootstrap-functions.php';

// Get access to tests_add_filter() function.
require_once WPIntegration\get_path_to_wp_test_dir() . 'includes/functions.php';

tests_add_filter(
\tests_add_filter(
'muplugins_loaded',
function() {
require_once dirname( __DIR__, 2 ) . '/duplicate-post.php';
require_once \dirname( __DIR__, 2 ) . '/duplicate-post.php';
}
);

Expand Down
21 changes: 0 additions & 21 deletions tests/unit/bootstrap.php

This file was deleted.

0 comments on commit c010070

Please sign in to comment.