‪TYPO3CMS  ‪main
FloatConverterTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
26 final class ‪FloatConverterTest extends UnitTestCase
27 {
28  #[Test]
30  {
31  self::assertSame(1.5, (new ‪FloatConverter())->convertFrom('1.5', 'float'));
32  }
33 
34  #[Test]
36  {
37  self::assertNull((new ‪FloatConverter())->convertFrom('', 'float'));
38  }
39 
40  #[Test]
41  public function ‪convertFromShouldAcceptIntegers(): void
42  {
43  self::assertSame((float)123, (new ‪FloatConverter())->convertFrom(123, 'float'));
44  }
45 
46  #[Test]
48  {
49  $mockMappingConfiguration = $this->createMock(PropertyMappingConfigurationInterface::class);
50  $series = [
51  [FloatConverter::class, ‪FloatConverter::CONFIGURATION_THOUSANDS_SEPARATOR, '.'],
52  [FloatConverter::class, ‪FloatConverter::CONFIGURATION_DECIMAL_POINT, ','],
53  ];
54  $mockMappingConfiguration
55  ->expects(self::exactly(2))
56  ->method('getConfigurationValue')
57  ->willReturnCallback(function (string $class, string $key) use (&$series): string {
58  $arguments = array_shift($series);
59  self::assertSame($class, $arguments[0]);
60  self::assertSame($key, $arguments[1]);
61  return $arguments[2];
62  });
63  self::assertSame(1024.42, (new ‪FloatConverter())->convertFrom('1.024,42', 'float', [], $mockMappingConfiguration));
64  }
65 
66  #[Test]
68  {
69  self::assertInstanceOf(Error::class, (new ‪FloatConverter())->convertFrom('not numeric', 'float'));
70  }
71 
72  #[Test]
74  {
75  self::assertEquals([], (new ‪FloatConverter())->getSourceChildPropertiesToBeConverted('myString'));
76  }
77 }
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\convertFromReturnsNullIfEmptyStringSpecified
‪convertFromReturnsNullIfEmptyStringSpecified()
Definition: FloatConverterTest.php:35
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\convertFromShouldRespectConfiguration
‪convertFromShouldRespectConfiguration()
Definition: FloatConverterTest.php:47
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\convertFromShouldAcceptIntegers
‪convertFromShouldAcceptIntegers()
Definition: FloatConverterTest.php:41
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter
Definition: ArrayConverterTest.php:18
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface
Definition: PropertyMappingConfigurationInterface.php:22
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\convertFromReturnsAnErrorIfSpecifiedStringIsNotNumeric
‪convertFromReturnsAnErrorIfSpecifiedStringIsNotNumeric()
Definition: FloatConverterTest.php:67
‪TYPO3\CMS\Extbase\Error\Error
Definition: Error.php:25
‪TYPO3\CMS\Extbase\Property\TypeConverter\FloatConverter
Definition: FloatConverter.php:29
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest
Definition: FloatConverterTest.php:27
‪TYPO3\CMS\Extbase\Property\TypeConverter\FloatConverter\CONFIGURATION_DECIMAL_POINT
‪const CONFIGURATION_DECIMAL_POINT
Definition: FloatConverter.php:38
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\convertFromShouldCastTheStringToFloat
‪convertFromShouldCastTheStringToFloat()
Definition: FloatConverterTest.php:29
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\getSourceChildPropertiesToBeConvertedShouldReturnEmptyArray
‪getSourceChildPropertiesToBeConvertedShouldReturnEmptyArray()
Definition: FloatConverterTest.php:73
‪TYPO3\CMS\Extbase\Property\TypeConverter\FloatConverter\CONFIGURATION_THOUSANDS_SEPARATOR
‪const CONFIGURATION_THOUSANDS_SEPARATOR
Definition: FloatConverter.php:33