‪TYPO3CMS  10.4
IntegerValidatorTest.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 ‪IntegerValidatorTest extends UnitTestCase
25 {
29  protected ‪$validatorClassName = IntegerValidator::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 ‪validIntegers()
45  {
46  return [
47  [1029437],
48  ['12345'],
49  ['+12345'],
50  ['-12345']
51  ];
52  }
53 
60  {
61  self::assertFalse($this->validator->validate($integer)->hasErrors());
62  }
63 
69  public function ‪invalidIntegers()
70  {
71  return [
72  ['not a number'],
73  [3.1415],
74  ['12345.987']
75  ];
76  }
77 
83  public function ‪integerValidatorReturnsErrorForAnInvalidInteger($invalidInteger)
84  {
85  self::assertTrue($this->validator->validate($invalidInteger)->hasErrors());
86  }
87 
92  {
93  self::assertEquals(1, count($this->validator->validate('not a number')->getErrors()));
94  }
95 }
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\IntegerValidatorTest\integerValidatorReturnsNoErrorsForAValidInteger
‪integerValidatorReturnsNoErrorsForAValidInteger($integer)
Definition: IntegerValidatorTest.php:58
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\IntegerValidatorTest\invalidIntegers
‪array invalidIntegers()
Definition: IntegerValidatorTest.php:68
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\IntegerValidatorTest
Definition: IntegerValidatorTest.php:25
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\IntegerValidatorTest\setup
‪setup()
Definition: IntegerValidatorTest.php:30
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\IntegerValidatorTest\integerValidatorCreatesTheCorrectErrorForAnInvalidSubject
‪integerValidatorCreatesTheCorrectErrorForAnInvalidSubject()
Definition: IntegerValidatorTest.php:90
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\IntegerValidatorTest\validIntegers
‪array validIntegers()
Definition: IntegerValidatorTest.php:43
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\IntegerValidatorTest\$validatorClassName
‪string $validatorClassName
Definition: IntegerValidatorTest.php:28
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\IntegerValidatorTest\integerValidatorReturnsErrorForAnInvalidInteger
‪integerValidatorReturnsErrorForAnInvalidInteger($invalidInteger)
Definition: IntegerValidatorTest.php:82
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator
Definition: AbstractCompositeValidatorTest.php:16
‪TYPO3\CMS\Extbase\Validation\Validator\IntegerValidator
Definition: IntegerValidator.php:22