‪TYPO3CMS  11.5
IntegerConverterTest.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 
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪IntegerConverterTest extends UnitTestCase
29 {
33  protected ‪$converter;
34 
35  protected function ‪setUp(): void
36  {
37  parent::setUp();
38  $this->converter = new ‪IntegerConverter();
39  }
40 
44  public function ‪checkMetadata(): void
45  {
46  self::assertEquals(['integer', 'string'], $this->converter->getSupportedSourceTypes(), 'Source types do not match');
47  self::assertEquals('integer', $this->converter->getSupportedTargetType(), 'Target type does not match');
48  self::assertEquals(10, $this->converter->getPriority(), 'Priority does not match');
49  }
50 
54  public function ‪convertFromShouldCastTheStringToInteger(): void
55  {
56  self::assertSame(15, $this->converter->convertFrom('15', 'integer'));
57  }
58 
62  public function ‪convertFromDoesNotModifyIntegers(): void
63  {
64  $source = 123;
65  self::assertSame($source, $this->converter->convertFrom($source, 'integer'));
66  }
67 
72  {
73  self::assertNull($this->converter->convertFrom('', 'integer'));
74  }
75 
80  {
81  self::assertInstanceOf(Error::class, $this->converter->convertFrom('not numeric', 'integer'));
82  }
83 
88  {
89  self::assertTrue($this->converter->canConvertFrom('15', 'integer'));
90  }
91 
96  {
97  self::assertTrue($this->converter->canConvertFrom(123, 'integer'));
98  }
99 
104  {
105  self::assertTrue($this->converter->canConvertFrom('', 'integer'));
106  }
107 
111  public function ‪canConvertFromShouldReturnTrueForANullValue(): void
112  {
113  self::assertTrue($this->converter->canConvertFrom(null, 'integer'));
114  }
115 
120  {
121  self::assertEquals([], $this->converter->getSourceChildPropertiesToBeConverted('myString'));
122  }
123 }
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest\setUp
‪setUp()
Definition: IntegerConverterTest.php:34
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest\convertFromReturnsAnErrorIfSpecifiedStringIsNotNumeric
‪convertFromReturnsAnErrorIfSpecifiedStringIsNotNumeric()
Definition: IntegerConverterTest.php:78
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest\convertFromReturnsNullIfEmptyStringSpecified
‪convertFromReturnsNullIfEmptyStringSpecified()
Definition: IntegerConverterTest.php:70
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest\canConvertFromShouldReturnTrueForANumericStringSource
‪canConvertFromShouldReturnTrueForANumericStringSource()
Definition: IntegerConverterTest.php:86
‪TYPO3\CMS\Extbase\Property\TypeConverterInterface
Definition: TypeConverterInterface.php:26
‪TYPO3\CMS\Extbase\Property\TypeConverter\IntegerConverter
Definition: IntegerConverter.php:27
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter
Definition: ArrayConverterTest.php:18
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest\canConvertFromShouldReturnTrueForAnEmptyValue
‪canConvertFromShouldReturnTrueForAnEmptyValue()
Definition: IntegerConverterTest.php:102
‪TYPO3\CMS\Extbase\Error\Error
Definition: Error.php:25
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest\checkMetadata
‪checkMetadata()
Definition: IntegerConverterTest.php:43
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest\canConvertFromShouldReturnTrueForAnIntegerSource
‪canConvertFromShouldReturnTrueForAnIntegerSource()
Definition: IntegerConverterTest.php:94
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest
Definition: IntegerConverterTest.php:29
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest\convertFromDoesNotModifyIntegers
‪convertFromDoesNotModifyIntegers()
Definition: IntegerConverterTest.php:61
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest\$converter
‪TypeConverterInterface $converter
Definition: IntegerConverterTest.php:32
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest\getSourceChildPropertiesToBeConvertedShouldReturnEmptyArray
‪getSourceChildPropertiesToBeConvertedShouldReturnEmptyArray()
Definition: IntegerConverterTest.php:118
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest\canConvertFromShouldReturnTrueForANullValue
‪canConvertFromShouldReturnTrueForANullValue()
Definition: IntegerConverterTest.php:110
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest\convertFromShouldCastTheStringToInteger
‪convertFromShouldCastTheStringToInteger()
Definition: IntegerConverterTest.php:53