[TASK] Streamline phpdoc annotations in EXT:extbase
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Validation / Validator / IntegerValidatorTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Testcase for the integer validator
19 */
20 class IntegerValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\AbstractValidatorTestcase
21 {
22 /**
23 * @var string
24 */
25 protected $validatorClassName = \TYPO3\CMS\Extbase\Validation\Validator\IntegerValidator::class;
26
27 public function setup()
28 {
29 $this->validator = $this->getMockBuilder($this->validatorClassName)
30 ->setMethods(['translateErrorMessage'])
31 ->getMock();
32 }
33
34 /**
35 * Data provider with valid integers
36 *
37 * @return array
38 */
39 public function validIntegers()
40 {
41 return [
42 [1029437],
43 ['12345'],
44 ['+12345'],
45 ['-12345']
46 ];
47 }
48
49 /**
50 * @test
51 * @dataProvider validIntegers
52 * @param mixed $integer
53 */
54 public function integerValidatorReturnsNoErrorsForAValidInteger($integer)
55 {
56 $this->assertFalse($this->validator->validate($integer)->hasErrors());
57 }
58
59 /**
60 * Data provider with invalid integers
61 *
62 * @return array
63 */
64 public function invalidIntegers()
65 {
66 return [
67 ['not a number'],
68 [3.1415],
69 ['12345.987']
70 ];
71 }
72
73 /**
74 * @test
75 * @dataProvider invalidIntegers
76 * @param mixed $invalidInteger
77 */
78 public function integerValidatorReturnsErrorForAnInvalidInteger($invalidInteger)
79 {
80 $this->assertTrue($this->validator->validate($invalidInteger)->hasErrors());
81 }
82
83 /**
84 * @test
85 */
86 public function integerValidatorCreatesTheCorrectErrorForAnInvalidSubject()
87 {
88 $this->assertEquals(1, count($this->validator->validate('not a number')->getErrors()));
89 }
90 }