-
Notifications
You must be signed in to change notification settings - Fork 59
Add ability to pass extensions to make-json command
#439
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
Merged
swissspidy
merged 4 commits into
wp-cli:main
from
michaelw85:#231_add_custom_extension_support
Apr 25, 2025
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Add ability to pass extensions to make json command
- Loading branch information
commit 380b36cb2d1390c9e9532e024b2a908644b9812c
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| <?php | ||
|
|
||
|
|
||
| namespace WP_CLI\I18n\Tests; | ||
|
|
||
| use ReflectionClass; | ||
| use ReflectionMethod; | ||
| use WP_CLI\I18n\MakeJsonCommand; | ||
| use WP_CLI\Tests\TestCase; | ||
| use WP_CLI\Utils; | ||
|
|
||
| class MakeJsonTest extends TestCase { | ||
| /** @var string A path files are located */ | ||
| private static $base; | ||
| /** @var \PHPUnit\Framework\MockObject\MockObject MakeJsonCommand partial mock */ | ||
| private static $mock = null; | ||
| /** @var \ReflectionMethod make_json reflection (private) */ | ||
| private static $make_json = null; | ||
|
|
||
| public function set_up() { | ||
| parent::set_up(); | ||
|
|
||
| /** | ||
| * PHP5.4 cannot set property with __DIR__ constant. | ||
| * Shamelessly stolen from @see IterableCodeExtractorTest.php | ||
| */ | ||
| self::$base = Utils\normalize_path( __DIR__ ) . '/data/make_json/'; | ||
michaelw85 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| self::$mock = $this->createPartialMock( MakeJsonCommand::class, [ 'build_json_files' ] ); | ||
|
|
||
| $reflection = new ReflectionClass( self::$mock ); | ||
| self::$make_json = $reflection->getMethod( 'make_json' ); | ||
| self::$make_json->setAccessible( true ); | ||
| } | ||
|
|
||
| public function test_no_custom_extensions() { | ||
| self::$mock | ||
| ->expects( $this->once() ) | ||
| ->method( 'build_json_files' ) | ||
| ->with( | ||
| $this->callback( | ||
| function ( $mapping ) { | ||
| $this->assertEquals( array_keys( $mapping ), [ 'baz.js', 'qux.js' ] ); | ||
|
|
||
| return true; | ||
| } | ||
| ), | ||
| $this->isType( 'string' ), | ||
| $this->isType( 'string' ) | ||
| ) | ||
| ->willReturn( [] ); | ||
|
|
||
| self::$make_json->invoke( self::$mock, self::$base . 'translations.po', 'bar', null, '', [] ); | ||
| } | ||
|
|
||
| public function test_with_custom_extensions() { | ||
| self::$mock | ||
| ->expects( $this->once() ) | ||
| ->method( 'build_json_files' ) | ||
| ->with( | ||
| $this->callback( | ||
| function ( $mapping ) { | ||
| $this->assertEquals( array_keys( $mapping ), [ 'foo.ts', 'bar.tag', 'baz.js', 'qux.js' ] ); | ||
|
|
||
| return true; | ||
| } | ||
| ), | ||
| $this->isType( 'string' ), | ||
| $this->isType( 'string' ) | ||
| ) | ||
| ->willReturn( [] ); | ||
|
|
||
| self::$make_json->invoke( self::$mock, self::$base . 'translations.po', 'bar', null, '', [ 'tag', 'ts' ] ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| msgid "" | ||
| msgstr "" | ||
| "Project-Id-Version: \n" | ||
| "Report-Msgid-Bugs-To: \n" | ||
| "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
| "Language-Team: LANGUAGE <LL@li.org>\n" | ||
| "MIME-Version: 1.0\n" | ||
| "Content-Type: text/plain; charset=UTF-8\n" | ||
| "Content-Transfer-Encoding: 8bit\n" | ||
| "POT-Creation-Date: 2025-04-25T10:38:48+02:00\n" | ||
| "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | ||
| "X-Generator: WP-CLI 2.11.0\n" | ||
| "X-Domain: ts\n" | ||
|
|
||
| #: foo.ts:1 | ||
| msgid "Hello TS" | ||
| msgstr "" | ||
|
|
||
| #: bar.tag:2 | ||
| msgid "Hello TAG" | ||
| msgstr "" | ||
|
|
||
| #: baz.js:3 | ||
| msgid "Hello JS" | ||
| msgstr "" | ||
|
|
||
| #: qux.min.js:4 | ||
| msgid "Hello Minified JS" | ||
| msgstr "" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.