‪TYPO3CMS  11.5
ArgumentTest.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 
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪ArgumentTest extends UnitTestCase
29 {
32 
33  protected function ‪setUp(): void
34  {
35  parent::setUp();
36  $this->simpleValueArgument = new ‪Argument('someName', 'string');
37  $this->objectArgument = new ‪Argument('someName', 'DateTime');
38  }
39 
44  {
45  $this->expectException(\InvalidArgumentException::class);
46  $this->expectExceptionCode(1232551853);
47  new ‪Argument('', 'Text');
48  }
49 
54  {
55  $this->expectException(\InvalidArgumentException::class);
56  $this->expectExceptionCode(1187951688);
57  new ‪Argument(new \ArrayObject(), 'Text');
58  }
59 
64  {
65  self::assertEquals('string', $this->simpleValueArgument->getDataType(), 'The specified data type has not been set correctly.');
66  self::assertEquals('someName', $this->simpleValueArgument->getName(), 'The specified name has not been set correctly.');
67  }
68 
73  {
74  $returnedArgument = $this->simpleValueArgument->setShortName('x');
75  self::assertSame($this->simpleValueArgument, $returnedArgument, 'The returned argument is not the original argument.');
76  }
77 
81  public function ‪invalidShortNames(): array
82  {
83  return [
84  [''],
85  ['as'],
86  [5],
87  ];
88  }
89 
95  public function ‪shortNameShouldThrowExceptionIfInvalid($invalidShortName): void
96  {
97  $this->expectException(\InvalidArgumentException::class);
98  $this->expectExceptionCode(1195824959);
99  $this->simpleValueArgument->setShortName($invalidShortName);
100  }
101 
105  public function ‪shortNameCanBeRetrievedAgain(): void
106  {
107  $this->simpleValueArgument->setShortName('x');
108  self::assertEquals('x', $this->simpleValueArgument->getShortName());
109  }
110 
115  {
116  $returnedArgument = $this->simpleValueArgument->setRequired(true);
117  self::assertSame($this->simpleValueArgument, $returnedArgument, 'The returned argument is not the original argument.');
118  self::assertTrue($this->simpleValueArgument->isRequired());
119  }
120 
125  {
126  $returnedArgument = $this->simpleValueArgument->setDefaultValue('default');
127  self::assertSame($this->simpleValueArgument, $returnedArgument, 'The returned argument is not the original argument.');
128  self::assertSame('default', $this->simpleValueArgument->getDefaultValue());
129  }
130 
135  {
136  $mockValidator = $this->createMock(ValidatorInterface::class);
137  $returnedArgument = $this->simpleValueArgument->setValidator($mockValidator);
138  self::assertSame($this->simpleValueArgument, $returnedArgument, 'The returned argument is not the original argument.');
139  self::assertSame($mockValidator, $this->simpleValueArgument->getValidator());
140  }
141 
145  public function ‪setValueProvidesFluentInterface(): void
146  {
147  $returnedArgument = $this->simpleValueArgument->setValue(null);
148  self::assertSame($this->simpleValueArgument, $returnedArgument, 'The returned argument is not the original argument.');
149  }
150 
154  public function ‪setValueUsesNullAsIs(): void
155  {
156  $this->simpleValueArgument = new ‪Argument('dummy', 'string');
157  $this->simpleValueArgument->setValue(null);
158  self::assertNull($this->simpleValueArgument->getValue());
159  }
160 
165  {
166  self::assertNull($this->simpleValueArgument->getPropertyMappingConfiguration()->getConfigurationValue(PersistentObjectConverter::class, ‪PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED));
167  self::assertNull($this->simpleValueArgument->getPropertyMappingConfiguration()->getConfigurationValue(PersistentObjectConverter::class, ‪PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED));
168  }
169 }
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller\ArgumentTest\setValidatorShouldProvideFluentInterfaceAndReallySetValidator
‪setValidatorShouldProvideFluentInterfaceAndReallySetValidator()
Definition: ArgumentTest.php:134
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller
Definition: ActionControllerTest.php:18
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller\ArgumentTest\shortNameShouldThrowExceptionIfInvalid
‪shortNameShouldThrowExceptionIfInvalid($invalidShortName)
Definition: ArgumentTest.php:95
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller\ArgumentTest\constructingArgumentWithInvalidNameThrowsException
‪constructingArgumentWithInvalidNameThrowsException()
Definition: ArgumentTest.php:53
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller\ArgumentTest\setUp
‪setUp()
Definition: ArgumentTest.php:33
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller\ArgumentTest\shortNameCanBeRetrievedAgain
‪shortNameCanBeRetrievedAgain()
Definition: ArgumentTest.php:105
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller\ArgumentTest\constructingArgumentWithoutNameThrowsException
‪constructingArgumentWithoutNameThrowsException()
Definition: ArgumentTest.php:43
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller\ArgumentTest\defaultPropertyMappingConfigurationDoesNotAllowCreationOrModificationOfObjects
‪defaultPropertyMappingConfigurationDoesNotAllowCreationOrModificationOfObjects()
Definition: ArgumentTest.php:164
‪TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter\CONFIGURATION_CREATION_ALLOWED
‪const CONFIGURATION_CREATION_ALLOWED
Definition: PersistentObjectConverter.php:52
‪TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter
Definition: PersistentObjectConverter.php:43
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller\ArgumentTest
Definition: ArgumentTest.php:29
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller\ArgumentTest\setShortNameProvidesFluentInterface
‪setShortNameProvidesFluentInterface()
Definition: ArgumentTest.php:72
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller\ArgumentTest\passingDataTypeToConstructorReallySetsTheDataType
‪passingDataTypeToConstructorReallySetsTheDataType()
Definition: ArgumentTest.php:63
‪TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter\CONFIGURATION_MODIFICATION_ALLOWED
‪const CONFIGURATION_MODIFICATION_ALLOWED
Definition: PersistentObjectConverter.php:47
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller\ArgumentTest\$simpleValueArgument
‪Argument $simpleValueArgument
Definition: ArgumentTest.php:30
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller\ArgumentTest\setDefaultValueShouldProvideFluentInterfaceAndReallySetDefaultValue
‪setDefaultValueShouldProvideFluentInterfaceAndReallySetDefaultValue()
Definition: ArgumentTest.php:124
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller\ArgumentTest\$objectArgument
‪Argument $objectArgument
Definition: ArgumentTest.php:31
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller\ArgumentTest\setRequiredShouldProvideFluentInterfaceAndReallySetRequiredState
‪setRequiredShouldProvideFluentInterfaceAndReallySetRequiredState()
Definition: ArgumentTest.php:114
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller\ArgumentTest\invalidShortNames
‪array invalidShortNames()
Definition: ArgumentTest.php:81
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller\ArgumentTest\setValueUsesNullAsIs
‪setValueUsesNullAsIs()
Definition: ArgumentTest.php:154
‪TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface
Definition: ValidatorInterface.php:22
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller\ArgumentTest\setValueProvidesFluentInterface
‪setValueProvidesFluentInterface()
Definition: ArgumentTest.php:145
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument
Definition: Argument.php:27