‪TYPO3CMS  11.5
IntegerValidatorTest.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 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪IntegerValidatorTest extends UnitTestCase
27 {
31  public function ‪validIntegers(): array
32  {
33  return [
34  [1029437],
35  ['12345'],
36  ['+12345'],
37  ['-12345'],
38  ];
39  }
40 
46  {
47  ‪$validator = $this->getMockBuilder(IntegerValidator::class)->onlyMethods(['translateErrorMessage'])->getMock();
48  self::assertFalse(‪$validator->validate($integer)->hasErrors());
49  }
50 
54  public function ‪invalidIntegers(): array
55  {
56  return [
57  ['not a number'],
58  [3.1415],
59  ['12345.987'],
60  ];
61  }
62 
67  public function ‪integerValidatorReturnsErrorForAnInvalidInteger($invalidInteger): void
68  {
69  ‪$validator = $this->getMockBuilder(IntegerValidator::class)->onlyMethods(['translateErrorMessage'])->getMock();
70  self::assertTrue(‪$validator->validate($invalidInteger)->hasErrors());
71  }
72 
77  {
78  ‪$validator = $this->getMockBuilder(IntegerValidator::class)->onlyMethods(['translateErrorMessage'])->getMock();
79  self::assertCount(1, ‪$validator->validate('not a number')->getErrors());
80  }
81 }
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\IntegerValidatorTest\integerValidatorReturnsNoErrorsForAValidInteger
‪integerValidatorReturnsNoErrorsForAValidInteger($integer)
Definition: IntegerValidatorTest.php:45
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\IntegerValidatorTest\invalidIntegers
‪invalidIntegers()
Definition: IntegerValidatorTest.php:54
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\IntegerValidatorTest
Definition: IntegerValidatorTest.php:27
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\IntegerValidatorTest\integerValidatorCreatesTheCorrectErrorForAnInvalidSubject
‪integerValidatorCreatesTheCorrectErrorForAnInvalidSubject()
Definition: IntegerValidatorTest.php:76
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\IntegerValidatorTest\validIntegers
‪validIntegers()
Definition: IntegerValidatorTest.php:31
‪$validator
‪if(isset($args['d'])) $validator
Definition: validateRstFiles.php:218
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\IntegerValidatorTest\integerValidatorReturnsErrorForAnInvalidInteger
‪integerValidatorReturnsErrorForAnInvalidInteger($invalidInteger)
Definition: IntegerValidatorTest.php:67
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator
Definition: AbstractCompositeValidatorTest.php:18
‪TYPO3\CMS\Extbase\Validation\Validator\IntegerValidator
Definition: IntegerValidator.php:22