ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
StringTransformationTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
25 use stdClass;
27 
28 class 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 }