Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: fix setUp()/tearDown() methods #290

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dull-pandas-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wpengine/wp-graphql-content-blocks": patch
---

tests: fix `setUp()`/`tearDown()` methods to prevent PHPUnit lifecycle issues.
5 changes: 2 additions & 3 deletions tests/unit/AutoloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ public function testAutoload() {
}

public function testRequireAutoloader() {
$reflection = new \ReflectionClass( $this->autoloader );
$is_loaded_property = $reflection->getProperty( 'is_loaded' );
$reflection = new \ReflectionClass( $this->autoloader );
$is_loaded_property = $reflection->getProperty( 'is_loaded' );
$is_loaded_property->setAccessible( true );
$is_loaded_property->setValue( $this->autoloader, false );

$method = $reflection->getMethod( 'require_autoloader' );
$method->setAccessible( true );


$this->assertTrue( $method->invokeArgs( $this->autoloader, [ WPGRAPHQL_CONTENT_BLOCKS_PLUGIN_DIR . '/vendor/autoload.php' ] ) );

$is_loaded_property->setValue( $this->autoloader, false );
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/BlockAttributesObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ final class BlockAttributesObjectTest extends PluginTestCase {
public function setUp(): void {
parent::setUp();

global $wpdb;

$this->post_id = wp_insert_post(
[
'post_title' => 'Post Title',
Expand All @@ -27,13 +25,16 @@ public function setUp(): void {
'post_status' => 'publish',
]
);

\WPGraphQL::clear_schema();
}

public function tearDown(): void {
// your tear down methods here
parent::tearDown();

wp_delete_post( $this->post_id, true );
\WPGraphQL::clear_schema();

parent::tearDown();
}

public function test_resolve_attribute_object_type() {
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/BlockQueriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ final class BlockQueriesTest extends PluginTestCase {
public function setUp(): void {
parent::setUp();

global $wpdb;

$this->post_id = wp_insert_post(
[
'post_title' => 'Post Title',
Expand Down Expand Up @@ -38,13 +36,16 @@ public function setUp(): void {
'post_status' => 'publish',
]
);

\WPGraphQL::clear_schema();
}

public function tearDown(): void {
// your tear down methods here
parent::tearDown();

wp_delete_post( $this->post_id, true );
\WPGraphQL::clear_schema();

parent::tearDown();
}

public function test_retrieve_non_flatten_editor_blocks() {
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/BlockSupportsAnchorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ public function setUp(): void {

public function tearDown(): void {
// your tear down methods here
parent::tearDown();

wp_delete_post( $this->post_id, true );
delete_option( 'graphql_general_settings' );
\WPGraphQL::clear_schema();

parent::tearDown();
}

/**
Expand Down
7 changes: 5 additions & 2 deletions tests/unit/ContentBlocksResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,18 @@ public function setUp(): void {
);

$this->instance = new ContentBlocksResolver();

\WPGraphQL::clear_schema();
}

public function tearDown(): void {
// your tear down methods here
parent::tearDown();

wp_delete_post( $this->post_id, true );
wp_delete_post( $this->reusable_post_id, true );
wp_delete_post( $this->reusable_block_id, true );
\WPGraphQL::clear_schema();

parent::tearDown();
}

public function test_resolve_content_blocks_resolves_reusable_blocks() {
Expand Down
8 changes: 5 additions & 3 deletions tests/unit/CoreImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ final class CoreImageTest extends PluginTestCase {
public function setUp(): void {
parent::setUp();

global $wpdb;
$this->attachment_id = $this->factory->attachment->create_upload_object( WP_TEST_DATA_DIR . '/images/test-image.jpg' );

$this->post_id = wp_insert_post(
Expand All @@ -30,13 +29,16 @@ public function setUp(): void {
'post_status' => 'publish',
]
);

\WPGraphQL::clear_schema();
}

public function tearDown(): void {
// your tear down methods here
parent::tearDown();

wp_delete_post( $this->post_id, true );
\WPGraphQL::clear_schema();

parent::tearDown();
}

public function test_retrieve_core_image_media_details() {
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/CoreTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ final class CoreTableTest extends PluginTestCase {
public function setUp(): void {
parent::setUp();

global $wpdb;

$this->post_id = wp_insert_post(
[
'post_title' => 'Post Title',
Expand All @@ -31,16 +29,18 @@ public function setUp(): void {
'post_status' => 'publish',
]
);

\WPGraphQL::clear_schema();
}

public function tearDown(): void {
parent::tearDown();

wp_delete_post( $this->post_id, true );
\WPGraphQL::clear_schema();

parent::tearDown();
}

public function test_retrieve_core_table_attribute_fields() {
$this->markTestSkipped( 'must be revisited since the test is failing on the CI for an unknown reason' );
$query = '
fragment CoreTableBlockFragment on CoreTable {
attributes {
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/CoreVideoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ final class CoreVideoTest extends PluginTestCase {
public function setUp(): void {
parent::setUp();

global $wpdb;

$this->post_id = wp_insert_post(
[
'post_title' => 'Post Title',
Expand All @@ -28,17 +26,19 @@ public function setUp(): void {
'post_status' => 'publish',
]
);

\WPGraphQL::clear_schema();
}

public function tearDown(): void {
// your tear down methods here
parent::tearDown();

wp_delete_post( $this->post_id, true );
\WPGraphQL::clear_schema();

parent::tearDown();
}

public function test_retrieve_core_video_attributes() {
$this->markTestSkipped( 'must be revisited since the test is failing on the CI for an unknown reason' );
$query = '
fragment CoreVideoBlockFragment on CoreVideo {
attributes {
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/EditorBlockInterfaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ public function setUp(): void {
$settings = get_option( 'graphql_general_settings', [] );
$settings['public_introspection_enabled'] = 'on';
update_option( 'graphql_general_settings', $settings );

\WPGraphQL::clear_schema();
}

public function tearDown(): void {
// your tear down methods here
delete_option( 'graphql_general_settings' );
\WPGraphQL::clear_schema();

// then
parent::tearDown();
Expand Down
1 change: 1 addition & 0 deletions tests/unit/PostTypeBlockInterfaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function setUp(): void {

public function tearDown(): void {
// your tear down methods here
delete_option( 'graphql_general_settings' );
\WPGraphQL::clear_schema();

parent::tearDown();
Expand Down
1 change: 1 addition & 0 deletions tests/unit/RegistryTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function setUp(): void {

public function tearDown(): void {
// your tear down methods here
delete_option( 'graphql_general_settings' );
\WPGraphQL::clear_schema();

parent::tearDown();
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/UpdateCallbacksTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

namespace WPGraphQL\ContentBlocks\Unit;

/**
* Class UpdateCallbacksTest
*/
class UpdateCallbacksTest extends WP_UnitTestCase {
class UpdateCallbacksTest extends PluginTestCase {
public function test_pre_set_site_transient_update_plugins_has_filter_added(): void {
self::assertSame( 10, has_action( 'pre_set_site_transient_update_plugins', 'WPGraphQL\ContentBlocks\PluginUpdater\check_for_plugin_updates' ) );
}
Expand Down
Loading