-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from MortalFlesh/feature/require-php82
Require php8.2
- Loading branch information
Showing
6 changed files
with
109 additions
and
8 deletions.
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
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
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,61 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace MF\Stringify; | ||
|
||
/** | ||
* @group unit | ||
*/ | ||
class SprintfTest extends AbstractTestCase | ||
{ | ||
/** @dataProvider provideValues */ | ||
public function testShouldFormatValuesToString(string $format, array $args, string $expected): void | ||
{ | ||
$result = sprintf($format, ...$args); | ||
|
||
$this->assertSame($expected, $result); | ||
} | ||
|
||
public static function provideValues(): iterable | ||
{ | ||
return [ | ||
'empty' => ['', [], ''], | ||
'string' => ['%s', ['foo'], 'foo'], | ||
'string with multiple args' => ['%s %s', ['foo', 'bar'], 'foo bar'], | ||
'string with numbers' => ['%s %d', ['foo', 42], 'foo 42'], | ||
'string with float' => ['%s %f', ['foo', 42.42], 'foo 42.420000'], | ||
'string with bool' => ['%s %b', ['foo', true], 'foo 1'], | ||
'string with array' => ['%s %A', ['foo', [1, 2, 3]], 'foo [1, 2, 3]'], | ||
'string with multiple arrays' => [ | ||
'%s %A %A', | ||
['foo', [1, 2, 3], ['foo' => 'bar']], | ||
'foo [1, 2, 3] ["foo" => "bar"]', | ||
], | ||
'string with object' => ['%s %A', ['foo', new \stdClass()], 'foo stdClass'], | ||
'string with text and values' => [ | ||
'Hello %A, your age is %A', | ||
['Jon', 42], | ||
'Hello "Jon", your age is 42', | ||
], | ||
'string with more values than placeholders' => [ | ||
'Hello %A, your age is %d', | ||
['Jon', 42, 3, 2, 1], | ||
'Hello "Jon", your age is 42', | ||
], | ||
'string with % in it' => [ | ||
'Hello %A, your age is %d%% and that %% is not a placeholder', | ||
['Jon', 42], | ||
'Hello "Jon", your age is 42% and that % is not a placeholder', | ||
], | ||
'string with % followed by a char in it' => [ | ||
'Hello %A, your age is %d%% and that %%char is not a placeholder', | ||
['Jon', 42], | ||
'Hello "Jon", your age is 42% and that %char is not a placeholder', | ||
], | ||
'string with % followed by the A char in it' => [ | ||
'Hello %A, your age is %d%% and that %%A char is not a placeholder', | ||
['Jon', 42], | ||
'Hello "Jon", your age is 42% and that %A char is not a placeholder', | ||
], | ||
]; | ||
} | ||
} |