From e4355eee9b1ed1b68ae236a73c2d0ab25b0588c1 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 14 Jul 2021 12:29:20 +0200 Subject: [PATCH 1/6] Use `set_up()` / `tear_down()` methods in test class As suggested by `Yoast/PHPUnit-Polyfills` --- tests/IterableCodeExtractorTest.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/IterableCodeExtractorTest.php b/tests/IterableCodeExtractorTest.php index 85fcc03d..a55f294a 100644 --- a/tests/IterableCodeExtractorTest.php +++ b/tests/IterableCodeExtractorTest.php @@ -11,7 +11,9 @@ class IterableCodeExtractorTest extends TestCase { /** @var string A path files are located */ private static $base; - public function setUp() { + public function set_up() { + parent::set_up(); + /** * PHP5.4 cannot set property with __DIR__ constant. */ @@ -23,10 +25,12 @@ public function setUp() { $property->setAccessible( false ); } - public function tearDown() { + public function tear_down() { if ( file_exists( self::$base . '/symlinked' ) ) { unlink( self::$base . '/symlinked' ); } + + parent::tear_down(); } public function test_can_include_files() { From cdcf9590baaedee8037886a26959cad7f79f7835 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 14 Jul 2021 12:29:43 +0200 Subject: [PATCH 2/6] Use `TestCase` class in PHPUnit test --- tests/PotGeneratorTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/PotGeneratorTest.php b/tests/PotGeneratorTest.php index c27eed89..6c190a11 100644 --- a/tests/PotGeneratorTest.php +++ b/tests/PotGeneratorTest.php @@ -5,9 +5,9 @@ use Gettext\Translation; use WP_CLI\I18n\PotGenerator; use Gettext\Translations; -use PHPUnit_Framework_TestCase; +use WP_CLI\Tests\TestCase; -class PotGeneratorTest extends PHPUnit_Framework_TestCase { +class PotGeneratorTest extends TestCase { public function test_adds_correct_amount_of_plural_strings() { $translations = new Translations(); From 7dad7116483fa5ec691b24cb461ec317195ec814 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 14 Jul 2021 12:29:57 +0200 Subject: [PATCH 3/6] Use more accurate `assertStringContainsString` --- tests/PotGeneratorTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/PotGeneratorTest.php b/tests/PotGeneratorTest.php index 6c190a11..2e7ff389 100644 --- a/tests/PotGeneratorTest.php +++ b/tests/PotGeneratorTest.php @@ -17,9 +17,9 @@ public function test_adds_correct_amount_of_plural_strings() { $result = PotGenerator::toString( $translations ); - $this->assertContains( 'msgid "%d cat"', $result ); - $this->assertContains( 'msgid_plural "%d cats"', $result ); - $this->assertContains( 'msgstr[0] ""', $result ); - $this->assertContains( 'msgstr[1] ""', $result ); + $this->assertStringContainsString( 'msgid "%d cat"', $result ); + $this->assertStringContainsString( 'msgid_plural "%d cats"', $result ); + $this->assertStringContainsString( 'msgstr[0] ""', $result ); + $this->assertStringContainsString( 'msgstr[1] ""', $result ); } } From 936b79afb7b25c290b76ec9838312c6e24912975 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 14 Jul 2021 12:30:10 +0200 Subject: [PATCH 4/6] Add terstsuite name --- phpunit.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index 62aa1e11..554e30d8 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,7 +8,7 @@ beStrictAboutTodoAnnotatedTests="true" colors="true" verbose="true"> - + tests From edbce5334125242e05918cc9f9c5e4053ebd863a Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 14 Jul 2021 12:32:04 +0200 Subject: [PATCH 5/6] Add check for `ParsedComment` --- src/PotGenerator.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/PotGenerator.php b/src/PotGenerator.php index 743960a4..45a70654 100644 --- a/src/PotGenerator.php +++ b/src/PotGenerator.php @@ -4,6 +4,7 @@ use Gettext\Generators\Po as PoGenerator; use Gettext\Translations; +use Gettext\Utils\ParsedComment; /** * POT file generator. @@ -57,8 +58,9 @@ public static function toString( Translations $translations, array $options = [] } if ( $translation->hasExtractedComments() ) { + /** @var ParsedComment|string $comment */ foreach ( $translation->getExtractedComments() as $comment ) { - $lines[] = '#. ' . $comment; + $lines[] = '#. ' . ( $comment instanceof ParsedComment ? $comment->getComment() : $comment ); } } From da5960a95cb4f261277a898e19e594394f60c126 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 15 Jul 2021 12:23:53 +0200 Subject: [PATCH 6/6] Add missing check --- src/MakePotCommand.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/MakePotCommand.php b/src/MakePotCommand.php index 84aa284e..f29a2c79 100644 --- a/src/MakePotCommand.php +++ b/src/MakePotCommand.php @@ -6,6 +6,7 @@ use Gettext\Merge; use Gettext\Translation; use Gettext\Translations; +use Gettext\Utils\ParsedComment; use WP_CLI; use WP_CLI_Command; use WP_CLI\Utils; @@ -677,10 +678,10 @@ protected function audit_strings( $translations ) { $comments = array_filter( $comments, function ( $comment ) { - /** @var string $comment */ + /** @var ParsedComment|string $comment */ /** @var string $file_header */ foreach ( $this->get_file_headers( $this->project_type ) as $file_header ) { - if ( 0 === strpos( $comment, $file_header ) ) { + if ( 0 === strpos( ( $comment instanceof ParsedComment ? $comment->getComment() : $comment ), $file_header ) ) { return null; } }