diff --git a/Tests/Fixtures/inc/functions/Attachments/ImagifyAttachmentMetaData.php b/Tests/Fixtures/inc/functions/Attachments/ImagifyHasAttachmentsWithoutRequiredMetadata.php similarity index 100% rename from Tests/Fixtures/inc/functions/Attachments/ImagifyAttachmentMetaData.php rename to Tests/Fixtures/inc/functions/Attachments/ImagifyHasAttachmentsWithoutRequiredMetadata.php diff --git a/Tests/Unit/bootstrap.php b/Tests/Unit/bootstrap.php index 1ef50450..81ff9d72 100644 --- a/Tests/Unit/bootstrap.php +++ b/Tests/Unit/bootstrap.php @@ -10,5 +10,28 @@ define( 'IMAGIFY_PLUGIN_ROOT', dirname( dirname( __DIR__ ) ) . DIRECTORY_SEPARATOR ); define( 'IMAGIFY_PLUGIN_TESTS_FIXTURES_DIR', dirname( __DIR__ ) . '/Fixtures' ); -require_once IMAGIFY_PLUGIN_ROOT . 'inc/functions/api.php'; -include_once IMAGIFY_PLUGIN_TESTS_FIXTURES_DIR . '/WP/class-wp-error.php'; +/** + * The original files need to loaded into memory before we mock them with Patchwork. Add files here before the unit + * tests start. + * + * @since 3.5 + */ +function load_original_files_before_mocking() { + $originals = [ + 'inc/functions/api.php', + 'inc/functions/attachments.php', + 'inc/functions/common.php', + ]; + foreach ( $originals as $file ) { + require_once IMAGIFY_PLUGIN_ROOT . $file; + } + + $fixtures = [ + '/WP/class-wp-error.php', + ]; + foreach ( $fixtures as $file ) { + require_once IMAGIFY_PLUGIN_TESTS_FIXTURES_DIR . $file; + } +} + +load_original_files_before_mocking(); diff --git a/Tests/Unit/inc/functions/Attachments/ImagifyAttachmentMetadata.php b/Tests/Unit/inc/functions/Attachments/ImagifyHasAttachmentsWithoutRequiredMetadata.php similarity index 73% rename from Tests/Unit/inc/functions/Attachments/ImagifyAttachmentMetadata.php rename to Tests/Unit/inc/functions/Attachments/ImagifyHasAttachmentsWithoutRequiredMetadata.php index fdc073c2..e93bca9a 100644 --- a/Tests/Unit/inc/functions/Attachments/ImagifyAttachmentMetadata.php +++ b/Tests/Unit/inc/functions/Attachments/ImagifyHasAttachmentsWithoutRequiredMetadata.php @@ -7,9 +7,10 @@ use wpdb; /** - * Test class covering inc/functions/attachments::imagify_has_attachments_without_required_metadata + * + * @covers imagify_has_attachments_without_required_metadata */ -class Test_ImagifyAttachmentMetadata extends TestCase { +class Test_ImagifyHasAttachmentsWithoutRequiredMetadata extends TestCase { private $wpdb; @@ -25,9 +26,6 @@ public function setUp(): void { $GLOBALS['wpdb'] = $this->wpdb = new wpdb( 'dbuser', 'dbpassword', 'dbname', 'dbhost' ); $this->wpdb->posts = 'wp_posts'; - - require_once IMAGIFY_PLUGIN_ROOT . 'inc/functions/attachments.php'; - require_once IMAGIFY_PLUGIN_ROOT . 'inc/functions/common.php'; } @@ -40,8 +38,7 @@ protected function tearDown(): void { /** * @dataProvider configTestData */ - public function testShouldReturnExpected( $config, $expected ) - { + public function testShouldReturnExpected( $config, $expected ) { $this->wpdb->set_var( $expected ); if( $expected ) { diff --git a/Tests/Unit/inc/functions/imagifySanitizeContext.php b/Tests/Unit/inc/functions/imagifySanitizeContext.php index 7c7f250d..a9f8fb28 100644 --- a/Tests/Unit/inc/functions/imagifySanitizeContext.php +++ b/Tests/Unit/inc/functions/imagifySanitizeContext.php @@ -6,13 +6,6 @@ use Imagify\Tests\Unit\TestCase; class Test_ImagifySanitizeContext extends TestCase { - - protected function setUp(): void { - parent::setUp(); - - require_once IMAGIFY_PLUGIN_ROOT . 'inc/functions/common.php'; - } - /** * Test should return sanitized key. */ diff --git a/Tests/Unit/phpunit.xml.dist b/Tests/Unit/phpunit.xml.dist index 861281e7..31a15118 100644 --- a/Tests/Unit/phpunit.xml.dist +++ b/Tests/Unit/phpunit.xml.dist @@ -1,28 +1,14 @@ - - - - - inc - classes - - - - - - ../../inc - - + + + + ../../inc + + + + + inc + classes + +