ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
StringTransformationTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use PHPUnit\Framework\TestCase;
25use stdClass;
26use PHPUnit\Framework\Attributes\DataProvider;
27
28class StringTransformationTest extends TestCase
29{
31
32 protected function setUp(): void
33 {
34 $this->transformation = new StringTransformation();
35 }
36
37 #[DataProvider('StringTestDataProvider')]
38 public function testStringTransformation(mixed $originVal, string $expectedVal): void
39 {
40 $transformedValue = $this->transformation->transform($originVal);
41 $this->assertIsString($transformedValue);
42 $this->assertEquals($expectedVal, $transformedValue);
43 }
44
45 public static function StringTestDataProvider(): array
46 {
47 $obj = new class () extends stdClass {
48 public function __toString()
49 {
50 return 'an object';
51 }
52 };
53 return [
54 'string_val' => ['hello', 'hello'],
55 'int_val' => [300, '300'],
56 'neg_int_val' => [-300, '-300'],
57 'zero_int_val' => [0, '0'],
58 'pos_bool' => [true, 'true'],
59 'neg_bool' => [false, 'false'],
60 'float_val' => [20.5, '20.5'],
61 'object_val' => [$obj, 'an object']
62 ];
63 }
64}