Skip to content

Commit

Permalink
Tests: use PSR-4
Browse files Browse the repository at this point in the history
* Ensure all test class names reflect the name of the class under test.
* Ensure all test class file names match the name of the test class.
* Change the Composer `autoload-dev` directive to use PSR-4 autoloading.
* Update the `phpunit.xml.dist` file to match.
* Update the `.phpcs.xml.dist` file to match.
  • Loading branch information
jrfnl committed Nov 20, 2023
1 parent 1df5e33 commit e34da0e
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 13 deletions.
9 changes: 7 additions & 2 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@

<rule ref="Yoast.NamingConventions.NamespaceName">
<properties>
<!-- Treat the "tests/php/unit" directory as a project root for path to namespace translations. -->
<!-- Treat the "tests/Unit" directory as a project root for path to namespace translations. -->
<property name="src_directory" type="array">
<element value="tests/Unit"/>
</property>
Expand Down Expand Up @@ -146,7 +146,12 @@
by WPCS. This will most likely be fixed once PHPCS 3.5.0 has been released and
WPCS has upgraded to that version. -->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound">
<exclude-pattern>/tests/Unit/Dependencies/yoast-seo-dependency-test\.php$</exclude-pattern>
<exclude-pattern>/tests/Unit/Dependencies/Dependency_Yoast_SEO_Test\.php$</exclude-pattern>
</rule>

<!-- The below issue will be fixed in YoastCS 3.0, after which this exclude can be removed. -->
<rule ref="Yoast.Files.FileName.InvalidClassFileName">
<exclude-pattern>/tests/Unit/*\.php$</exclude-pattern>
</rule>

</ruleset>
9 changes: 3 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,11 @@
]
},
"autoload-dev": {
"classmap": [
"tests/Unit"
],
"psr-4": {
"Yoast\\WP\\ACF\\Tests\\": "tests/"
},
"files": [
"tests/js/system/data/test-data-loader-functions.php"
],
"exclude-from-classmap": [
"/tests/Unit/Doubles/acf.php"
]
},
"config": {
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
>
<testsuites>
<testsuite name="yoastacf">
<directory suffix="test.php">tests/Unit</directory>
<directory suffix="Test.php">tests/Unit</directory>
</testsuite>
</testsuites>

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
use Yoast_ACF_Analysis_Dependency_ACF;

/**
* Class ACF_Dependency_Test.
* Class Dependency_ACF_Test.
*
* @covers Yoast_ACF_Analysis_Dependency_ACF
*/
class ACF_Dependency_Test extends TestCase {
class Dependency_ACF_Test extends TestCase {

/**
* Tests the situation where no ACF class exists.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
use Yoast_ACF_Analysis_Dependency_Yoast_SEO;

/**
* Class Yoast_SEO_Dependency_Test.
* Class Dependency_Yoast_SEO_Test.
*
* @covers Yoast_ACF_Analysis_Dependency_Yoast_SEO
*/
class Yoast_SEO_Dependency_Test extends TestCase {
class Dependency_Yoast_SEO_Test extends TestCase {

/**
* Whether or not to preserve the global state.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit e34da0e

Please sign in to comment.