Skip to content

Commit

Permalink
Merge pull request #1000 from Automattic/fix/tests-structure
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryJones authored Sep 17, 2023
2 parents d8bf67f + 65e44cf commit 17c5e9f
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/.phpunit.cache/
/node_modules/
/vendor/
/.phpcs.xml
/.phpunit.result.cache
/composer.lock
/phpcs.xml
/phpunit.xml
Expand Down
12 changes: 10 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@
}
},
"scripts": {
"coverage": [
"@putenv WP_MULTISITE=1",
"@php ./vendor/bin/phpunit --exclude=ms-excluded --coverage-html ./.phpunit.cache/coverage-html"
],
"coverage-ci": [
"@putenv WP_MULTISITE=1",
"@php ./vendor/bin/phpunit --exclude=ms-excluded"
],
"cs": [
"@php ./vendor/bin/phpcs -p -s -v -n . --standard=\"WordPress-VIP-Go\" --extensions=php --ignore=\"/vendor/*,/node_modules/*,/tests/*\""
],
Expand All @@ -65,11 +73,11 @@
"bash bin/install-wp-tests.sh wordpress_test root root localhost"
],
"integration": [
"@php ./vendor/bin/phpunit --exclude=ms-required"
"@php ./vendor/bin/phpunit --exclude=ms-required --no-coverage"
],
"integration-ms": [
"@putenv WP_MULTISITE=1",
"@php ./vendor/bin/phpunit --exclude=ms-excluded"
"@php ./vendor/bin/phpunit --exclude=ms-excluded --no-coverage"
],
"behat": "run-behat-tests",
"behat-rerun": "rerun-behat-tests",
Expand Down
59 changes: 41 additions & 18 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,19 +1,42 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
convertErrorsToExceptions="true"
convertWarningsToExceptions="true"
convertNoticesToExceptions="true"
convertDeprecationsToExceptions="true"
>
<testsuites>
<testsuite name="default">
<directory prefix="test-" suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
bootstrap="tests/Integration/bootstrap.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="false"
beStrictAboutCoversAnnotation="false"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
colors="true"
failOnRisky="true"
failOnWarning="true"
testdox="true"
verbose="true">
<testsuites>
<testsuite name="Integration">
<directory>tests/Integration</directory>
</testsuite>
</testsuites>

<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<file>co-authors-plus.php</file>
<file>template-tags.php</file>
<file>upgrade.php</file>
<directory>php</directory>
</include>
<exclude>
<!-- Inclusion of the next file breaks code coverage with Class "Yoast\WP\SEO\Generators\Schema\Author" not found -->
<file>php/integrations/yoast/class-coauthor.php</file>
<!-- The next view file has a floating $this which breaks PHPUnit coverage. -->
<file>php/integrations/amp/meta-author.php</file>
</exclude>
<report>
<text outputFile="php://stdout"/>
<clover outputFile=".phpunit.cache/clover.xml"/>
</report>
</coverage>
</phpunit>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
* Test Co-Authors Plus' modifications of author queries
*/

class Test_Author_Queried_Object extends CoAuthorsPlus_TestCase {
namespace Automattic\CoAuthorsPlus\Tests\Integration;

class AuthorQueriedObjectTest extends TestCase {

/**
* On author pages, the queried object should only be set
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

class Test_Author_Queries extends CoAuthorsPlus_TestCase {
namespace Automattic\CoAuthorsPlus\Tests\Integration;

class AuthorQueriesTest extends TestCase {

public function test__author_arg__user_is_post_author_query_as_post_author() {
$author_id = $this->factory()->user->create(
Expand All @@ -21,7 +23,7 @@ public function test__author_arg__user_is_post_author_query_as_post_author() {

wp_set_current_user( $author_id );

$query = new WP_Query(
$query = new \WP_Query(
array(
'author' => $author_id,
)
Expand All @@ -48,7 +50,7 @@ public function test__author_arg__user_is_post_author() {
);
$this->_cap->add_coauthors( $post_id, array( $author->user_login ) );

$query = new WP_Query(
$query = new \WP_Query(
array(
'author' => $author_id,
)
Expand All @@ -75,7 +77,7 @@ public function test__author_name_arg__user_is_post_author() {
);
$this->_cap->add_coauthors( $post_id, array( $author->user_login ) );

$query = new WP_Query(
$query = new \WP_Query(
array(
'author_name' => $author->user_login,
)
Expand Down Expand Up @@ -110,7 +112,7 @@ public function test__author_name_arg__user_is_coauthor() {
);
$this->_cap->add_coauthors( $post_id, array( $author1->user_login, $author2->user_login ) );

$query = new WP_Query(
$query = new \WP_Query(
array(
'author_name' => $author2->user_login,
)
Expand Down Expand Up @@ -145,7 +147,7 @@ public function test__author_arg__user_is_coauthor__author_arg() {
);
$this->_cap->add_coauthors( $post_id, array( $author1->user_login, $author2->user_login ) );

$query = new WP_Query(
$query = new \WP_Query(
array(
'author' => $author2_id,
)
Expand Down Expand Up @@ -173,7 +175,7 @@ public function test__author_name_arg_plus_tax_query__user_is_post_author() {
$this->_cap->add_coauthors( $post_id, array( $author->user_login ) );
wp_set_post_terms( $post_id, 'test' );

$query = new WP_Query(
$query = new \WP_Query(
array(
'author_name' => $author->user_login,
'tag' => 'test',
Expand Down Expand Up @@ -210,7 +212,7 @@ public function tests__author_name_arg_plus_tax_query__is_coauthor() {
$this->_cap->add_coauthors( $post_id, array( $author1->user_login, $author2->user_login ) );
wp_set_post_terms( $post_id, 'test' );

$query = new WP_Query(
$query = new \WP_Query(
array(
'author_name' => $author2->user_login,
'tag' => 'test',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

class Test_CoAuthors_Plus extends CoAuthorsPlus_TestCase {
namespace Automattic\CoAuthorsPlus\Tests\Integration;

class CoAuthorsPlusTest extends TestCase {

private $author1;
private $editor1;
Expand Down Expand Up @@ -72,7 +74,7 @@ public function test_get_coauthor_by_when_guest_author() {

$coauthor = $coauthors_plus->get_coauthor_by( 'id', $guest_author_id );

$this->assertInstanceOf( stdClass::class, $coauthor );
$this->assertInstanceOf( \stdClass::class, $coauthor );
$this->assertTrue( property_exists( $coauthor, 'ID' ) );
$this->assertEquals( $guest_author_id, $coauthor->ID );
$this->assertEquals( 'guest-author', $coauthor->type );
Expand All @@ -97,7 +99,7 @@ public function test_get_coauthor_by_when_guest_author_has_unicode_username() {

$coauthor = $coauthors_plus->get_coauthor_by( 'user_login', $user_login );

$this->assertInstanceOf( stdClass::class, $coauthor );
$this->assertInstanceOf( \stdClass::class, $coauthor );
$this->assertTrue( property_exists( $coauthor, 'ID' ) );
$this->assertEquals( $guest_author_id, $coauthor->ID );
$this->assertEquals( 'guest-author', $coauthor->type );
Expand All @@ -118,26 +120,26 @@ public function test_get_coauthor_by_when_guest_authors_not_enabled() {

$coauthor = $coauthors_plus->get_coauthor_by( 'id', $this->author1->ID );

$this->assertInstanceOf( WP_User::class, $coauthor );
$this->assertInstanceOf( \WP_User::class, $coauthor );
$this->assertTrue( property_exists( $coauthor, 'ID' ) );
$this->assertEquals( $this->author1->ID, $coauthor->ID );
$this->assertEquals( 'wpuser', $coauthor->type );

$coauthor = $coauthors_plus->get_coauthor_by( 'user_login', $this->author1->user_login );

$this->assertInstanceOf( WP_User::class, $coauthor );
$this->assertInstanceOf( \WP_User::class, $coauthor );
$this->assertTrue( property_exists( $coauthor->data, 'user_login' ) );
$this->assertEquals( $this->author1->user_login, $coauthor->user_login );

$coauthor = $coauthors_plus->get_coauthor_by( 'user_nicename', $this->author1->user_nicename );

$this->assertInstanceOf( WP_User::class, $coauthor );
$this->assertInstanceOf( \WP_User::class, $coauthor );
$this->assertTrue( property_exists( $coauthor->data, 'user_nicename' ) );
$this->assertEquals( $this->author1->user_nicename, $coauthor->user_nicename );

$coauthor = $coauthors_plus->get_coauthor_by( 'user_email', $this->author1->user_email );

$this->assertInstanceOf( WP_User::class, $coauthor );
$this->assertInstanceOf( \WP_User::class, $coauthor );
$this->assertTrue( property_exists( $coauthor->data, 'user_email' ) );
$this->assertEquals( $this->author1->user_email, $coauthor->user_email );

Expand All @@ -147,7 +149,7 @@ public function test_get_coauthor_by_when_guest_authors_not_enabled() {

$coauthor = $coauthors_plus->get_coauthor_by( 'id', $this->editor1->ID );

$this->assertInstanceOf( stdClass::class, $coauthor );
$this->assertInstanceOf( \stdClass::class, $coauthor );
$this->assertTrue( property_exists( $coauthor, 'linked_account' ) );
$this->assertEquals( $this->editor1->user_login, $coauthor->linked_account );
}
Expand Down Expand Up @@ -519,7 +521,7 @@ public function test_get_author_term_using_caching() {
$author_term = $coauthors_plus->get_author_term( $this->author1 );
$author_term_cached = wp_cache_get( $cache_key, 'co-authors-plus' );

$this->assertInstanceOf( WP_Term::class, $author_term );
$this->assertInstanceOf( \WP_Term::class, $author_term );
$this->assertEquals( $author_term, $author_term_cached );
}

Expand All @@ -538,7 +540,7 @@ public function test_get_author_term_when_author_has_linked_account() {

$author_term = $coauthors_plus->get_author_term( $coauthor );

$this->assertInstanceOf( WP_Term::class, $author_term );
$this->assertInstanceOf( \WP_Term::class, $author_term );

// Checks when term does not exist or deleted somehow.
wp_delete_term( $author_term->term_id, $author_term->taxonomy );
Expand Down Expand Up @@ -566,7 +568,7 @@ public function test_get_author_term_when_author_has_not_linked_account() {

$author_term = $coauthors_plus->get_author_term( $coauthor );

$this->assertInstanceOf( WP_Term::class, $author_term );
$this->assertInstanceOf( \WP_Term::class, $author_term );

// Checks when term does not exist or deleted somehow.
wp_delete_term( $author_term->term_id, $author_term->taxonomy );
Expand Down
Loading

0 comments on commit 17c5e9f

Please sign in to comment.