[TASK] Shorten the extend class in all unit tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Validation / Validator / StringValidatorTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator;
4
5 /* *
6 * This script belongs to the Extbase framework. *
7 * *
8 * It is free software; you can redistribute it and/or modify it under *
9 * the terms of the GNU Lesser General Public License as published by the *
10 * Free Software Foundation, either version 3 of the License, or (at your *
11 * option) any later version. *
12 * *
13 * This script is distributed in the hope that it will be useful, but *
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
15 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
16 * General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with the script. *
20 * If not, see http://www.gnu.org/licenses/lgpl.html *
21 * *
22 * The TYPO3 project - inspiring people to share! *
23 * */
24
25 use TYPO3\CMS\Extbase\Validation\Validator\StringValidator;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27
28 /**
29 * Testcase for the string length validator
30 *
31 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
32 */
33 class StringValidatorTest extends UnitTestCase
34 {
35 /**
36 * @test
37 */
38 public function stringValidatorShouldValidateString()
39 {
40 $this->assertFalse((new StringValidator())->validate('Hello World')->hasErrors());
41 }
42
43 /**
44 * @test
45 */
46 public function stringValidatorShouldReturnErrorIfNumberIsGiven()
47 {
48 /** @var StringValidator $validator */
49 $validator = $this->getMockBuilder(StringValidator::class)
50 ->setMethods(['translateErrorMessage'])
51 ->getMock();
52
53 $this->assertTrue($validator->validate(42)->hasErrors());
54 }
55
56 /**
57 * @test
58 */
59 public function stringValidatorShouldReturnErrorIfObjectWithToStringMethodStringIsGiven()
60 {
61 /** @var StringValidator $validator */
62 $validator = $this->getMockBuilder(StringValidator::class)
63 ->setMethods(['translateErrorMessage'])
64 ->getMock();
65
66 $object = new class() {
67 /** @return string */
68 public function __toString()
69 {
70 return 'ASDF';
71 }
72 };
73
74 $this->assertTrue($validator->validate($object)->hasErrors());
75 }
76 }