diff --git a/includes/MslsBlock.php b/includes/MslsBlock.php
index 70fdc57f..c019cb2f 100644
--- a/includes/MslsBlock.php
+++ b/includes/MslsBlock.php
@@ -4,7 +4,6 @@
class MslsBlock {
-
protected MslsOptions $options;
public function __construct( MslsOptions $options ) {
diff --git a/tests/phpunit/Component/Icon/TestIconPng.php b/tests/phpunit/Component/Icon/TestIconPng.php
index 5255bc42..19a0e32b 100644
--- a/tests/phpunit/Component/Icon/TestIconPng.php
+++ b/tests/phpunit/Component/Icon/TestIconPng.php
@@ -6,7 +6,7 @@
use lloc\Msls\Component\Icon\IconPng;
use lloc\MslsTests\MslsUnitTestCase;
-class TestIconPng extends MslsUnitTestCase {
+final class TestIconPng extends MslsUnitTestCase {
public function test_get(): void {
Functions\when( 'plugin_dir_path' )->justReturn( dirname( __DIR__, 4 ) . '/' );
diff --git a/tests/phpunit/Component/Icon/TestIconSvg.php b/tests/phpunit/Component/Icon/TestIconSvg.php
index 3c6f3224..03c71dd8 100644
--- a/tests/phpunit/Component/Icon/TestIconSvg.php
+++ b/tests/phpunit/Component/Icon/TestIconSvg.php
@@ -6,7 +6,7 @@
use lloc\Msls\Component\Icon\IconSvg;
use lloc\MslsTests\MslsUnitTestCase;
-class TestIconSvg extends MslsUnitTestCase {
+final class TestIconSvg extends MslsUnitTestCase {
public function test_get(): void {
Functions\when( 'plugin_dir_path' )->justReturn( dirname( __DIR__, 4 ) . '/' );
diff --git a/tests/phpunit/ContentImport/Importers/Attachments/TestLinking.php b/tests/phpunit/ContentImport/Importers/Attachments/TestLinking.php
index 2fa777b6..95d03c9b 100644
--- a/tests/phpunit/ContentImport/Importers/Attachments/TestLinking.php
+++ b/tests/phpunit/ContentImport/Importers/Attachments/TestLinking.php
@@ -7,7 +7,7 @@
use lloc\Msls\ContentImport\Importers\Attachments\Linking;
use lloc\MslsTests\MslsUnitTestCase;
-class TestLinking extends MslsUnitTestCase {
+final class TestLinking extends MslsUnitTestCase {
public function testImport(): void {
$coordinates = \Mockery::mock( ImportCoordinates::class );
diff --git a/tests/phpunit/ContentImport/Importers/PostFields/TestDuplicating.php b/tests/phpunit/ContentImport/Importers/PostFields/TestDuplicating.php
index 056513a7..600c11e2 100644
--- a/tests/phpunit/ContentImport/Importers/PostFields/TestDuplicating.php
+++ b/tests/phpunit/ContentImport/Importers/PostFields/TestDuplicating.php
@@ -7,7 +7,7 @@
use lloc\Msls\ContentImport\Importers\PostFields\Duplicating;
use lloc\MslsTests\MslsUnitTestCase;
-class TestDuplicating extends MslsUnitTestCase {
+final class TestDuplicating extends MslsUnitTestCase {
public function testImport(): void {
Functions\expect( 'wp_insert_post' )->once();
diff --git a/tests/phpunit/ContentImport/Importers/PostMeta/TestDuplicating.php b/tests/phpunit/ContentImport/Importers/PostMeta/TestDuplicating.php
index 98a98929..6500d39f 100644
--- a/tests/phpunit/ContentImport/Importers/PostMeta/TestDuplicating.php
+++ b/tests/phpunit/ContentImport/Importers/PostMeta/TestDuplicating.php
@@ -9,7 +9,7 @@
use function Brain\Monkey\Functions;
-class TestDuplicating extends MslsUnitTestCase {
+final class TestDuplicating extends MslsUnitTestCase {
public function testImport(): void {
Functions\expect( 'switch_to_blog' )->twice();
diff --git a/tests/phpunit/ContentImport/Importers/TestAttachmentsImporters.php b/tests/phpunit/ContentImport/Importers/TestAttachmentsImporters.php
index 3af28ae1..5dd35c50 100644
--- a/tests/phpunit/ContentImport/Importers/TestAttachmentsImporters.php
+++ b/tests/phpunit/ContentImport/Importers/TestAttachmentsImporters.php
@@ -5,7 +5,7 @@
use lloc\Msls\ContentImport\Importers\AttachmentsImporters;
use lloc\MslsTests\MslsUnitTestCase;
-class TestAttachmentsImporters extends MslsUnitTestCase {
+final class TestAttachmentsImporters extends MslsUnitTestCase {
public function testDetails(): void {
diff --git a/tests/phpunit/ContentImport/Importers/TestBaseImporter.php b/tests/phpunit/ContentImport/Importers/TestBaseImporter.php
index 2acc5a6b..fbf79787 100644
--- a/tests/phpunit/ContentImport/Importers/TestBaseImporter.php
+++ b/tests/phpunit/ContentImport/Importers/TestBaseImporter.php
@@ -8,34 +8,44 @@
use lloc\Msls\ContentImport\Relations;
use lloc\MslsTests\MslsUnitTestCase;
-class TestBaseImporter extends MslsUnitTestCase {
-
- public function setUp(): void {
- parent::setUp();
+final class TestBaseImporter extends MslsUnitTestCase {
+ private function BaseImporterFactory(): BaseImporter {
$import_coordinates = \Mockery::mock( ImportCoordinates::class );
- $this->test = new BaseImporter( $import_coordinates );
+
+ return new BaseImporter( $import_coordinates );
}
public function testImport(): void {
- $this->assertEquals( array(), $this->test->import( array() ) );
+ $test = $this->BaseImporterFactory();
+
+ $this->assertEquals( array(), $test->import( array() ) );
}
public function testSetImportCoordinates(): void {
$import_coordinates = \Mockery::mock( ImportCoordinates::class );
$this->expectNotToPerformAssertions();
- $this->test->set_import_coordinates( $import_coordinates );
+
+ $test = $this->BaseImporterFactory();
+
+ $test->set_import_coordinates( $import_coordinates );
}
public function testGetLogger(): void {
- $this->assertInstanceOf( ImportLogger::class, $this->test->get_logger() );
+ $test = $this->BaseImporterFactory();
+
+ $this->assertInstanceOf( ImportLogger::class, $test->get_logger() );
}
public function testGetRelations(): void {
- $this->assertInstanceOf( Relations::class, $this->test->get_relations() );
+ $test = $this->BaseImporterFactory();
+
+ $this->assertInstanceOf( Relations::class, $test->get_relations() );
}
public function testInfo(): void {
- $this->assertInstanceOf( \stdClass::class, $this->test->info() );
+ $test = $this->BaseImporterFactory();
+
+ $this->assertInstanceOf( \stdClass::class, $test->info() );
}
}
diff --git a/tests/phpunit/ContentImport/Importers/TestImportersBaseFactory.php b/tests/phpunit/ContentImport/Importers/TestImportersBaseFactory.php
index 92fbab14..f932615d 100644
--- a/tests/phpunit/ContentImport/Importers/TestImportersBaseFactory.php
+++ b/tests/phpunit/ContentImport/Importers/TestImportersBaseFactory.php
@@ -7,7 +7,7 @@
use lloc\MslsTests\MslsUnitTestCase;
use Mockery\Mock;
-class TestImportersBaseFactory extends MslsUnitTestCase {
+final class TestImportersBaseFactory extends MslsUnitTestCase {
public function testMake(): void {
$coordinates = \Mockery::mock( ImportCoordinates::class );
diff --git a/tests/phpunit/ContentImport/Importers/TestMap.php b/tests/phpunit/ContentImport/Importers/TestMap.php
index 93db70e7..545d439d 100644
--- a/tests/phpunit/ContentImport/Importers/TestMap.php
+++ b/tests/phpunit/ContentImport/Importers/TestMap.php
@@ -6,7 +6,7 @@
use lloc\Msls\ContentImport\Importers\Map;
use lloc\MslsTests\MslsUnitTestCase;
-class TestMap extends MslsUnitTestCase {
+final class TestMap extends MslsUnitTestCase {
public function testMake(): void {
$coordinates = \Mockery::mock( ImportCoordinates::class );
diff --git a/tests/phpunit/ContentImport/Importers/TestPostFieldsImporters.php b/tests/phpunit/ContentImport/Importers/TestPostFieldsImporters.php
index fa3dcb86..c761e0d2 100644
--- a/tests/phpunit/ContentImport/Importers/TestPostFieldsImporters.php
+++ b/tests/phpunit/ContentImport/Importers/TestPostFieldsImporters.php
@@ -8,7 +8,7 @@
use lloc\Msls\ContentImport\Importers\PostFieldsImporters;
use lloc\MslsTests\MslsUnitTestCase;
-class TestPostFieldsImporters extends MslsUnitTestCase {
+final class TestPostFieldsImporters extends MslsUnitTestCase {
public function testMake(): void {
$importer = \Mockery::mock( Duplicating::class );
diff --git a/tests/phpunit/ContentImport/Importers/TestPostMetaImporters.php b/tests/phpunit/ContentImport/Importers/TestPostMetaImporters.php
index 94cbb1fb..1b79f484 100644
--- a/tests/phpunit/ContentImport/Importers/TestPostMetaImporters.php
+++ b/tests/phpunit/ContentImport/Importers/TestPostMetaImporters.php
@@ -5,7 +5,7 @@
use lloc\Msls\ContentImport\Importers\PostMetaImporters;
use lloc\MslsTests\MslsUnitTestCase;
-class TestPostMetaImporters extends MslsUnitTestCase {
+final class TestPostMetaImporters extends MslsUnitTestCase {
public function testDetails(): void {
$test = new PostMetaImporters();
diff --git a/tests/phpunit/ContentImport/Importers/TestPostThumbnailImporters.php b/tests/phpunit/ContentImport/Importers/TestPostThumbnailImporters.php
index 42cabf56..9fc8f433 100644
--- a/tests/phpunit/ContentImport/Importers/TestPostThumbnailImporters.php
+++ b/tests/phpunit/ContentImport/Importers/TestPostThumbnailImporters.php
@@ -5,7 +5,7 @@
use lloc\Msls\ContentImport\Importers\PostThumbnailImporters;
use lloc\MslsTests\MslsUnitTestCase;
-class TestPostThumbnailImporters extends MslsUnitTestCase {
+final class TestPostThumbnailImporters extends MslsUnitTestCase {
public function testDetails(): void {
$test = new PostThumbnailImporters();
diff --git a/tests/phpunit/ContentImport/Importers/TestTermsImporters.php b/tests/phpunit/ContentImport/Importers/TestTermsImporters.php
index e0b9a21a..495d5820 100644
--- a/tests/phpunit/ContentImport/Importers/TestTermsImporters.php
+++ b/tests/phpunit/ContentImport/Importers/TestTermsImporters.php
@@ -5,7 +5,7 @@
use lloc\Msls\ContentImport\Importers\TermsImporters;
use lloc\MslsTests\MslsUnitTestCase;
-class TestTermsImporters extends MslsUnitTestCase {
+final class TestTermsImporters extends MslsUnitTestCase {
public function testDetails(): void {
$test = new TermsImporters();
diff --git a/tests/phpunit/ContentImport/LogWriters/TestAdminNoticeLogger.php b/tests/phpunit/ContentImport/LogWriters/TestAdminNoticeLogger.php
index d7665f02..038f3e4e 100644
--- a/tests/phpunit/ContentImport/LogWriters/TestAdminNoticeLogger.php
+++ b/tests/phpunit/ContentImport/LogWriters/TestAdminNoticeLogger.php
@@ -7,16 +7,12 @@
use lloc\Msls\ContentImport\LogWriters\AdminNoticeLogger;
use lloc\MslsTests\MslsUnitTestCase;
-class TestAdminNoticeLogger extends MslsUnitTestCase {
-
- public function setUp(): void {
- parent::setUp();
-
- $this->test = new AdminNoticeLogger();
- }
+final class TestAdminNoticeLogger extends MslsUnitTestCase {
public function testGetTransient(): void {
- $this->assertEquals( 'msls_last_import_log', $this->test->get_transient() );
+ $test = new AdminNoticeLogger();
+
+ $this->assertEquals( 'msls_last_import_log', $test->get_transient() );
}
public function testWrite(): void {
@@ -29,10 +25,12 @@ public function testWrite(): void {
$coordinates->dest_blog_id = 2;
$coordinates->dest_post_id = 13;
- $this->test->set_import_coordinates( $coordinates );
+ $test = new AdminNoticeLogger();
+
+ $test->set_import_coordinates( $coordinates );
$data = array( 'info', array( 'foo' ) );
- $this->test->write( $data );
+ $test->write( $data );
$this->expectNotToPerformAssertions();
}
diff --git a/tests/phpunit/ContentImport/TestAttachmentPathFinder.php b/tests/phpunit/ContentImport/TestAttachmentPathFinder.php
index 5c5daa25..91c09036 100644
--- a/tests/phpunit/ContentImport/TestAttachmentPathFinder.php
+++ b/tests/phpunit/ContentImport/TestAttachmentPathFinder.php
@@ -6,13 +6,7 @@
use lloc\MslsTests\MslsUnitTestCase;
use Brain\Monkey\Functions;
-class TestAttachmentPathFinder extends MslsUnitTestCase {
-
- public function setUp(): void {
- parent::setUp();
-
- $this->test = new AttachmentPathFinder();
- }
+final class TestAttachmentPathFinder extends MslsUnitTestCase {
public static function dataprovider_filter_srcset(): array {
$image_src = 'http://example.com/image.jpg';
@@ -42,7 +36,9 @@ public function test_filter_srcset( $source, $imageSrc, $attachmentId, $expected
Functions\expect( 'delete_post_meta' )->times( $time_dpm );
Functions\expect( 'get_blog_post' )->times( $times_gbp )->andReturn( $blog_post );
- $this->assertEquals( $expected, $this->test->filter_srcset( $source, null, $imageSrc, null, $attachmentId ) );
+ $test = new AttachmentPathFinder();
+
+ $this->assertEquals( $expected, $test->filter_srcset( $source, null, $imageSrc, null, $attachmentId ) );
}
public static function dataprovider_filter_attachement_url(): array {
@@ -71,6 +67,8 @@ public function test_filter_attachment_url( string $image_src, $source_post, int
Functions\expect( 'delete_post_meta' )->zeroOrMoreTimes();
Functions\expect( 'get_blog_post' )->zeroOrMoreTimes()->andReturn( $source_post );
- $this->assertEquals( $source_post->guid, $this->test->filter_attachment_url( $image_src, $attachment_id ) );
+ $test = new AttachmentPathFinder();
+
+ $this->assertEquals( $source_post->guid, $test->filter_attachment_url( $image_src, $attachment_id ) );
}
}
diff --git a/tests/phpunit/ContentImport/TestContentImporter.php b/tests/phpunit/ContentImport/TestContentImporter.php
index 81cab160..a94d2430 100644
--- a/tests/phpunit/ContentImport/TestContentImporter.php
+++ b/tests/phpunit/ContentImport/TestContentImporter.php
@@ -9,36 +9,41 @@
use lloc\MslsTests\MslsUnitTestCase;
use Brain\Monkey\Actions;
-class TestContentImporter extends MslsUnitTestCase {
-
-
- public function setUp(): void {
- parent::setUp();
+final class TestContentImporter extends MslsUnitTestCase {
+ private function ContentImporterFactory(): ContentImporter {
$main = \Mockery::mock( MslsMain::class );
$main->shouldReceive( 'verify_nonce' )->andReturnTrue();
- $this->test = new ContentImporter( $main );
+ return new ContentImporter( $main );
}
public function test_logger(): void {
- $this->test->set_logger( \Mockery::mock( ImportLogger::class ) );
+ $test = $this->ContentImporterFactory();
+
+ $test->set_logger( \Mockery::mock( ImportLogger::class ) );
- $this->assertInstanceOf( ImportLogger::class, $this->test->get_logger() );
+ $this->assertInstanceOf( ImportLogger::class, $test->get_logger() );
}
public function test_relations(): void {
- $this->test->set_relations( \Mockery::mock( Relations::class ) );
+ $test = $this->ContentImporterFactory();
- $this->assertInstanceOf( Relations::class, $this->test->get_relations() );
+ $test->set_relations( \Mockery::mock( Relations::class ) );
+
+ $this->assertInstanceOf( Relations::class, $test->get_relations() );
}
public function test_handle_import(): void {
- $this->assertEquals( array(), $this->test->handle_import() );
+ $test = $this->ContentImporterFactory();
+
+ $this->assertEquals( array(), $test->handle_import() );
}
public function test_parse_sources_no_post(): void {
- $this->assertFalse( $this->test->parse_sources() );
+ $test = $this->ContentImporterFactory();
+
+ $this->assertFalse( $test->parse_sources() );
}
public function test_handle_false(): void {
@@ -46,7 +51,7 @@ public function test_handle_false(): void {
Actions\expectAdded( 'msls_main_save' )->once();
- $this->test->handle( false );
+ $this->ContentImporterFactory()->handle( false );
}
public function test_handle_true(): void {
@@ -54,6 +59,6 @@ public function test_handle_true(): void {
Actions\expectRemoved( 'msls_main_save' )->once();
- $this->test->handle( true );
+ $this->ContentImporterFactory()->handle( true );
}
}
diff --git a/tests/phpunit/ContentImport/TestImportCoordinates.php b/tests/phpunit/ContentImport/TestImportCoordinates.php
index 79430cd1..44b56fb9 100644
--- a/tests/phpunit/ContentImport/TestImportCoordinates.php
+++ b/tests/phpunit/ContentImport/TestImportCoordinates.php
@@ -6,25 +6,25 @@
use lloc\MslsTests\MslsUnitTestCase;
use Brain\Monkey\Functions;
-class TestImportCoordinates extends MslsUnitTestCase {
+final class TestImportCoordinates extends MslsUnitTestCase {
+ public function ImportCoordinatesFactory(): ImportCoordinates {
+ $test = new ImportCoordinates();
- public function setUp(): void {
- parent::setUp();
+ $test->source_blog_id = 1;
+ $test->source_post_id = 42;
+ $test->dest_blog_id = 2;
+ $test->dest_post_id = 13;
+ $test->source_post = \Mockery::mock( \WP_Post::class );
+ $test->source_lang = 'de_DE';
+ $test->dest_lang = 'it_IT';
- $this->test = new ImportCoordinates();
-
- $this->test->source_blog_id = 1;
- $this->test->source_post_id = 42;
- $this->test->dest_blog_id = 2;
- $this->test->dest_post_id = 13;
- $this->test->source_post = \Mockery::mock( \WP_Post::class );
- $this->test->source_lang = 'de_DE';
- $this->test->dest_lang = 'it_IT';
+ return $test;
}
public static function providerValidate(): array {
$post = \Mockery::mock( \WP_Post::class );
+
return array(
array( null, null, null, null, null, false ),
array( $post, null, null, null, null, false ),
@@ -42,9 +42,10 @@ public function testValidate( $post_a, $post_b, $source_post, $lang_a, $lang_b,
Functions\expect( 'get_blog_post' )->andReturn( $post_a, $post_b );
Functions\expect( 'get_blog_option' )->andReturn( $lang_a, $lang_b );
- $this->test->source_post = $source_post;
+ $test = $this->ImportCoordinatesFactory();
+ $test->source_post = $source_post;
- $this->assertEquals( $expected, $this->test->validate() );
+ $this->assertEquals( $expected, $test->validate() );
}
public function testParseImportersFromPost(): void {
@@ -61,16 +62,20 @@ public function testParseImportersFromPost(): void {
->with( INPUT_GET, ImportCoordinates::IMPORTERS_GLOBAL_KEY, FILTER_FORCE_ARRAY )
->andReturn( array( 'pagesType' => 'pagesSlug' ) );
- $this->assertNull( $this->test->get_importer_for( 'pagesType' ) );
+ $test = $this->ImportCoordinatesFactory();
- $this->test->parse_importers_from_request();
+ $this->assertNull( $test->get_importer_for( 'pagesType' ) );
- $this->assertEquals( 'pagesSlug', $this->test->get_importer_for( 'pagesType' ) );
+ $test->parse_importers_from_request();
+
+ $this->assertEquals( 'pagesSlug', $test->get_importer_for( 'pagesType' ) );
}
public function testSetImporterFor(): void {
- $this->test->set_importer_for( 'postsType', 'postsSlug' );
+ $test = $this->ImportCoordinatesFactory();
+
+ $test->set_importer_for( 'postsType', 'postsSlug' );
- $this->assertEquals( 'postsSlug', $this->test->get_importer_for( 'postsType' ) );
+ $this->assertEquals( 'postsSlug', $test->get_importer_for( 'postsType' ) );
}
}
diff --git a/tests/phpunit/ContentImport/TestImportLogger.php b/tests/phpunit/ContentImport/TestImportLogger.php
index bf36a840..0707fa7b 100644
--- a/tests/phpunit/ContentImport/TestImportLogger.php
+++ b/tests/phpunit/ContentImport/TestImportLogger.php
@@ -6,15 +6,7 @@
use lloc\Msls\ContentImport\ImportLogger;
use lloc\MslsTests\MslsUnitTestCase;
-class TestImportLogger extends MslsUnitTestCase {
-
- public function setUp(): void {
- parent::setUp();
-
- $coordinates = \Mockery::mock( ImportCoordinates::class );
-
- $this->test = new ImportLogger( $coordinates );
- }
+final class TestImportLogger extends MslsUnitTestCase {
public static function provider_get_data(): array {
return array(
@@ -28,6 +20,9 @@ public static function provider_get_data(): array {
* @dataProvider provider_get_data
*/
public function test_get_data( $key ): void {
- $this->assertArrayHasKey( $key, $this->test->get_data() );
+ $coordinates = \Mockery::mock( ImportCoordinates::class );
+ $test = new ImportLogger( $coordinates );
+
+ $this->assertArrayHasKey( $key, $test->get_data() );
}
}
diff --git a/tests/phpunit/ContentImport/TestMetaBox.php b/tests/phpunit/ContentImport/TestMetaBox.php
index e7f79684..b9a45d35 100644
--- a/tests/phpunit/ContentImport/TestMetaBox.php
+++ b/tests/phpunit/ContentImport/TestMetaBox.php
@@ -4,17 +4,29 @@
use lloc\Msls\ContentImport\MetaBox;
use lloc\MslsTests\MslsUnitTestCase;
+use Brain\Monkey\Functions;
-class TestMetaBox extends MslsUnitTestCase {
+final class TestMetaBox extends MslsUnitTestCase {
+ public function test_render(): void {
+ $post = \Mockery::mock( 'WP_Post' );
+ $post->ID = 1;
- public function setUp(): void {
- parent::setUp();
+ Functions\expect( 'get_post' )->once()->andReturn( $post );
+ Functions\expect( 'get_option' )->twice()->andReturn( array() );
+ Functions\expect( 'get_available_languages' )->once()->andReturn( array() );
+ Functions\expect( 'get_current_blog_id' )->once()->andReturn( 1 );
+ Functions\expect( 'get_blog_option' )->once()->andReturn( 'de_DE' );
+ Functions\expect( 'msls_blog_collection' )->once()->andReturn( array() );
- $this->test = new MetaBox();
+ $expected = '
No translated versions linked to this post: import content functionality is disabled.
';
+
+ ( new MetaBox() )->render();
+
+ $this->expectOutputString( $expected );
}
public function test_print_modal_html(): void {
- $this->assertEquals( '', $this->test->print_modal_html() );
+ $this->assertEquals( '', ( new MetaBox() )->print_modal_html() );
}
}
diff --git a/tests/phpunit/ContentImport/TestRelations.php b/tests/phpunit/ContentImport/TestRelations.php
index 0ccc81d9..fe5989ae 100644
--- a/tests/phpunit/ContentImport/TestRelations.php
+++ b/tests/phpunit/ContentImport/TestRelations.php
@@ -6,17 +6,12 @@
use lloc\Msls\ContentImport\Relations;
use lloc\MslsTests\MslsUnitTestCase;
-class TestRelations extends MslsUnitTestCase {
-
- public function setUp(): void {
- parent::setUp();
+final class TestRelations extends MslsUnitTestCase {
+ public function test_get_data(): void {
$coordinates = \Mockery::mock( ImportCoordinates::class );
+ $test = new Relations( $coordinates );
- $this->test = new Relations( $coordinates );
- }
-
- public function test_get_data(): void {
- $this->assertIsArray( $this->test->get_data() );
+ $this->assertIsArray( $test->get_data() );
}
}
diff --git a/tests/phpunit/ContentImport/TestService.php b/tests/phpunit/ContentImport/TestService.php
index 76f49daf..01af4c50 100644
--- a/tests/phpunit/ContentImport/TestService.php
+++ b/tests/phpunit/ContentImport/TestService.php
@@ -7,7 +7,7 @@
use lloc\MslsTests\MslsUnitTestCase;
use Brain\Monkey\Functions;
-class TestService extends MslsUnitTestCase {
+final class TestService extends MslsUnitTestCase {
public function test_register_not_active_false(): void {
$options = \Mockery::mock( MslsOptions::class );
diff --git a/tests/phpunit/Map/TestHrefLang.php b/tests/phpunit/Map/TestHrefLang.php
index 17e8f1e6..c16ac528 100644
--- a/tests/phpunit/Map/TestHrefLang.php
+++ b/tests/phpunit/Map/TestHrefLang.php
@@ -9,11 +9,9 @@
use lloc\Msls\MslsBlogCollection;
use lloc\MslsTests\MslsUnitTestCase;
-class TestHrefLang extends MslsUnitTestCase {
-
- protected function setUp(): void {
- parent::setUp();
+final class TestHrefLang extends MslsUnitTestCase {
+ private function HrefLangFactory(): HrefLang {
$map = array(
'de_DE' => 'de',
'de_DE_formal' => 'de',
@@ -26,12 +24,8 @@ protected function setUp(): void {
foreach ( $map as $locale => $alpha2 ) {
$blog = \Mockery::mock( MslsBlog::class );
- $blog->shouldReceive(
- array(
- 'get_alpha2' => $alpha2,
- 'get_language' => $locale,
- )
- );
+ $blog->shouldReceive( 'get_alpha2' )->andReturn( $alpha2 );
+ $blog->shouldReceive( 'get_language' )->andReturn( $locale );
$blogs[] = $blog;
}
@@ -39,23 +33,27 @@ protected function setUp(): void {
$collection = \Mockery::mock( MslsBlogCollection::class );
$collection->shouldReceive( 'get_objects' )->andReturn( $blogs );
- $this->test = new HrefLang( $collection );
+ return new HrefLang( $collection );
}
public function test_get(): void {
- $this->assertEquals( 'de-DE', $this->test->get( 'de_DE' ) );
- $this->assertEquals( 'de-DE', $this->test->get( 'de_DE_formal' ) );
- $this->assertEquals( 'fr', $this->test->get( 'fr_FR' ) );
- $this->assertEquals( 'es', $this->test->get( 'es_ES' ) );
- $this->assertEquals( 'cat', $this->test->get( 'cat' ) );
- $this->assertEquals( 'en-GB', $this->test->get( 'en_GB' ) );
- $this->assertEquals( 'en-US', $this->test->get( 'en_US' ) );
+ $test = $this->HrefLangFactory();
+
+ $this->assertEquals( 'de-DE', $test->get( 'de_DE' ) );
+ $this->assertEquals( 'de-DE', $test->get( 'de_DE_formal' ) );
+ $this->assertEquals( 'fr', $test->get( 'fr_FR' ) );
+ $this->assertEquals( 'es', $test->get( 'es_ES' ) );
+ $this->assertEquals( 'cat', $test->get( 'cat' ) );
+ $this->assertEquals( 'en-GB', $test->get( 'en_GB' ) );
+ $this->assertEquals( 'en-US', $test->get( 'en_US' ) );
}
public function test_get_has_filter(): void {
Functions\when( 'has_filter' )->justReturn( true );
Filters\expectApplied( 'msls_head_hreflang' )->once()->with( 'en_US' )->andReturn( 'en-US' );
- $this->assertEquals( 'en-US', $this->test->get( 'en_US' ) );
+ $test = $this->HrefLangFactory();
+
+ $this->assertEquals( 'en-US', $test->get( 'en_US' ) );
}
}
diff --git a/tests/phpunit/MslsUnitTestCase.php b/tests/phpunit/MslsUnitTestCase.php
index 984a92d1..8f5cbba0 100644
--- a/tests/phpunit/MslsUnitTestCase.php
+++ b/tests/phpunit/MslsUnitTestCase.php
@@ -8,13 +8,6 @@
class MslsUnitTestCase extends TestCase {
- /**
- * Instance of the class to test
- *
- * @var object $test
- */
- protected object $test;
-
protected function setUp(): void {
parent::setUp();
Monkey\setUp();
diff --git a/tests/phpunit/Query/TestTranslatedPostsQuery.php b/tests/phpunit/Query/TestTranslatedPostsQuery.php
index 969265c1..3eb17eac 100644
--- a/tests/phpunit/Query/TestTranslatedPostsQuery.php
+++ b/tests/phpunit/Query/TestTranslatedPostsQuery.php
@@ -6,7 +6,7 @@
use lloc\Msls\Query\TranslatedPostIdQuery;
use lloc\MslsTests\MslsUnitTestCase;
-class TestTranslatedPostsQuery extends MslsUnitTestCase {
+final class TestTranslatedPostsQuery extends MslsUnitTestCase {
public function test_invoke_empty_string(): void {
$sql_cache = \Mockery::mock( MslsSqlCacher::class );
diff --git a/tests/phpunit/TestMslsAdmin.php b/tests/phpunit/TestMslsAdmin.php
index 2322589d..9bc436c8 100644
--- a/tests/phpunit/TestMslsAdmin.php
+++ b/tests/phpunit/TestMslsAdmin.php
@@ -8,13 +8,9 @@
use lloc\Msls\MslsBlogCollection;
use lloc\Msls\MslsOptions;
-class TestMslsAdmin extends MslsUnitTestCase {
+final class TestMslsAdmin extends MslsUnitTestCase {
- /**
- * @param array $users
- * @return MslsAdmin
- */
- public function get_sut( array $users = array() ): MslsAdmin {
+ private function MslsAdminFactory( array $users = array() ): MslsAdmin {
Functions\when( 'get_option' )->justReturn( array() );
Functions\when( 'update_option' )->justReturn( true );
Functions\when( 'get_current_blog_id' )->justReturn( 1 );
@@ -88,23 +84,22 @@ public function test_has_problems( array $languages, bool $is_empty, string $reg
}
public function test_subsubsub(): void {
- $obj = $this->get_sut();
+ $obj = $this->MslsAdminFactory();
- $this->assertEquals(
- '',
- $obj->subsubsub()
- );
+ $expected = '';
+
+ $this->assertEquals( $expected, $obj->subsubsub() );
}
public function test_blog_language(): void {
- $obj = $this->get_sut();
+ $obj = $this->MslsAdminFactory();
$this->expectOutputRegex( '/^