53 lines
1.2 KiB
PHP
53 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Integration\WithApp\Helpers;
|
|
|
|
use App\Lib\Helpers\ToolboxHelperCore;
|
|
|
|
it('returns false when replace is array but search is string', function (): void {
|
|
// GIVEN
|
|
$count = 0;
|
|
|
|
// WHEN
|
|
$result = ToolboxHelperCore::mbReplace('a', ['b'], 'aaa', $count);
|
|
|
|
// THEN
|
|
expect($result)->toBeFalse();
|
|
});
|
|
|
|
it('replaces recursively in nested array subject', function (): void {
|
|
// GIVEN
|
|
$count = 0;
|
|
$subject = ['a.b', ['a.b', 'z']];
|
|
|
|
// WHEN
|
|
$result = ToolboxHelperCore::mbReplace('.', '-', $subject, $count);
|
|
|
|
// THEN
|
|
expect($result)->toBe(['a-b', ['a-b', 'z']])
|
|
->and($count)->toBe(0);
|
|
});
|
|
|
|
it('replaces with search array and scalar replacement', function (): void {
|
|
// GIVEN
|
|
$count = 0;
|
|
|
|
// WHEN
|
|
$result = ToolboxHelperCore::mbReplace(['ab', 'cd'], '_', 'ab-cd', $count);
|
|
|
|
// THEN
|
|
expect($result)->toBe('_-_');
|
|
});
|
|
|
|
it('replaces with paired search and replace arrays', function (): void {
|
|
// GIVEN
|
|
$count = 0;
|
|
|
|
// WHEN
|
|
$result = ToolboxHelperCore::mbReplace(['ab', 'cd'], ['X', 'Y'], 'ab-cd', $count);
|
|
|
|
// THEN
|
|
expect($result)->toBe('X-Y');
|
|
});
|