*/ public static function preservedValueProvider() { return [ 'integer zero' => [0, 'v=0'], 'string zero' => ['0', 'v=0'], 'float zero' => [0.0, 'v=0'], 'negative' => [-5, 'v=-5'], 'positive integer' => [5, 'v=5'], 'float' => [2.5, 'v=2.5'], 'string zero decimal' => ['0.0', 'v=0.0'], ]; } /** * @dataProvider preservedValueProvider * * @param mixed $replace * @param string $expected * * @return void */ public function testNumericValuesSurviveSubstitution($replace, $expected): void { $this->assertSame($expected, thold_str_replace('', $replace, 'v=')); } /** * @return array */ public static function absentValueProvider() { return [ 'null' => [null], 'false' => [false], 'empty string' => [''], ]; } /** * @dataProvider absentValueProvider * * @param mixed $replace * * @return void */ public function testAbsentValuesBecomeEmpty($replace): void { $this->assertSame('v=', thold_str_replace('', $replace, 'v=')); } /** * @return void */ public function testEveryOccurrenceIsReplaced(): void { $this->assertSame('0 and 0', thold_str_replace('', 0, ' and ')); } /** * @return void */ public function testSubjectWithoutTheTagIsUnchanged(): void { $this->assertSame('no tags here', thold_str_replace('', 5, 'no tags here')); } /** * @return void */ public function testNullableSubjectIsNormalizedAtTheBoundary(): void { $deprecations = []; set_error_handler(static function ($severity, $message) use (&$deprecations) { if ($severity === E_DEPRECATED) { $deprecations[] = $message; return true; } return false; }); try { $this->assertSame('', thold_str_replace('', 'value', null)); $this->assertSame('', thold_str_replace('', null, null)); } finally { restore_error_handler(); } $this->assertSame([], $deprecations); } }