‪TYPO3CMS  11.5
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 
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪FloatConverterTest extends UnitTestCase
30 {
34  protected ‪$converter;
35 
36  protected function ‪setUp(): void
37  {
38  parent::setUp();
39  $this->converter = new ‪FloatConverter();
40  }
41 
45  public function ‪checkMetadata(): void
46  {
47  self::assertEquals(['float', 'integer', 'string'], $this->converter->getSupportedSourceTypes(), 'Source types do not match');
48  self::assertEquals('float', $this->converter->getSupportedTargetType(), 'Target type does not match');
49  self::assertEquals(10, $this->converter->getPriority(), 'Priority does not match');
50  }
51 
55  public function ‪convertFromShouldCastTheStringToFloat(): void
56  {
57  self::assertSame(1.5, $this->converter->convertFrom('1.5', 'float'));
58  }
59 
64  {
65  self::assertNull($this->converter->convertFrom('', 'float'));
66  }
67 
71  public function ‪convertFromShouldAcceptIntegers(): void
72  {
73  self::assertSame((float)123, $this->converter->convertFrom(123, 'float'));
74  }
75 
79  public function ‪convertFromShouldRespectConfiguration(): void
80  {
81  $mockMappingConfiguration = $this->createMock(PropertyMappingConfigurationInterface::class);
82  $mockMappingConfiguration
83  ->expects(self::exactly(2))
84  ->method('getConfigurationValue')
85  ->withConsecutive(
87  [FloatConverter::class, ‪FloatConverter::CONFIGURATION_DECIMAL_POINT]
88  )
89  ->willReturnOnConsecutiveCalls('.', ',');
90  self::assertSame(1024.42, $this->converter->convertFrom('1.024,42', 'float', [], $mockMappingConfiguration));
91  }
92 
97  {
98  self::assertInstanceOf(Error::class, $this->converter->convertFrom('not numeric', 'float'));
99  }
100 
104  public function ‪canConvertFromShouldReturnTrue(): void
105  {
106  self::assertTrue($this->converter->canConvertFrom('1.5', 'float'));
107  }
108 
113  {
114  self::assertTrue($this->converter->canConvertFrom('', 'integer'));
115  }
116 
120  public function ‪canConvertFromShouldReturnTrueForANullValue(): void
121  {
122  self::assertTrue($this->converter->canConvertFrom(null, 'integer'));
123  }
124 
129  {
130  self::assertEquals([], $this->converter->getSourceChildPropertiesToBeConverted('myString'));
131  }
132 }
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\canConvertFromShouldReturnTrueForAnEmptyValue
‪canConvertFromShouldReturnTrueForAnEmptyValue()
Definition: FloatConverterTest.php:111
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\convertFromReturnsNullIfEmptyStringSpecified
‪convertFromReturnsNullIfEmptyStringSpecified()
Definition: FloatConverterTest.php:62
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\$converter
‪TypeConverterInterface $converter
Definition: FloatConverterTest.php:33
‪TYPO3\CMS\Extbase\Property\TypeConverterInterface
Definition: TypeConverterInterface.php:26
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\canConvertFromShouldReturnTrue
‪canConvertFromShouldReturnTrue()
Definition: FloatConverterTest.php:103
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\convertFromShouldRespectConfiguration
‪convertFromShouldRespectConfiguration()
Definition: FloatConverterTest.php:78
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\convertFromShouldAcceptIntegers
‪convertFromShouldAcceptIntegers()
Definition: FloatConverterTest.php:70
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter
Definition: ArrayConverterTest.php:18
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\canConvertFromShouldReturnTrueForANullValue
‪canConvertFromShouldReturnTrueForANullValue()
Definition: FloatConverterTest.php:119
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface
Definition: PropertyMappingConfigurationInterface.php:22
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\checkMetadata
‪checkMetadata()
Definition: FloatConverterTest.php:44
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\convertFromReturnsAnErrorIfSpecifiedStringIsNotNumeric
‪convertFromReturnsAnErrorIfSpecifiedStringIsNotNumeric()
Definition: FloatConverterTest.php:95
‪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:30
‪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:54
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\getSourceChildPropertiesToBeConvertedShouldReturnEmptyArray
‪getSourceChildPropertiesToBeConvertedShouldReturnEmptyArray()
Definition: FloatConverterTest.php:127
‪TYPO3\CMS\Extbase\Property\TypeConverter\FloatConverter\CONFIGURATION_THOUSANDS_SEPARATOR
‪const CONFIGURATION_THOUSANDS_SEPARATOR
Definition: FloatConverter.php:33
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\setUp
‪setUp()
Definition: FloatConverterTest.php:35