‪TYPO3CMS  11.5
NumberValidatorTest.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 ‪NumberValidatorTest extends UnitTestCase
30 {
31  protected string ‪$validatorClassName = NumberValidator::class;
32 
36  protected ‪$validator;
37 
38  public function ‪setup(): void
39  {
40  parent::setUp();
41  $this->validator = $this->getMockBuilder($this->validatorClassName)
42  ->onlyMethods(['translateErrorMessage'])
43  ->getMock();
44  }
45 
50  {
51  self::assertFalse($this->validator->validate(1029437)->hasErrors());
52  }
53 
57  public function ‪numberValidatorReturnsFalseForAString(): void
58  {
59  $expectedResult = new Result();
60  // we only test for the error code, after the message translation method is mocked
61  $expectedResult->addError(new Error('', 1221563685));
62  self::assertEquals($expectedResult, $this->validator->validate('not a number'));
63  }
64 }
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\NumberValidatorTest\numberValidatorReturnsTrueForASimpleInteger
‪numberValidatorReturnsTrueForASimpleInteger()
Definition: NumberValidatorTest.php:48
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\NumberValidatorTest\numberValidatorReturnsFalseForAString
‪numberValidatorReturnsFalseForAString()
Definition: NumberValidatorTest.php:56
‪TYPO3\CMS\Extbase\Error\Result
Definition: Result.php:24
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\NumberValidatorTest
Definition: NumberValidatorTest.php:30
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\NumberValidatorTest\$validator
‪ValidatorInterface $validator
Definition: NumberValidatorTest.php:35
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\NumberValidatorTest\setup
‪setup()
Definition: NumberValidatorTest.php:37
‪TYPO3\CMS\Extbase\Error\Error
Definition: Error.php:25
‪TYPO3\CMS\Extbase\Validation\Error
Definition: Error.php:22
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\NumberValidatorTest\$validatorClassName
‪string $validatorClassName
Definition: NumberValidatorTest.php:31
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator
Definition: AbstractCompositeValidatorTest.php:18
‪TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface
Definition: ValidatorInterface.php:22
‪TYPO3\CMS\Extbase\Validation\Validator\NumberValidator
Definition: NumberValidator.php:22