‪TYPO3CMS  10.4
FloatValidatorTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20 
24 class ‪FloatValidatorTest extends UnitTestCase
25 {
29  protected ‪$validatorClassName = FloatValidator::class;
30 
31  public function ‪setup(): void
32  {
33  parent::setUp();
34  $this->validator = $this->getMockBuilder($this->validatorClassName)
35  ->setMethods(['translateErrorMessage'])
36  ->getMock();
37  }
38 
44  public function ‪validFloats()
45  {
46  return [
47  [1029437.234726],
48  ['123.45'],
49  ['+123.45'],
50  ['-123.45'],
51  ['123.45e3'],
52  [123450.0]
53  ];
54  }
55 
62  {
63  self::assertFalse($this->validator->validate($float)->hasErrors());
64  }
65 
71  public function ‪invalidFloats()
72  {
73  return [
74  [1029437],
75  ['1029437'],
76  ['not a number']
77  ];
78  }
79 
86  {
87  self::assertTrue($this->validator->validate($float)->hasErrors());
88  }
89 
94  {
95  self::assertEquals(1, count($this->validator->validate(123456)->getErrors()));
96  }
97 }
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\FloatValidatorTest\$validatorClassName
‪string $validatorClassName
Definition: FloatValidatorTest.php:28
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\FloatValidatorTest\floatValidatorCreatesTheCorrectErrorForAnInvalidSubject
‪floatValidatorCreatesTheCorrectErrorForAnInvalidSubject()
Definition: FloatValidatorTest.php:92
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\FloatValidatorTest
Definition: FloatValidatorTest.php:25
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\FloatValidatorTest\floatValidatorReturnsErrorForAnInvalidFloat
‪floatValidatorReturnsErrorForAnInvalidFloat($float)
Definition: FloatValidatorTest.php:84
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\FloatValidatorTest\floatValidatorReturnsNoErrorsForAValidFloat
‪floatValidatorReturnsNoErrorsForAValidFloat($float)
Definition: FloatValidatorTest.php:60
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\FloatValidatorTest\setup
‪setup()
Definition: FloatValidatorTest.php:30
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\FloatValidatorTest\invalidFloats
‪array invalidFloats()
Definition: FloatValidatorTest.php:70
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator
Definition: AbstractCompositeValidatorTest.php:16
‪TYPO3\CMS\Extbase\Validation\Validator\FloatValidator
Definition: FloatValidator.php:22
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\FloatValidatorTest\validFloats
‪array validFloats()
Definition: FloatValidatorTest.php:43