-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolves #3
- Loading branch information
Showing
3 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,59 @@ | ||
<?php | ||
|
||
namespace Major\Fluent\Laravel\Tests; | ||
|
||
use Major\Fluent\Exceptions\Bundle\FunctionExistsException; | ||
use Major\Fluent\Exceptions\Resolver\ReferenceException; | ||
|
||
final class FunctionsTest extends TestCase | ||
{ | ||
/** | ||
* @testdox function can be used | ||
*/ | ||
public function testUsage(): void | ||
{ | ||
$this->translator->addFunction('CONCAT', fn (string ...$args) => implode($args)); | ||
|
||
$this->assertSame('FooBar', __('functions.strings')); | ||
} | ||
|
||
/** | ||
* @testdox arguments can be passed to function | ||
*/ | ||
public function testArguments(): void | ||
{ | ||
$this->translator->addFunction('CONCAT', fn (string ...$args) => implode($args)); | ||
|
||
$this->assertSame('BarBaz', __('functions.args', ['foo' => 'Bar', 'bar' => 'Baz'])); | ||
} | ||
|
||
/** | ||
* @testdox function can not be registered twice | ||
*/ | ||
public function testRegisterTwice(): void | ||
{ | ||
$this->expectException(FunctionExistsException::class); | ||
$this->expectExceptionMessage('Attempt to override an existing function: CONCAT().'); | ||
|
||
$this->translator->addFunction('CONCAT', fn (string ...$args) => implode($args)); | ||
$this->translator->addFunction('CONCAT', fn (string ...$args) => implode(', ', $args)); | ||
} | ||
|
||
/** | ||
* @testdox function can be registered after bundle is resolved | ||
*/ | ||
public function testLateRegistration(): void | ||
{ | ||
try { | ||
$this->assertSame('FooBar', __('functions.strings')); | ||
|
||
$this->fail('Exception should have been thrown.'); | ||
} catch (ReferenceException $e) { | ||
$this->assertSame('Unknown function: CONCAT().', $e->getMessage()); | ||
} | ||
|
||
$this->translator->addFunction('CONCAT', fn (string ...$args) => implode($args)); | ||
|
||
$this->assertSame('FooBar', __('functions.strings')); | ||
} | ||
} |
This file contains 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,2 @@ | ||
strings = { CONCAT("Foo", "Bar") } | ||
args = { CONCAT($foo, $bar) } |