Skip to content

Commit

Permalink
Merge pull request #360 from Yoast/JRF/tests-use-psr4
Browse files Browse the repository at this point in the history
Tests: use PSR-4
  • Loading branch information
jrfnl authored Nov 20, 2023
2 parents 49e0ab1 + e34da0e commit a6ef203
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 39 deletions.
26 changes: 19 additions & 7 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<file>.</file>

<exclude-pattern>tests/js/system/data/acf*\.php$</exclude-pattern><!-- Code exported from ACF. -->
<exclude-pattern>tests/php/unit/Dependencies/acf\.php$</exclude-pattern><!-- ACF mock class. -->
<exclude-pattern>tests/Unit/Doubles/acf\.php$</exclude-pattern><!-- ACF mock class. -->

<!-- Only check PHP files. -->
<arg name="extensions" value="php"/>
Expand Down Expand Up @@ -80,15 +80,23 @@
</properties>
</rule>

<rule ref="Yoast.Files.TestDoubles">
<properties>
<property name="doubles_path" type="array">
<element value="/tests/Unit/Doubles"/>
</property>
</properties>
</rule>

<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/php/unit"/>
<element value="tests/Unit"/>
</property>

<property name="prefixes" type="array" extend="true">
<element value="Yoast\WP\ACF\Tests"/>
<element value="Yoast\WP\ACF\Tests\Unit"/>
</property>
</properties>
</rule>
Expand All @@ -113,8 +121,7 @@

<!-- Valid usage: For testing purposes, some non-prefixed globals are being created. -->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<exclude-pattern>/integration-tests/bootstrap\.php$</exclude-pattern>
<exclude-pattern>/tests/bootstrap\.php$</exclude-pattern>
<exclude-pattern>/tests/Unit/bootstrap\.php$</exclude-pattern>
</rule>


Expand All @@ -139,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/php/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/php/unit"
],
"psr-4": {
"Yoast\\WP\\ACF\\Tests\\": "tests/"
},
"files": [
"tests/js/system/data/test-data-loader-functions.php"
],
"exclude-from-classmap": [
"/tests/php/unit/Dependencies/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/php/unit</directory>
<directory suffix="Test.php">tests/Unit</directory>
</testsuite>
</testsuites>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Yoast\WP\ACF\Tests;
namespace Yoast\WP\ACF\Tests\Unit;

use Brain\Monkey\Functions;
use Yoast\WPTestUtils\BrainMonkey\TestCase;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Yoast\WP\ACF\Tests\Configuration;
namespace Yoast\WP\ACF\Tests\Unit\Configuration;

use Brain\Monkey\Filters;
use Brain\Monkey\Functions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Yoast\WP\ACF\Tests\Configuration;
namespace Yoast\WP\ACF\Tests\Unit\Configuration;

use Yoast\PHPUnitPolyfills\TestCases\TestCase;
use Yoast_ACF_Analysis_String_Store;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php

namespace Yoast\WP\ACF\Tests\Dependencies;
namespace Yoast\WP\ACF\Tests\Unit\Dependencies;

use Yoast\WPTestUtils\BrainMonkey\TestCase;
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 All @@ -31,7 +31,7 @@ public function testNoACFClassExists() {
public function testACFClassExists() {
$testee = new Yoast_ACF_Analysis_Dependency_ACF();

require_once __DIR__ . \DIRECTORY_SEPARATOR . 'acf.php';
require_once \dirname( __DIR__ ) . '/Doubles/acf.php';

$this->assertTrue( $testee->is_met() );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php

namespace Yoast\WP\ACF\Tests\Dependencies;
namespace Yoast\WP\ACF\Tests\Unit\Dependencies;

use Yoast\WPTestUtils\BrainMonkey\TestCase;
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
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace Yoast\WP\ACF\Tests\Doubles;
namespace Yoast\WP\ACF\Tests\Unit\Doubles;

use Yoast_ACF_Analysis_Dependency;

/**
* Class Failing_Dependency.
* Class Failing_Dependency_Mock.
*/
class Failing_Dependency implements Yoast_ACF_Analysis_Dependency {
class Failing_Dependency_Mock implements Yoast_ACF_Analysis_Dependency {

/**
* Checks if this dependency is met.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace Yoast\WP\ACF\Tests\Doubles;
namespace Yoast\WP\ACF\Tests\Unit\Doubles;

use Yoast_ACF_Analysis_Dependency;

/**
* Class Passing_Dependency.
* Class Passing_Dependency_Mock.
*/
class Passing_Dependency implements Yoast_ACF_Analysis_Dependency {
class Passing_Dependency_Mock implements Yoast_ACF_Analysis_Dependency {

/**
* Checks if this dependency is met.
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/php/unit/main-test.php → tests/Unit/Main_Test.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Yoast\WP\ACF\Tests;
namespace Yoast\WP\ACF\Tests\Unit;

use AC_Yoast_SEO_ACF_Content_Analysis;
use Yoast\WPTestUtils\BrainMonkey\TestCase;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Yoast\WP\ACF\Tests;
namespace Yoast\WP\ACF\Tests\Unit;

use Yoast\PHPUnitPolyfills\TestCases\TestCase;
use Yoast_ACF_Analysis_Configuration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace Yoast\WP\ACF\Tests;
namespace Yoast\WP\ACF\Tests\Unit;

use Brain\Monkey\Functions;
use Yoast\WP\ACF\Tests\Doubles\Failing_Dependency;
use Yoast\WP\ACF\Tests\Doubles\Passing_Dependency;
use Yoast\WP\ACF\Tests\Unit\Doubles\Failing_Dependency_Mock;
use Yoast\WP\ACF\Tests\Unit\Doubles\Passing_Dependency_Mock;
use Yoast\WPTestUtils\BrainMonkey\TestCase;
use Yoast_ACF_Analysis_Requirements;

Expand Down Expand Up @@ -44,7 +44,7 @@ public function testNoDependencies() {
*/
public function testPassingDependency() {
$testee = new Yoast_ACF_Analysis_Requirements();
$testee->add_dependency( new Passing_Dependency() );
$testee->add_dependency( new Passing_Dependency_Mock() );

$this->assertTrue( $testee->are_met() );
}
Expand All @@ -59,7 +59,7 @@ public function testPassingDependency() {
*/
public function testFailingDependency() {
$testee = new Yoast_ACF_Analysis_Requirements();
$testee->add_dependency( new Failing_Dependency() );
$testee->add_dependency( new Failing_Dependency_Mock() );

$this->assertFalse( $testee->are_met() );
}
Expand All @@ -74,8 +74,8 @@ public function testFailingDependency() {
*/
public function testMixedDependencies() {
$testee = new Yoast_ACF_Analysis_Requirements();
$testee->add_dependency( new Failing_Dependency() );
$testee->add_dependency( new Passing_Dependency() );
$testee->add_dependency( new Failing_Dependency_Mock() );
$testee->add_dependency( new Passing_Dependency_Mock() );

$this->assertFalse( $testee->are_met() );
}
Expand Down

0 comments on commit a6ef203

Please sign in to comment.