diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4168e10f..7ba8feb5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -20,7 +20,7 @@ jobs: fail-fast: false matrix: php-versions: ['8.2', '8.3'] - flow-versions: ['8.0', '8.3', '9.0'] + flow-versions: ['8.4', '9.0'] dependencies: ['highest'] defaults: @@ -29,14 +29,14 @@ jobs: steps: - name: Checkout Flow development distribution - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: repository: neos/flow-development-distribution ref: ${{ matrix.flow-versions }} path: ${{ env.FLOW_FOLDER }} - name: Checkout package - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: path: ${{ env.PACKAGE_FOLDER}}/${{ env.PACKAGE_NAME }} diff --git a/Tests/Functional/AbstractFunctionalTestCase.php b/Tests/Functional/AbstractFunctionalTestCase.php index c254f750..e7f642e6 100644 --- a/Tests/Functional/AbstractFunctionalTestCase.php +++ b/Tests/Functional/AbstractFunctionalTestCase.php @@ -11,7 +11,7 @@ * information, please view the LICENSE file which was distributed with this * source code. */ - +use PHPUnit\Framework\Attributes\Large; use Neos\Flow\Http\Client\Browser; use Neos\Flow\Mvc\Routing\Route; use Neos\Flow\Tests\FunctionalTestCase; @@ -21,9 +21,8 @@ /** * Testcase for Simple Form - * - * @group large */ +#[Large] abstract class AbstractFunctionalTestCase extends FunctionalTestCase { /** diff --git a/Tests/Functional/FormBuildingFinishedTest.php b/Tests/Functional/FormBuildingFinishedTest.php index 4823b857..c311cecf 100644 --- a/Tests/Functional/FormBuildingFinishedTest.php +++ b/Tests/Functional/FormBuildingFinishedTest.php @@ -10,19 +10,17 @@ * information, please view the LICENSE file which was distributed with this * source code. */ - +use PHPUnit\Framework\Attributes\Large; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Assert; /** * Testcase for onBuildingFinished - * - * @group large */ +#[Large] class FormBuildingFinishedTest extends AbstractFunctionalTestCase { - /** - * @test - */ + #[Test] public function aFormElementCanAddNewSubelementsWithValidationApplied() { $this->browser->request('http://localhost/test/form/simpleform/TestingFormBuildingFinished'); diff --git a/Tests/Functional/SimpleFormTest.php b/Tests/Functional/SimpleFormTest.php index 97500984..4525495b 100644 --- a/Tests/Functional/SimpleFormTest.php +++ b/Tests/Functional/SimpleFormTest.php @@ -10,22 +10,21 @@ * information, please view the LICENSE file which was distributed with this * source code. */ +use PHPUnit\Framework\Attributes\Large; +use PHPUnit\Framework\Attributes\Test; use Neos\Utility\ObjectAccess; use PHPUnit\Framework\Assert; use Symfony\Component\DomCrawler\Field\InputFormField; /** * Testcase for Simple Form - * - * @group large */ +#[Large] class SimpleFormTest extends AbstractFunctionalTestCase { protected static $testablePersistenceEnabled = true; - /** - * @test - */ + #[Test] public function goingForthAndBackStoresFormValuesOfFirstPage() { $this->browser->request('http://localhost/test/form/simpleform/ThreePageFormWithValidation'); @@ -41,9 +40,7 @@ public function goingForthAndBackStoresFormValuesOfFirstPage() Assert::assertSame('My Text on the first page', $form['--three-page-form-with-validation']['text1-1']->getValue()); } - /** - * @test - */ + #[Test] public function goingForthAndBackStoresFormValuesOfSecondPage() { $this->browser->request('http://localhost/test/form/simpleform/ThreePageFormWithValidation'); @@ -59,9 +56,7 @@ public function goingForthAndBackStoresFormValuesOfSecondPage() Assert::assertSame('My Text on the second page', $form['--three-page-form-with-validation']['text2-1']->getValue()); } - /** - * @test - */ + #[Test] public function goingForthAndBackStoresFormValuesOfSecondPageAndTriggersValidationOnlyWhenGoingForward() { $this->browser->request('http://localhost/test/form/simpleform/ThreePageFormWithValidation'); @@ -83,10 +78,7 @@ public function goingForthAndBackStoresFormValuesOfSecondPageAndTriggersValidati Assert::assertSame('', $form['--three-page-form-with-validation']['text3-1']->getValue()); } - /** - * @test - * Thanks to Anian Weber for reporting that issue! - */ + #[Test] public function validationIsNotSkippedForGetRequests() { $this->browser->request('http://localhost/test/form/simpleform/ThreePageFormWithValidation'); @@ -109,11 +101,11 @@ public function validationIsNotSkippedForGetRequests() } /** - * @test * @see https://github.com/neos/form/issues/126 * @see https://github.com/neos/form/issues/135 * @see https://github.com/neos/form/issues/143 */ + #[Test] public function formStateCanContainArbitraryObjects() { $this->browser->request('http://localhost/test/form/simpleform/TwoPageFormWithUpload'); @@ -136,9 +128,8 @@ public function formStateCanContainArbitraryObjects() * that we do NOT send any of the parameters with the form; as we only want the form state to be applied. * * So, if the form state contains some values, we want to be sure these values are re-displayed. - * - * @test */ + #[Test] public function goingForthAndBackStoresFormValuesOfSecondPageEvenWhenSecondPageIsManuallyCalledAsGetRequest() { $this->markTestSkipped('This test is skipped because we no longer allow Form validators to be skipped, see https://github.com/neos/form/security/advisories/GHSA-m5vx-8chx-qvmm'); diff --git a/Tests/Unit/Core/Model/AbstractFinisherTest.php b/Tests/Unit/Core/Model/AbstractFinisherTest.php index ab281890..41a74a44 100644 --- a/Tests/Unit/Core/Model/AbstractFinisherTest.php +++ b/Tests/Unit/Core/Model/AbstractFinisherTest.php @@ -10,7 +10,10 @@ * information, please view the LICENSE file which was distributed with this * source code. */ - +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\MockObject\MockObject; use Neos\Flow\Tests\UnitTestCase; use Neos\Form\Core\Model\AbstractFinisher; use Neos\Form\Core\Model\FinisherContext; @@ -20,11 +23,11 @@ /** * Test for AbstractFinisher - * @covers \Neos\Form\Core\Model\AbstractFinisher - * @covers \Neos\Form\Core\Model\FinisherContext - * @covers \Neos\Form\Core\Runtime\FormRuntime - * @covers \Neos\Form\Core\Runtime\FormState */ +#[CoversClass(AbstractFinisher::class)] +#[CoversClass(FinisherContext::class)] +#[CoversClass(FormRuntime::class)] +#[CoversClass(FormState::class)] class AbstractFinisherTest extends UnitTestCase { /** @@ -32,9 +35,7 @@ class AbstractFinisherTest extends UnitTestCase */ protected $formRuntime = null; - /** - * @test - */ + #[Test] public function executeSetsFinisherContextAndCallsExecuteInternal() { $finisher = $this->getAbstractFinisher(); @@ -45,9 +46,7 @@ public function executeSetsFinisherContextAndCallsExecuteInternal() Assert::assertSame($finisherContext, $finisher->_get('finisherContext')); } - /** - * @test - */ + #[Test] public function parseOptionReturnsPreviouslySetOption() { $finisher = $this->getAbstractFinisher(); @@ -58,9 +57,7 @@ public function parseOptionReturnsPreviouslySetOption() Assert::assertSame('bar', $finisher->_call('parseOption', 'foo')); } - /** - * @test - */ + #[Test] public function parseOptionReturnsNumbersAndSimpleTypesWithoutModification() { $finisher = $this->getAbstractFinisher(); @@ -73,7 +70,7 @@ public function parseOptionReturnsNumbersAndSimpleTypesWithoutModification() Assert::assertSame($obj, $finisher->_call('parseOption', 'baz')); } - public function dataProviderForDefaultOptions() + public static function dataProviderForDefaultOptions() { $defaultOptions = [ 'overridden1' => 'Overridden1Default', @@ -117,10 +114,8 @@ public function dataProviderForDefaultOptions() ]; } - /** - * @dataProvider dataProviderForDefaultOptions - * @test - */ + #[DataProvider('dataProviderForDefaultOptions')] + #[Test] public function parseOptionReturnsDefaultOptionIfNecessary($defaultOptions, $options, $optionKey, $expected) { $finisher = $this->getAbstractFinisher(); @@ -132,7 +127,7 @@ public function parseOptionReturnsDefaultOptionIfNecessary($defaultOptions, $opt Assert::assertSame($expected, $finisher->_call('parseOption', $optionKey)); } - public function dataProviderForPlaceholderReplacement() + public static function dataProviderForPlaceholderReplacement() { $formValues = [ 'foo' => 'My Value', @@ -153,10 +148,8 @@ public function dataProviderForPlaceholderReplacement() ]; } - /** - * @dataProvider dataProviderForPlaceholderReplacement - * @test - */ + #[DataProvider('dataProviderForPlaceholderReplacement')] + #[Test] public function placeholdersAreReplacedWithFormRuntimeValues($formValues, $optionValue, $expected) { $finisher = $this->getAbstractFinisher(); @@ -173,10 +166,8 @@ public function placeholdersAreReplacedWithFormRuntimeValues($formValues, $optio Assert::assertSame($expected, $finisher->_call('parseOption', 'key1')); } - /** - * @dataProvider dataProviderForPlaceholderReplacement - * @test - */ + #[DataProvider('dataProviderForPlaceholderReplacement')] + #[Test] public function placeholdersInsideDefaultsReplacedWithFormRuntimeValues($formValues, $optionValue, $expected) { $finisher = $this->getAbstractFinisher(); @@ -193,9 +184,7 @@ public function placeholdersInsideDefaultsReplacedWithFormRuntimeValues($formVal Assert::assertSame($expected, $finisher->_call('parseOption', 'key1')); } - /** - * @test - */ + #[Test] public function cancelCanBeSetOnFinisherContext() { $finisherContext = $this->getFinisherContext(); @@ -205,7 +194,7 @@ public function cancelCanBeSetOnFinisherContext() } /** - * @return AbstractFinisher|\PHPUnit\Framework\MockObject\MockObject + * @return AbstractFinisher|MockObject */ protected function getAbstractFinisher() { diff --git a/Tests/Unit/Core/Model/AbstractFormElementTest.php b/Tests/Unit/Core/Model/AbstractFormElementTest.php index 32542265..cbb35acc 100644 --- a/Tests/Unit/Core/Model/AbstractFormElementTest.php +++ b/Tests/Unit/Core/Model/AbstractFormElementTest.php @@ -10,7 +10,9 @@ * information, please view the LICENSE file which was distributed with this * source code. */ - +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\Attributes\DataProvider; use Neos\Flow\Tests\UnitTestCase; use Neos\Flow\Validation\Exception\InvalidValidationOptionsException; use Neos\Flow\Validation\Validator\ConjunctionValidator; @@ -28,13 +30,11 @@ /** * Test for AbstractFormElement Domain Model - * @covers \Neos\Form\Core\Model\AbstractFormElement */ +#[CoversClass(AbstractFormElement::class)] class AbstractFormElementTest extends UnitTestCase { - /** - * @test - */ + #[Test] public function constructorSetsIdentifierAndType() { $element = $this->getFormElement(['myIdentifier', 'Neos.Form:MyType']); @@ -42,7 +42,7 @@ public function constructorSetsIdentifierAndType() Assert::assertSame('Neos.Form:MyType', $element->getType()); } - public function invalidIdentifiers() + public static function invalidIdentifiers() { return [ 'Null Identifier' => [null], @@ -51,10 +51,8 @@ public function invalidIdentifiers() ]; } - /** - * @test - * @dataProvider invalidIdentifiers - */ + #[DataProvider('invalidIdentifiers')] + #[Test] public function ifBogusIdentifierSetInConstructorAnExceptionIsThrown($identifier) { $this->expectException(IdentifierNotValidException::class); @@ -62,9 +60,7 @@ public function ifBogusIdentifierSetInConstructorAnExceptionIsThrown($identifier $this->getFormElement([$identifier, 'Neos.Form:MyType']); } - /** - * @test - */ + #[Test] public function labelCanBeSetAndGet() { $formElement = $this->getFormElement(['foo', 'Neos.Form:MyType']); @@ -73,9 +69,7 @@ public function labelCanBeSetAndGet() Assert::assertSame('my label', $formElement->getLabel()); } - /** - * @test - */ + #[Test] public function defaultValueCanBeSetAndGet() { $formDefinition = new FormDefinition('foo'); @@ -88,9 +82,7 @@ public function defaultValueCanBeSetAndGet() Assert::assertSame('My Default Value', $formElement->getDefaultValue()); } - /** - * @test - */ + #[Test] public function renderingOptionsCanBeSetAndGet() { $formElement = $this->getFormElement(['foo', 'Neos.Form:MyType']); @@ -101,9 +93,7 @@ public function renderingOptionsCanBeSetAndGet() Assert::assertSame(['option1' => 'value1', 'option2' => 'value2'], $formElement->getRenderingOptions()); } - /** - * @test - */ + #[Test] public function rendererClassNameCanBeGetAndSet() { $formElement = $this->getFormElement(['foo', 'Neos.Form:MyType']); @@ -112,9 +102,7 @@ public function rendererClassNameCanBeGetAndSet() Assert::assertSame('MyRendererClassName', $formElement->getRendererClassName()); } - /** - * @test - */ + #[Test] public function getUniqueIdentifierBuildsIdentifierFromRootFormAndElementIdentifier() { $formDefinition = new FormDefinition('foo'); @@ -126,7 +114,7 @@ public function getUniqueIdentifierBuildsIdentifierFromRootFormAndElementIdentif Assert::assertSame('foo-bar', $myFormElement->getUniqueIdentifier()); } - public function getUniqueIdentifierReplacesSpecialCharactersByUnderscoresProvider() + public static function getUniqueIdentifierReplacesSpecialCharactersByUnderscoresProvider() { return [ ['foo', 'bar', 'foo-bar'], @@ -137,14 +125,14 @@ public function getUniqueIdentifierReplacesSpecialCharactersByUnderscoresProvide } /** - * @test - * @dataProvider getUniqueIdentifierReplacesSpecialCharactersByUnderscoresProvider * @param string $formIdentifier * @param string $elementIdentifier * @param string $expectedResult * @throws FormDefinitionConsistencyException * @throws IdentifierNotValidException */ + #[DataProvider('getUniqueIdentifierReplacesSpecialCharactersByUnderscoresProvider')] + #[Test] public function getUniqueIdentifierReplacesSpecialCharactersByUnderscores($formIdentifier, $elementIdentifier, $expectedResult) { $formDefinition = new FormDefinition($formIdentifier); @@ -157,10 +145,10 @@ public function getUniqueIdentifierReplacesSpecialCharactersByUnderscores($formI } /** - * @test * @throws FormDefinitionConsistencyException * @throws IdentifierNotValidException */ + #[Test] public function isRequiredReturnsFalseByDefault() { $formDefinition = $this->getFormDefinitionWithProcessingRule('bar'); @@ -173,9 +161,7 @@ public function isRequiredReturnsFalseByDefault() $this->assertFalse($myFormElement->isRequired()); } - /** - * @test - */ + #[Test] public function isRequiredReturnsTrueIfNotEmptyValidatorIsAdded() { $formDefinition = $this->getFormDefinitionWithProcessingRule('bar'); @@ -196,7 +182,7 @@ public function isRequiredReturnsTrueIfNotEmptyValidatorIsAdded() */ protected function getFormElement(array $constructorArguments) { - return $this->getMockBuilder(AbstractFormElement::class)->setMethods(['dummy'])->setConstructorArgs($constructorArguments)->getMock(); + return $this->getMockBuilder(AbstractFormElement::class)->addMethods(['dummy'])->setConstructorArgs($constructorArguments)->getMock(); } /** @@ -210,8 +196,8 @@ protected function getFormDefinitionWithProcessingRule($formElementIdentifier) $mockProcessingRule = $this->getAccessibleMock(ProcessingRule::class, ['dummy']); $mockProcessingRule->_set('validator', new ConjunctionValidator()); - $formDefinition = $this->getMockBuilder(FormDefinition::class)->setMethods(['getProcessingRule'])->setConstructorArgs(['foo'])->getMock(); - $formDefinition->expects($this->any())->method('getProcessingRule')->with($formElementIdentifier)->will($this->returnValue($mockProcessingRule)); + $formDefinition = $this->getMockBuilder(FormDefinition::class)->onlyMethods(['getProcessingRule'])->setConstructorArgs(['foo'])->getMock(); + $formDefinition->expects($this->any())->method('getProcessingRule')->with($formElementIdentifier)->willReturn($mockProcessingRule); return $formDefinition; } diff --git a/Tests/Unit/Core/Model/FinisherContextTest.php b/Tests/Unit/Core/Model/FinisherContextTest.php index ffbc50b2..5bb2d5f0 100644 --- a/Tests/Unit/Core/Model/FinisherContextTest.php +++ b/Tests/Unit/Core/Model/FinisherContextTest.php @@ -10,7 +10,8 @@ * information, please view the LICENSE file which was distributed with this * source code. */ - +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Test; use Neos\Flow\Tests\UnitTestCase; use Neos\Form\Core\Model\FinisherContext; use Neos\Form\Core\Runtime\FormRuntime; @@ -18,8 +19,8 @@ /** * Test for FinisherContext Domain Model - * @covers \Neos\Form\Core\Model\FinisherContext */ +#[CoversClass(FinisherContext::class)] class FinisherContextTest extends UnitTestCase { /** @@ -38,25 +39,19 @@ public function setUp(): void $this->finisherContext = new FinisherContext($this->mockFormRuntime); } - /** - * @test - */ + #[Test] public function getFormRuntimeReturnsTheFormRuntime() { Assert::assertSame($this->mockFormRuntime, $this->finisherContext->getFormRuntime()); } - /** - * @test - */ + #[Test] public function isCancelReturnsFalseByDefault() { Assert::assertFalse($this->finisherContext->isCancelled()); } - /** - * @test - */ + #[Test] public function isCancelReturnsTrueIfContextHasBeenCancelled() { $this->finisherContext->cancel(); diff --git a/Tests/Unit/Core/Model/FormDefinitionTest.php b/Tests/Unit/Core/Model/FormDefinitionTest.php index 6b95b75d..eac5a40b 100644 --- a/Tests/Unit/Core/Model/FormDefinitionTest.php +++ b/Tests/Unit/Core/Model/FormDefinitionTest.php @@ -10,7 +10,10 @@ * information, please view the LICENSE file which was distributed with this * source code. */ - +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\Attributes\DataProvider; +use Neos\Form\Tests\Unit\Core\Model\Fixture\EmptyFinisher; use Neos\Flow\Mvc\ActionRequest; use Neos\Flow\Mvc\ActionResponse; use Neos\Flow\Tests\UnitTestCase; @@ -36,14 +39,12 @@ /** * Test for FormDefinition Domain Model - * @covers \Neos\Form\Core\Model\FormDefinition - * @covers \Neos\Form\Core\Model\Page */ +#[CoversClass(FormDefinition::class)] +#[CoversClass(Page::class)] class FormDefinitionTest extends UnitTestCase { - /** - * @test - */ + #[Test] public function identifierSetInConstructorCanBeReadAgain() { $formDefinition = new FormDefinition('foo'); @@ -53,7 +54,7 @@ public function identifierSetInConstructorCanBeReadAgain() Assert::assertSame('bar', $formDefinition->getIdentifier()); } - public function invalidIdentifiers() + public static function invalidIdentifiers() { return [ 'Null Identifier' => [null], @@ -63,11 +64,11 @@ public function invalidIdentifiers() } /** - * @test - * @dataProvider invalidIdentifiers * @param $identifier * @throws IdentifierNotValidException */ + #[DataProvider('invalidIdentifiers')] + #[Test] public function ifBogusIdentifierSetInConstructorAnExceptionIsThrown($identifier) { $this->expectException(IdentifierNotValidException::class); @@ -75,9 +76,9 @@ public function ifBogusIdentifierSetInConstructorAnExceptionIsThrown($identifier } /** - * @test * @throws IdentifierNotValidException */ + #[Test] public function constructorSetsRendererClassName() { $formDefinition = new FormDefinition('myForm', [ @@ -91,15 +92,15 @@ public function constructorSetsRendererClassName() } /** - * @test * @throws IdentifierNotValidException */ + #[Test] public function constructorSetsFinishers() { $formDefinition = new FormDefinition('myForm', [ 'finisherPresets' => [ 'myFinisher' => [ - 'implementationClassName' => $this->buildAccessibleProxy(Fixture\EmptyFinisher::class), + 'implementationClassName' => $this->buildAccessibleProxy(EmptyFinisher::class), 'options' => [ 'foo' => 'bar', 'test' => 'asdf' @@ -122,15 +123,15 @@ public function constructorSetsFinishers() $finishers = $formDefinition->getFinishers(); Assert::assertSame(1, count($finishers)); $finisher = $finishers[0]; - $this->assertInstanceOf(Fixture\EmptyFinisher::class, $finisher); + $this->assertInstanceOf(EmptyFinisher::class, $finisher); /** @noinspection PhpUndefinedMethodInspection */ Assert::assertSame(['foo' => 'baz', 'test' => 'asdf'], $finisher->_get('options')); } /** - * @test * @throws IdentifierNotValidException */ + #[Test] public function constructorSetsRenderingOptions() { $formDefinition = new FormDefinition('myForm', [ @@ -147,9 +148,9 @@ public function constructorSetsRenderingOptions() } /** - * @test * @throws IdentifierNotValidException */ + #[Test] public function constructorMakesValidatorPresetsAvailable() { $formDefinition = new FormDefinition('myForm', [ @@ -164,9 +165,9 @@ public function constructorMakesValidatorPresetsAvailable() } /** - * @test * @throws IdentifierNotValidException */ + #[Test] public function constructorThrowsExceptionIfUnknownPropertySet() { $this->expectException(TypeDefinitionNotValidException::class); @@ -179,18 +180,14 @@ public function constructorThrowsExceptionIfUnknownPropertySet() ]); } - /** - * @test - */ + #[Test] public function getPagesReturnsEmptyArrayByDefault() { $formDefinition = new FormDefinition('foo'); Assert::assertSame([], $formDefinition->getPages()); } - /** - * @test - */ + #[Test] public function getPageByIndexThrowsExceptionIfSpecifiedIndexDoesNotExist() { $this->expectException(Exception::class); @@ -198,9 +195,7 @@ public function getPageByIndexThrowsExceptionIfSpecifiedIndexDoesNotExist() $formDefinition->getPageByIndex(0); } - /** - * @test - */ + #[Test] public function hasPageWithIndexReturnsTrueIfTheSpecifiedIndexExists() { $formDefinition = new FormDefinition('foo'); @@ -210,10 +205,10 @@ public function hasPageWithIndexReturnsTrueIfTheSpecifiedIndexExists() } /** - * @test * @throws FormDefinitionConsistencyException * @throws IdentifierNotValidException */ + #[Test] public function hasPageWithIndexReturnsFalseIfTheSpecifiedIndexDoesNotExist() { $formDefinition = new FormDefinition('foo'); @@ -223,9 +218,7 @@ public function hasPageWithIndexReturnsFalseIfTheSpecifiedIndexDoesNotExist() Assert::assertFalse($formDefinition->hasPageWithIndex(1)); } - /** - * @test - */ + #[Test] public function addPageAddsPageToPagesArrayAndSetsBackReferenceToForm() { $formDefinition = new FormDefinition('foo'); @@ -237,9 +230,7 @@ public function addPageAddsPageToPagesArrayAndSetsBackReferenceToForm() Assert::assertSame($page, $formDefinition->getPageByIndex(0)); } - /** - * @test - */ + #[Test] public function addPageAddsIndexToPage() { $formDefinition = new FormDefinition('foo'); @@ -254,10 +245,10 @@ public function addPageAddsIndexToPage() } /** - * @test * @throws FormDefinitionConsistencyException * @throws IdentifierNotValidException */ + #[Test] public function getElementByIdentifierReturnsElementsWhichAreAlreadyAttachedToThePage() { $page = new Page('bar'); @@ -270,9 +261,7 @@ public function getElementByIdentifierReturnsElementsWhichAreAlreadyAttachedToTh Assert::assertSame($mockFormElement, $formDefinition->getElementByIdentifier('myFormElementIdentifier')); } - /** - * @test - */ + #[Test] public function getElementByIdentifierReturnsElementsWhichAreLazilyAttachedToThePage() { $formDefinition = new FormDefinition('foo'); @@ -285,9 +274,7 @@ public function getElementByIdentifierReturnsElementsWhichAreLazilyAttachedToThe Assert::assertSame($mockFormElement, $formDefinition->getElementByIdentifier('myFormElementIdentifier')); } - /** - * @test - */ + #[Test] public function bindReturnsBoundFormRuntime() { $formDefinition = new FormDefinition('foo'); @@ -300,9 +287,7 @@ public function bindReturnsBoundFormRuntime() Assert::assertInstanceOf(FormRuntime::class, $form); } - /** - * @test - */ + #[Test] public function attachingTwoElementsWithSameIdentifierToFormThrowsException1() { $this->expectException(DuplicateFormElementException::class); @@ -318,9 +303,7 @@ public function attachingTwoElementsWithSameIdentifierToFormThrowsException1() $formDefinition->addPage($page); } - /** - * @test - */ + #[Test] public function attachingTwoElementsWithSameIdentifierToFormThrowsException2() { $this->expectException(DuplicateFormElementException::class); @@ -337,9 +320,7 @@ public function attachingTwoElementsWithSameIdentifierToFormThrowsException2() $page->addElement($mockFormElement2); } - /** - * @test - */ + #[Test] public function aPageCanOnlyBeAttachedToASingleFormDefinition() { $this->expectException(FormDefinitionConsistencyException::class); @@ -354,11 +335,11 @@ public function aPageCanOnlyBeAttachedToASingleFormDefinition() } /** - * @test * @throws Exception * @throws IdentifierNotValidException * @throws TypeDefinitionNotFoundException */ + #[Test] public function createPageCreatesPageAndAddsItToForm() { $formDefinition = new FormDefinition('myForm', [ @@ -376,11 +357,11 @@ public function createPageCreatesPageAndAddsItToForm() } /** - * @test * @throws Exception * @throws IdentifierNotValidException * @throws TypeDefinitionNotFoundException */ + #[Test] public function createPageSetsLabelFromTypeDefinition() { $formDefinition = new FormDefinition('myForm', [ @@ -397,11 +378,11 @@ public function createPageSetsLabelFromTypeDefinition() } /** - * @test * @throws Exception * @throws IdentifierNotValidException * @throws TypeDefinitionNotFoundException */ + #[Test] public function createPageSetsRendererClassNameFromTypeDefinition() { $formDefinition = new FormDefinition('myForm', [ @@ -418,11 +399,11 @@ public function createPageSetsRendererClassNameFromTypeDefinition() } /** - * @test * @throws Exception * @throws IdentifierNotValidException * @throws TypeDefinitionNotFoundException */ + #[Test] public function createPageSetsRenderingOptionsFromTypeDefinition() { $formDefinition = new FormDefinition('myForm', [ @@ -439,11 +420,11 @@ public function createPageSetsRenderingOptionsFromTypeDefinition() } /** - * @test * @throws Exception * @throws IdentifierNotValidException * @throws TypeDefinitionNotFoundException */ + #[Test] public function createPageThrowsExceptionIfUnknownPropertyFoundInTypeDefinition() { $this->expectException(TypeDefinitionNotValidException::class); @@ -462,11 +443,11 @@ public function createPageThrowsExceptionIfUnknownPropertyFoundInTypeDefinition( } /** - * @test * @throws Exception * @throws IdentifierNotValidException * @throws TypeDefinitionNotFoundException */ + #[Test] public function createPageThrowsExceptionIfImplementationClassNameNotFound() { $this->expectException(TypeDefinitionNotFoundException::class); @@ -482,18 +463,14 @@ public function createPageThrowsExceptionIfImplementationClassNameNotFound() $formDefinition->createPage('myPage', 'Neos.Form:Page2'); } - /** - * @test - */ + #[Test] public function formFieldTypeManagerIsReturned() { $formDefinition = new FormDefinition('myForm'); Assert::assertInstanceOf(SupertypeResolver::class, $formDefinition->getFormFieldTypeManager()); } - /** - * @test - */ + #[Test] public function movePageBeforeMovesPageBeforeReferenceElement() { $formDefinition = new FormDefinition('foo1'); @@ -517,9 +494,7 @@ public function movePageBeforeMovesPageBeforeReferenceElement() Assert::assertSame([$page2, $page1, $page3], $formDefinition->getPages()); } - /** - * @test - */ + #[Test] public function movePageBeforeThrowsExceptionIfPagesDoNotBelongToSameForm() { $this->expectException(FormDefinitionConsistencyException::class); @@ -532,9 +507,7 @@ public function movePageBeforeThrowsExceptionIfPagesDoNotBelongToSameForm() $formDefinition->movePageBefore($page2, $page1); } - /** - * @test - */ + #[Test] public function movePageAfterMovesPageAfterReferenceElement() { $formDefinition = new FormDefinition('foo1'); @@ -558,9 +531,7 @@ public function movePageAfterMovesPageAfterReferenceElement() Assert::assertSame([$page2, $page1, $page3], $formDefinition->getPages()); } - /** - * @test - */ + #[Test] public function movePageAfterThrowsExceptionIfPagesDoNotBelongToSameForm() { $this->expectException(FormDefinitionConsistencyException::class); @@ -574,10 +545,10 @@ public function movePageAfterThrowsExceptionIfPagesDoNotBelongToSameForm() } /** - * @test * @throws FormDefinitionConsistencyException * @throws IdentifierNotValidException */ + #[Test] public function removePageRemovesPageFromForm() { $formDefinition = new FormDefinition('foo1'); @@ -596,10 +567,10 @@ public function removePageRemovesPageFromForm() } /** - * @test * @throws FormDefinitionConsistencyException * @throws IdentifierNotValidException */ + #[Test] public function removePageRemovesFormElementsOnPageFromForm() { $formDefinition = new FormDefinition('foo1'); @@ -619,9 +590,7 @@ public function removePageRemovesFormElementsOnPageFromForm() $this->assertNull($formDefinition->getElementByIdentifier('el2')); } - /** - * @test - */ + #[Test] public function removePageThrowsExceptionIfPageIsNotOnForm() { $this->expectException(FormDefinitionConsistencyException::class); @@ -631,9 +600,7 @@ public function removePageThrowsExceptionIfPageIsNotOnForm() $formDefinition->removePage($page1); } - /** - * @test - */ + #[Test] public function getProcessingRuleCreatesProcessingRuleIfItDoesNotExistYet() { $formDefinition = new FormDefinition('foo1'); @@ -646,9 +613,7 @@ public function getProcessingRuleCreatesProcessingRuleIfItDoesNotExistYet() Assert::assertSame(['foo' => $processingRule1], $formDefinition->getProcessingRules()); } - /** - * @test - */ + #[Test] public function addFinisherAddsFinishersToList() { $formDefinition = new FormDefinition('foo1'); @@ -658,9 +623,7 @@ public function addFinisherAddsFinishersToList() Assert::assertSame([$finisher], $formDefinition->getFinishers()); } - /** - * @test - */ + #[Test] public function createFinisherThrowsExceptionIfFinisherPresetNotFound() { $this->expectException(FinisherPresetNotFoundException::class); @@ -669,9 +632,7 @@ public function createFinisherThrowsExceptionIfFinisherPresetNotFound() $formDefinition->createFinisher('asdf'); } - /** - * @test - */ + #[Test] public function createFinisherThrowsExceptionIfImplementationClassNameIsEmpty() { $this->expectException(FinisherPresetNotFoundException::class); @@ -680,20 +641,16 @@ public function createFinisherThrowsExceptionIfImplementationClassNameIsEmpty() $formDefinition->createFinisher('asdf'); } - /** - * @test - */ + #[Test] public function createFinisherCreatesFinisherCorrectly() { $formDefinition = $this->getFormDefinitionWithFinisherConfiguration(); $finisher = $formDefinition->createFinisher('email'); - $this->assertInstanceOf(Fixture\EmptyFinisher::class, $finisher); + $this->assertInstanceOf(EmptyFinisher::class, $finisher); Assert::assertSame([$finisher], $formDefinition->getFinishers()); } - /** - * @test - */ + #[Test] public function createFinisherSetsOptionsCorrectly() { $formDefinition = $this->getFormDefinitionWithFinisherConfiguration(); @@ -702,9 +659,7 @@ public function createFinisherSetsOptionsCorrectly() Assert::assertSame(['foo' => 'bar', 'name' => 'asdf'], $finisher->_get('options')); } - /** - * @test - */ + #[Test] public function createFinisherSetsOptionsCorrectlyAndMergesThemWithPassedOptions() { $formDefinition = $this->getFormDefinitionWithFinisherConfiguration(); @@ -724,10 +679,10 @@ protected function getFormDefinitionWithFinisherConfiguration() 'assd' => 'as' ], 'email' => [ - 'implementationClassName' => $this->buildAccessibleProxy(Fixture\EmptyFinisher::class) + 'implementationClassName' => $this->buildAccessibleProxy(EmptyFinisher::class) ], 'emailWithOptions' => [ - 'implementationClassName' => $this->buildAccessibleProxy(Fixture\EmptyFinisher::class), + 'implementationClassName' => $this->buildAccessibleProxy(EmptyFinisher::class), 'options' => [ 'foo' => 'bar', 'name' => 'asdf' @@ -755,8 +710,8 @@ protected function getMockFinisher() */ protected function getMockFormElement($identifier) { - $mockFormElement = $this->getMockBuilder(AbstractFormElement::class)->setMethods(['getIdentifier'])->disableOriginalConstructor()->getMock(); - $mockFormElement->expects($this->any())->method('getIdentifier')->will($this->returnValue($identifier)); + $mockFormElement = $this->getMockBuilder(AbstractFormElement::class)->onlyMethods(['getIdentifier'])->disableOriginalConstructor()->getMock(); + $mockFormElement->expects($this->any())->method('getIdentifier')->willReturn($identifier); return $mockFormElement; } diff --git a/Tests/Unit/Core/Model/PageTest.php b/Tests/Unit/Core/Model/PageTest.php index b248c945..e26a0582 100644 --- a/Tests/Unit/Core/Model/PageTest.php +++ b/Tests/Unit/Core/Model/PageTest.php @@ -10,7 +10,9 @@ * information, please view the LICENSE file which was distributed with this * source code. */ - +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\Attributes\DataProvider; use Neos\Flow\Tests\UnitTestCase; use Neos\Flow\Validation\Validator\ConjunctionValidator; use Neos\Flow\Validation\Validator\NotEmptyValidator; @@ -33,14 +35,12 @@ /** * Test for Page Domain Model - * @covers \Neos\Form\Core\Model\Page - * @covers \Neos\Form\Core\Model\AbstractFormElement */ +#[CoversClass(Page::class)] +#[CoversClass(AbstractFormElement::class)] class PageTest extends UnitTestCase { - /** - * @test - */ + #[Test] public function identifierSetInConstructorCanBeReadAgain() { $page = new Page('foo'); @@ -50,25 +50,21 @@ public function identifierSetInConstructorCanBeReadAgain() Assert::assertSame('bar', $page->getIdentifier()); } - /** - * @test - */ + #[Test] public function defaultTypeIsCorrect() { $page = new Page('foo'); Assert::assertSame('Neos.Form:Page', $page->getType()); } - /** - * @test - */ + #[Test] public function typeCanBeOverridden() { $page = new Page('foo', 'Neos.Foo:Bar'); Assert::assertSame('Neos.Foo:Bar', $page->getType()); } - public function invalidIdentifiers() + public static function invalidIdentifiers() { return [ 'Null Identifier' => [null], @@ -78,69 +74,61 @@ public function invalidIdentifiers() } /** - * @test - * @dataProvider invalidIdentifiers * @param mixed $identifier * @throws IdentifierNotValidException */ + #[DataProvider('invalidIdentifiers')] + #[Test] public function ifBogusIdentifierSetInConstructorAnExceptionIsThrown($identifier) { $this->expectException(IdentifierNotValidException::class); new Page($identifier); } - /** - * @test - */ + #[Test] public function getElementsReturnsEmptyArrayByDefault() { $page = new Page('foo'); Assert::assertSame([], $page->getElements()); } - /** - * @test - */ + #[Test] public function getElementsRecursivelyReturnsEmptyArrayByDefault() { $page = new Page('foo'); Assert::assertSame([], $page->getElementsRecursively()); } - /** - * @test - */ + #[Test] public function getElementsRecursivelyReturnsFirstLevelFormElements() { $page = new Page('foo'); /** @var AbstractFormElement|MockObject $element1 */ - $element1 = $this->getMockBuilder(AbstractFormElement::class)->setMethods(['dummy'])->disableOriginalConstructor()->getMock(); + $element1 = $this->getMockBuilder(AbstractFormElement::class)->addMethods(['dummy'])->disableOriginalConstructor()->getMock(); /** @var AbstractFormElement|MockObject $element2 */ - $element2 = $this->getMockBuilder(AbstractFormElement::class)->setMethods(['dummy'])->disableOriginalConstructor()->getMock(); + $element2 = $this->getMockBuilder(AbstractFormElement::class)->addMethods(['dummy'])->disableOriginalConstructor()->getMock(); $page->addElement($element1); $page->addElement($element2); Assert::assertSame([$element1, $element2], $page->getElementsRecursively()); } - /** - * @test - */ + #[Test] public function getElementsRecursivelyReturnsRecursiveFormElementsInCorrectOrder() { $page = new Page('foo'); /** @var AbstractFormElement|MockObject $element1 */ - $element1 = $this->getMockBuilder(AbstractFormElement::class)->setMethods(['dummy'])->disableOriginalConstructor()->getMock(); + $element1 = $this->getMockBuilder(AbstractFormElement::class)->addMethods(['dummy'])->disableOriginalConstructor()->getMock(); /** @var Section|MockObject $element2 */ - $element2 = $this->getMockBuilder(Section::class)->setMethods(['dummy'])->disableOriginalConstructor()->getMock(); + $element2 = $this->getMockBuilder(Section::class)->addMethods(['dummy'])->disableOriginalConstructor()->getMock(); /** @var AbstractFormElement|MockObject $element21 */ - $element21 = $this->getMockBuilder(AbstractFormElement::class)->setMethods(['dummy'])->disableOriginalConstructor()->getMock(); + $element21 = $this->getMockBuilder(AbstractFormElement::class)->addMethods(['dummy'])->disableOriginalConstructor()->getMock(); /** @var AbstractFormElement|MockObject $element22 */ - $element22 = $this->getMockBuilder(AbstractFormElement::class)->setMethods(['dummy'])->disableOriginalConstructor()->getMock(); + $element22 = $this->getMockBuilder(AbstractFormElement::class)->addMethods(['dummy'])->disableOriginalConstructor()->getMock(); $element2->addElement($element21); $element2->addElement($element22); /** @var AbstractFormElement|MockObject $element3 */ - $element3 = $this->getMockBuilder(AbstractFormElement::class)->setMethods(['dummy'])->disableOriginalConstructor()->getMock(); + $element3 = $this->getMockBuilder(AbstractFormElement::class)->addMethods(['dummy'])->disableOriginalConstructor()->getMock(); $page->addElement($element1); $page->addElement($element2); @@ -148,15 +136,13 @@ public function getElementsRecursivelyReturnsRecursiveFormElementsInCorrectOrder Assert::assertSame([$element1, $element2, $element21, $element22, $element3], $page->getElementsRecursively()); } - /** - * @test - */ + #[Test] public function aFormElementCanOnlyBeAttachedToASinglePage() { $this->expectException(FormDefinitionConsistencyException::class); /** @var AbstractFormElement|MockObject $element */ - $element = $this->getMockBuilder(AbstractFormElement::class)->setMethods(['dummy'])->disableOriginalConstructor()->getMock(); + $element = $this->getMockBuilder(AbstractFormElement::class)->addMethods(['dummy'])->disableOriginalConstructor()->getMock(); $page1 = new Page('bar1'); $page2 = new Page('bar2'); @@ -165,22 +151,18 @@ public function aFormElementCanOnlyBeAttachedToASinglePage() $page2->addElement($element); } - /** - * @test - */ + #[Test] public function addElementAddsElementAndSetsBackReferenceToPage() { $page = new Page('bar'); /** @var AbstractFormElement|MockObject $element */ - $element = $this->getMockBuilder(AbstractFormElement::class)->setMethods(['dummy'])->disableOriginalConstructor()->getMock(); + $element = $this->getMockBuilder(AbstractFormElement::class)->addMethods(['dummy'])->disableOriginalConstructor()->getMock(); $page->addElement($element); Assert::assertSame([$element], $page->getElements()); Assert::assertSame($page, $element->getParentRenderable()); } - /** - * @test - */ + #[Test] public function createElementCreatesElementAndAddsItToForm() { $formDefinition = $this->getDummyFormDefinition(); @@ -193,9 +175,7 @@ public function createElementCreatesElementAndAddsItToForm() Assert::assertSame([$element], $page->getElements()); } - /** - * @test - */ + #[Test] public function createElementSetsAdditionalPropertiesInElement() { $formDefinition = $this->getDummyFormDefinition(); @@ -209,9 +189,7 @@ public function createElementSetsAdditionalPropertiesInElement() Assert::assertSame('MyRendererClassName', $element->getRendererClassName()); } - /** - * @test - */ + #[Test] public function createElementThrowsExceptionIfPageIsNotAttachedToParentForm() { $this->expectException(FormDefinitionConsistencyException::class); @@ -219,9 +197,7 @@ public function createElementThrowsExceptionIfPageIsNotAttachedToParentForm() $page->createElement('myElement', 'Neos.Form:MyElementType'); } - /** - * @test - */ + #[Test] public function createElementThrowsExceptionIfImplementationClassNameNotFound() { $this->expectException(TypeDefinitionNotFoundException::class); @@ -231,9 +207,7 @@ public function createElementThrowsExceptionIfImplementationClassNameNotFound() $page->createElement('myElement', 'Neos.Form:MyElementTypeWithoutImplementationClassName'); } - /** - * @test - */ + #[Test] public function createElementThrowsExceptionIfImplementationClassNameDoesNotImplementFormElementInterface() { $this->expectException(TypeDefinitionNotValidException::class); @@ -243,9 +217,7 @@ public function createElementThrowsExceptionIfImplementationClassNameDoesNotImpl $page->createElement('myElement', 'Neos.Form:MyElementTypeWhichDoesNotImplementFormElementInterface'); } - /** - * @test - */ + #[Test] public function createElementThrowsExceptionIfUnknownPropertyFoundInTypeDefinition() { $this->expectException(TypeDefinitionNotValidException::class); @@ -255,9 +227,7 @@ public function createElementThrowsExceptionIfUnknownPropertyFoundInTypeDefiniti $page->createElement('myElement', 'Neos.Form:MyElementTypeWithUnknownProperties'); } - /** - * @test - */ + #[Test] public function moveElementBeforeMovesElementBeforeReferenceElement() { $formDefinition = $this->getDummyFormDefinition(); @@ -270,9 +240,7 @@ public function moveElementBeforeMovesElementBeforeReferenceElement() Assert::assertSame([$element2, $element1], $page->getElements()); } - /** - * @test - */ + #[Test] public function moveElementBeforeThrowsExceptionIfElementsAreNotOnSamePage() { $this->expectException(FormDefinitionConsistencyException::class); @@ -287,9 +255,7 @@ public function moveElementBeforeThrowsExceptionIfElementsAreNotOnSamePage() $page1->moveElementBefore($element1, $element2); } - /** - * @test - */ + #[Test] public function moveElementAfterMovesElementAfterReferenceElement() { $formDefinition = $this->getDummyFormDefinition(); @@ -302,9 +268,7 @@ public function moveElementAfterMovesElementAfterReferenceElement() Assert::assertSame([$element2, $element1], $page->getElements()); } - /** - * @test - */ + #[Test] public function moveElementAfterThrowsExceptionIfElementsAreNotOnSamePage() { $this->expectException(FormDefinitionConsistencyException::class); @@ -319,9 +283,7 @@ public function moveElementAfterThrowsExceptionIfElementsAreNotOnSamePage() $page1->moveElementAfter($element1, $element2); } - /** - * @test - */ + #[Test] public function removeElementRemovesElementFromCurrentPageAndUnregistersItFromForm() { $formDefinition = $this->getDummyFormDefinition(); @@ -337,23 +299,19 @@ public function removeElementRemovesElementFromCurrentPageAndUnregistersItFromFo $this->assertNull($element1->getParentRenderable()); } - /** - * @test - */ + #[Test] public function removeElementThrowsExceptionIfElementIsNotOnCurrentPage() { $this->expectException(FormDefinitionConsistencyException::class); $formDefinition = $this->getDummyFormDefinition(); $page1 = $formDefinition->createPage('myPage1'); /** @var AbstractFormElement|MockObject $element1 */ - $element1 = $this->getMockBuilder(AbstractFormElement::class)->setMethods(['dummy'])->disableOriginalConstructor()->getMock(); + $element1 = $this->getMockBuilder(AbstractFormElement::class)->addMethods(['dummy'])->disableOriginalConstructor()->getMock(); $page1->removeElement($element1); } - /** - * @test - */ + #[Test] public function validatorKeyCorrectlyAddsValidator() { $formDefinition = $this->getDummyFormDefinition(); @@ -361,7 +319,7 @@ public function validatorKeyCorrectlyAddsValidator() $mockProcessingRule = $this->getAccessibleMock(ProcessingRule::class, ['dummy']); /** @noinspection PhpUndefinedMethodInspection */ $mockProcessingRule->_set('validator', new ConjunctionValidator()); - $formDefinition->expects($this->any())->method('getProcessingRule')->with('asdf')->will($this->returnValue($mockProcessingRule)); + $formDefinition->expects($this->any())->method('getProcessingRule')->with('asdf')->willReturn($mockProcessingRule); $page1 = $formDefinition->createPage('myPage1'); /** @var AbstractFormElement|MockObject $element */ @@ -378,9 +336,7 @@ public function validatorKeyCorrectlyAddsValidator() Assert::assertSame($validatorOptions['maximum'], PHP_INT_MAX); } - /** - * @test - */ + #[Test] public function validatorKeyThrowsExceptionIfValidatorPresetIsNotFound() { $this->expectException(ValidatorPresetNotFoundException::class); @@ -458,7 +414,7 @@ protected function getDummyFormDefinition() ] ]]; - $formDefinition = $this->getMockBuilder(FormDefinition::class)->setMethods(['getProcessingRule'])->setConstructorArgs($formDefinitionConstructorArguments)->getMock(); + $formDefinition = $this->getMockBuilder(FormDefinition::class)->onlyMethods(['getProcessingRule'])->setConstructorArgs($formDefinitionConstructorArguments)->getMock(); return $formDefinition; } } diff --git a/Tests/Unit/Core/Model/ProcessingRuleTest.php b/Tests/Unit/Core/Model/ProcessingRuleTest.php index 4f5fd6e0..fb7c6e79 100644 --- a/Tests/Unit/Core/Model/ProcessingRuleTest.php +++ b/Tests/Unit/Core/Model/ProcessingRuleTest.php @@ -10,7 +10,8 @@ * information, please view the LICENSE file which was distributed with this * source code. */ - +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Test; use Neos\Error\Messages\Error; use Neos\Error\Messages\Result; use Neos\Flow\Property\PropertyMapper; @@ -23,8 +24,8 @@ /** * Test for ProcessingRule Domain Model - * @covers \Neos\Form\Core\Model\ProcessingRule */ +#[CoversClass(ProcessingRule::class)] class ProcessingRuleTest extends UnitTestCase { /** @@ -46,35 +47,29 @@ public function setUp(): void $this->inject($this->processingRule, 'propertyMapper', $this->mockPropertyMapper); } - /** - * @test - */ + #[Test] public function getDataTypeReturnsNullByDefault() { $this->assertNull($this->processingRule->getDataType()); } - /** - * @test - */ + #[Test] public function getDataTypeReturnsSpecifiedDataType() { $this->processingRule->setDataType('SomeDataType'); Assert::assertSame('SomeDataType', $this->processingRule->getDataType()); } - /** - * @test - */ + #[Test] public function getValidatorsReturnsAnEmptyCollectionByDefault() { Assert::assertSame(0, count($this->processingRule->getValidators())); } /** - * @test * @throws \ReflectionException */ + #[Test] public function getValidatorsReturnsPreviouslyAddedValidators() { /** @var ValidatorInterface $mockValidator1 */ @@ -89,18 +84,14 @@ public function getValidatorsReturnsPreviouslyAddedValidators() Assert::assertTrue($validators->contains($mockValidator2)); } - /** - * @test - */ + #[Test] public function processReturnsTheUnchangedValueByDefault() { $actualResult = $this->processingRule->process('Some Value'); Assert::assertEquals('Some Value', $actualResult); } - /** - * @test - */ + #[Test] public function processingMessagesCanBeModifiedBeforeProcessing() { $this->processingRule->getProcessingMessages()->addError(new Error('Test')); @@ -108,25 +99,21 @@ public function processingMessagesCanBeModifiedBeforeProcessing() Assert::assertTrue($this->processingRule->getProcessingMessages()->hasErrors()); } - /** - * @test - */ + #[Test] public function processDoesNotConvertValueIfTargetTypeIsNotSpecified() { $this->mockPropertyMapper->expects($this->never())->method('convert'); $this->processingRule->process('Some Value'); } - /** - * @test - */ + #[Test] public function processConvertsValueIfDataTypeIsSpecified() { $this->processingRule->setDataType('SomeDataType'); $propertyMappingConfiguration = $this->processingRule->getPropertyMappingConfiguration(); - $this->mockPropertyMapper->expects($this->once())->method('convert')->with('Some Value', 'SomeDataType', $propertyMappingConfiguration)->will($this->returnValue('Converted Value')); - $this->mockPropertyMapper->expects($this->any())->method('getMessages')->will($this->returnValue(new Result())); + $this->mockPropertyMapper->expects($this->once())->method('convert')->with('Some Value', 'SomeDataType', $propertyMappingConfiguration)->willReturn('Converted Value'); + $this->mockPropertyMapper->expects($this->any())->method('getMessages')->willReturn(new Result()); Assert::assertEquals('Converted Value', $this->processingRule->process('Some Value')); } } diff --git a/Tests/Unit/Core/Renderer/FormRuntimeTest.php b/Tests/Unit/Core/Renderer/FormRuntimeTest.php index 52130061..5a5f6f84 100644 --- a/Tests/Unit/Core/Renderer/FormRuntimeTest.php +++ b/Tests/Unit/Core/Renderer/FormRuntimeTest.php @@ -10,7 +10,10 @@ * information, please view the LICENSE file which was distributed with this * source code. */ - +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Test; +use Neos\Form\Tests\Unit\Core\Runtime\Renderer\Fixture\DummyFinisher; +use PHPUnit\Framework\MockObject\MockObject; use Neos\Flow\Mvc\ActionRequest; use Neos\Flow\Mvc\ActionResponse; use Neos\Flow\Tests\UnitTestCase; @@ -25,21 +28,18 @@ /** * Test for Form Runtime - * - * @covers \Neos\Form\Core\Runtime\FormRuntime */ +#[CoversClass(FormRuntime::class)] class FormRuntimeTest extends UnitTestCase { - /** - * @test - */ + #[Test] public function valuesSetInConstructorCanBeReadAgain() { $formDefinition = new FormDefinition('foo'); - $mockActionRequest = $this->getMockBuilder(ActionRequest::class)->setMethods(['createSubRequest'])->disableOriginalConstructor()->getMock(); + $mockActionRequest = $this->getMockBuilder(ActionRequest::class)->onlyMethods(['createSubRequest'])->disableOriginalConstructor()->getMock(); - $mockFormSubRequest = $this->getMockBuilder(ActionRequest::class)->setMethods(['getParentRequest'])->disableOriginalConstructor()->getMock(); + $mockFormSubRequest = $this->getMockBuilder(ActionRequest::class)->onlyMethods(['getParentRequest'])->disableOriginalConstructor()->getMock(); $mockFormSubRequest->expects(self::any())->method('getParentRequest')->willReturn($mockActionRequest); $mockActionRequest->expects(self::once())->method('createSubRequest')->willReturn($mockFormSubRequest); @@ -52,9 +52,7 @@ public function valuesSetInConstructorCanBeReadAgain() Assert::assertSame($formDefinition, $formRuntime->_get('formDefinition')); } - /** - * @test - */ + #[Test] public function getTypeReturnsTypeOfFormDefinition() { $formDefinition = new FormDefinition('foo'); @@ -62,9 +60,7 @@ public function getTypeReturnsTypeOfFormDefinition() Assert::assertSame('Neos.Form:Form', $formRuntime->getType()); } - /** - * @test - */ + #[Test] public function getIdentifierReturnsIdentifierOfFormDefinition() { $formDefinition = new FormDefinition('foo'); @@ -72,9 +68,7 @@ public function getIdentifierReturnsIdentifierOfFormDefinition() Assert::assertSame('foo', $formRuntime->getIdentifier()); } - /** - * @test - */ + #[Test] public function getRenderingOptionsReturnsRenderingOptionsOfFormDefinition() { $formDefinition = new FormDefinition('foo'); @@ -83,9 +77,7 @@ public function getRenderingOptionsReturnsRenderingOptionsOfFormDefinition() Assert::assertSame(['asdf' => 'test'], $formRuntime->getRenderingOptions()); } - /** - * @test - */ + #[Test] public function getRendererClassNameReturnsRendererClassNameOfFormDefinition() { $formDefinition = new FormDefinition('foo'); @@ -94,9 +86,7 @@ public function getRendererClassNameReturnsRendererClassNameOfFormDefinition() Assert::assertSame('MyRendererClassName', $formRuntime->getRendererClassName()); } - /** - * @test - */ + #[Test] public function getLabelReturnsLabelOfFormDefinition() { $formDefinition = new FormDefinition('foo'); @@ -105,9 +95,7 @@ public function getLabelReturnsLabelOfFormDefinition() Assert::assertSame('my cool label', $formRuntime->getLabel()); } - /** - * @test - */ + #[Test] public function invokeFinishersInvokesFinishersInCorrectOrder() { $formDefinition = new FormDefinition('foo'); @@ -141,15 +129,13 @@ public function invokeFinishersInvokesFinishersInCorrectOrder() */ protected function getMockFinisher(\Closure $closureToExecute) { - $finisher = new Renderer\Fixture\DummyFinisher(); + $finisher = new DummyFinisher(); $finisher->cb = $closureToExecute; return $finisher; } - /** - * @test - */ + #[Test] public function pageNavigationWorks() { $formDefinition = new FormDefinition('foo'); @@ -179,9 +165,7 @@ public function pageNavigationWorks() Assert::assertSame(null, $formRuntime->getNextPage()); } - /** - * @test - */ + #[Test] public function arrayAccessReturnsDefaultValuesIfSet() { $formDefinition = new FormDefinition('foo'); @@ -213,7 +197,7 @@ public function arrayAccessReturnsDefaultValuesIfSet() /** * @param FormDefinition $formDefinition - * @return FormRuntime|\PHPUnit\Framework\MockObject\MockObject + * @return FormRuntime|MockObject */ protected function createFormRuntime(FormDefinition $formDefinition) { diff --git a/Tests/Unit/Factory/AbstractFormFactoryTest.php b/Tests/Unit/Factory/AbstractFormFactoryTest.php index 02937315..6c4b6595 100644 --- a/Tests/Unit/Factory/AbstractFormFactoryTest.php +++ b/Tests/Unit/Factory/AbstractFormFactoryTest.php @@ -10,7 +10,10 @@ * information, please view the LICENSE file which was distributed with this * source code. */ - +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\MockObject\MockObject; use Neos\Flow\Configuration\ConfigurationManager; use Neos\Flow\Tests\UnitTestCase; use Neos\Form\Exception\PresetNotFoundException; @@ -19,11 +22,11 @@ /** * Test for Supertype Resolver - * @covers \Neos\Form\Factory\AbstractFormFactory */ +#[CoversClass(AbstractFormFactory::class)] class AbstractFormFactoryTest extends UnitTestCase { - public function dataProviderForConfigurationMerging() + public static function dataProviderForConfigurationMerging() { $presets = [ 'default' => [ @@ -86,10 +89,8 @@ public function dataProviderForConfigurationMerging() ]; } - /** - * @dataProvider dataProviderForConfigurationMerging - * @test - */ + #[DataProvider('dataProviderForConfigurationMerging')] + #[Test] public function getPresetConfigurationReturnsCorrectConfigurationForPresets($presets, $presetName, $expected) { $abstractFormFactory = $this->getAbstractFormFactory(); @@ -101,9 +102,7 @@ public function getPresetConfigurationReturnsCorrectConfigurationForPresets($pre Assert::assertSame($expected, $actual); } - /** - * @test - */ + #[Test] public function getPresetConfigurationThrowsExceptionIfPresetIsNotFound() { $this->expectException(PresetNotFoundException::class); @@ -111,9 +110,7 @@ public function getPresetConfigurationThrowsExceptionIfPresetIsNotFound() $abstractFormFactory->_call('getPresetConfiguration', 'NonExistingPreset'); } - /** - * @test - */ + #[Test] public function initializeObjectLoadsSettings() { $abstractFormFactory = $this->getAbstractFormFactory(); @@ -122,7 +119,7 @@ public function initializeObjectLoadsSettings() ->expects($this->once()) ->method('getConfiguration') ->with(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.Form') - ->will($this->returnValue('MyConfig')); + ->willReturn('MyConfig'); $abstractFormFactory->_set('configurationManager', $mockConfigurationManager); $abstractFormFactory->_call('initializeObject'); @@ -130,18 +127,16 @@ public function initializeObjectLoadsSettings() } /** - * @return AbstractFormFactory|\PHPUnit\Framework\MockObject\MockObject + * @return AbstractFormFactory|MockObject */ protected function getAbstractFormFactory() { return $this->getAccessibleMock(AbstractFormFactory::class, ['build']); } - /** - * @dataProvider dataProviderForConfigurationMerging - * @test - */ - public function getPresetsWorks($presets) + #[DataProvider('dataProviderForConfigurationMerging')] + #[Test] + public function getPresetsWorks($presets, $presetName, $expected) { $abstractFormFactory = $this->getAbstractFormFactory(); $abstractFormFactory->_set('formSettings', [ diff --git a/Tests/Unit/Factory/ArrayFormFactoryTest.php b/Tests/Unit/Factory/ArrayFormFactoryTest.php index bc17cc2e..e56329a3 100644 --- a/Tests/Unit/Factory/ArrayFormFactoryTest.php +++ b/Tests/Unit/Factory/ArrayFormFactoryTest.php @@ -10,7 +10,8 @@ * information, please view the LICENSE file which was distributed with this * source code. */ - +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Test; use Neos\Flow\Tests\UnitTestCase; use Neos\Form\Core\Model\Page; use Neos\Form\Exception\IdentifierNotValidException; @@ -18,14 +19,10 @@ use Neos\Form\FormElements\GenericFormElement; use PHPUnit\Framework\Assert; -/** - * @covers \Neos\Form\Factory\ArrayFormFactory - */ +#[CoversClass(ArrayFormFactory::class)] class ArrayFormFactoryTest extends UnitTestCase { - /** - * @test - */ + #[Test] public function simpleFormObjectIsReturned() { $factory = $this->getArrayFormFactory(); @@ -37,9 +34,7 @@ public function simpleFormObjectIsReturned() Assert::assertSame('myFormIdentifier', $form->getIdentifier()); } - /** - * @test - */ + #[Test] public function formObjectWithSubRenderablesIsReturned() { $factory = $this->getArrayFormFactory(); @@ -75,9 +70,7 @@ public function formObjectWithSubRenderablesIsReturned() Assert::assertSame(['options' => ['MyKey' => 'MyValue']], $element1->getProperties()); } - /** - * @test - */ + #[Test] public function renderableWithoutIdentifierThrowsException() { $this->expectException(IdentifierNotValidException::class); diff --git a/Tests/Unit/Persistence/YamlPersistenceManagerTest.php b/Tests/Unit/Persistence/YamlPersistenceManagerTest.php index e2fa7f8f..a128034a 100644 --- a/Tests/Unit/Persistence/YamlPersistenceManagerTest.php +++ b/Tests/Unit/Persistence/YamlPersistenceManagerTest.php @@ -10,7 +10,8 @@ * information, please view the LICENSE file which was distributed with this * source code. */ - +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Test; use Neos\Flow\Tests\UnitTestCase; use Neos\Form\Exception\PersistenceManagerException; use Neos\Form\Persistence\YamlPersistenceManager; @@ -18,9 +19,7 @@ use org\bovigo\vfs\vfsStreamWrapper; use PHPUnit\Framework\Assert; -/** - * @covers \Neos\Form\Persistence\YamlPersistenceManager - */ +#[CoversClass(YamlPersistenceManager::class)] class YamlPersistenceManagerTest extends UnitTestCase { /** @@ -41,9 +40,7 @@ public function setUp(): void ); } - /** - * @test - */ + #[Test] public function injectSettingsCreatesSaveDirectoryIfItDoesntExist() { Assert::assertFalse(vfsStreamWrapper::getRoot()->hasChild('foo/bar')); @@ -58,9 +55,7 @@ public function injectSettingsCreatesSaveDirectoryIfItDoesntExist() } - /** - * @test - */ + #[Test] public function loadThrowsExceptionIfSavePathIsNotSet() { $this->expectException(PersistenceManagerException::class); @@ -68,9 +63,7 @@ public function loadThrowsExceptionIfSavePathIsNotSet() $yamlPersistenceManager->load('dummy'); } - /** - * @test - */ + #[Test] public function loadThrowsExceptionIfSpecifiedFormDoesNotExist() { $this->expectException(PersistenceManagerException::class); @@ -85,9 +78,7 @@ public function loadThrowsExceptionIfSpecifiedFormDoesNotExist() $yamlPersistenceManager->load('someNonExistingPersistenceIdentifier'); } - /** - * @test - */ + #[Test] public function loadReturnsFormDefinitionAsArray() { $mockYamlFormDefinition = 'type: \'Neos.Form:Form\' @@ -105,9 +96,7 @@ public function loadReturnsFormDefinitionAsArray() Assert::assertEquals($expectedResult, $actualResult); } - /** - * @test - */ + #[Test] public function saveStoresFormDefinitionAsYaml() { $mockArrayFormDefinition = [ @@ -126,17 +115,13 @@ public function saveStoresFormDefinitionAsYaml() Assert::assertEquals($expectedResult, $actualResult); } - /** - * @test - */ + #[Test] public function existsReturnsFalseIfTheSpecifiedFormDoesNotExist() { $this->assertFalse($this->yamlPersistenceManager->exists('someNonExistingPersistenceIdentifier')); } - /** - * @test - */ + #[Test] public function existsReturnsTrueIfTheSpecifiedFormExists() { $mockYamlFormDefinition = 'type: \'Neos.Form:Form\' @@ -147,9 +132,7 @@ public function existsReturnsTrueIfTheSpecifiedFormExists() Assert::assertTrue($this->yamlPersistenceManager->exists('mockFormPersistenceIdentifier')); } - /** - * @test - */ + #[Test] public function listFormsThrowsExceptionIfSavePathIsNotSet() { $this->expectException(PersistenceManagerException::class); @@ -158,17 +141,13 @@ public function listFormsThrowsExceptionIfSavePathIsNotSet() } - /** - * @test - */ + #[Test] public function listFormsReturnsAnEmptyArrayIfNoFormsAreAvailable() { Assert::assertEquals([], $this->yamlPersistenceManager->listForms()); } - /** - * @test - */ + #[Test] public function listFormsReturnsAvailableForms() { $mockYamlFormDefinition1 = 'type: \'Neos.Form:Form\' diff --git a/Tests/Unit/Utility/SupertypeResolverTest.php b/Tests/Unit/Utility/SupertypeResolverTest.php index 342e797c..1abcb418 100644 --- a/Tests/Unit/Utility/SupertypeResolverTest.php +++ b/Tests/Unit/Utility/SupertypeResolverTest.php @@ -10,7 +10,9 @@ * information, please view the LICENSE file which was distributed with this * source code. */ - +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Neos\Flow\Tests\UnitTestCase; use Neos\Form\Exception\TypeDefinitionNotFoundException; use Neos\Form\Utility\SupertypeResolver; @@ -18,11 +20,11 @@ /** * Test for Supertype Resolver - * @covers \Neos\Form\Utility\SupertypeResolver */ +#[CoversClass(SupertypeResolver::class)] class SupertypeResolverTest extends UnitTestCase { - public function dataProviderForTypeResolving() + public static function dataProviderForTypeResolving() { $types = [ 'typeFoo' => [ @@ -124,19 +126,15 @@ public function dataProviderForTypeResolving() ]; } - /** - * @dataProvider dataProviderForTypeResolving - * @test - */ + #[DataProvider('dataProviderForTypeResolving')] + #[Test] public function getMergedTypeDefinitionWorks($types, $typeName, $expected) { $supertypeResolver = new SupertypeResolver($types); Assert::assertSame($expected, $supertypeResolver->getMergedTypeDefinition($typeName)); } - /** - * @test - */ + #[Test] public function getMergedTypeDefinitionThrowsExceptionIfTypeNotFound() { $this->expectException(TypeDefinitionNotFoundException::class); diff --git a/Tests/Unit/ViewHelpers/FormViewHelperTest.php b/Tests/Unit/ViewHelpers/FormViewHelperTest.php index c3e7dad2..1f981a53 100644 --- a/Tests/Unit/ViewHelpers/FormViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/FormViewHelperTest.php @@ -10,7 +10,9 @@ * information, please view the LICENSE file which was distributed with this * source code. */ - +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\MockObject\MockObject; use GuzzleHttp\Psr7\Uri; use Neos\Flow\Mvc\ActionRequest; use Neos\Flow\Mvc\Controller\ControllerContext; @@ -30,7 +32,7 @@ class FormViewHelperTest extends UnitTestCase protected $formViewHelper; /** - * @var ControllerContext|\PHPUnit\Framework\MockObject\MockObject + * @var ControllerContext|MockObject */ protected $mockControllerContext; @@ -46,7 +48,7 @@ public function setUp(): void /** * @return array */ - public function getFormActionUriDataProvider() + public static function getFormActionUriDataProvider() { return [ ['requestUri' => '', 'sectionArgument' => null, 'expectedResult' => ''], @@ -66,32 +68,32 @@ public function getFormActionUriDataProvider() } /** - * @test * @param string $requestUri * @param string $sectionArgument * @param string $expectedResult - * @dataProvider getFormActionUriDataProvider * @throws \ReflectionException */ + #[DataProvider('getFormActionUriDataProvider')] + #[Test] public function getFormActionUriTests($requestUri, $sectionArgument, $expectedResult) { $mockActionRequest = $this->getMockBuilder(ActionRequest::class)->disableOriginalConstructor()->getMock(); - $this->mockControllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($mockActionRequest)); + $this->mockControllerContext->expects($this->any())->method('getRequest')->willReturn($mockActionRequest); $mockHttpRequest = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock(); - $mockActionRequest->expects($this->any())->method('getHttpRequest')->will($this->returnValue($mockHttpRequest)); + $mockActionRequest->expects($this->any())->method('getHttpRequest')->willReturn($mockHttpRequest); $mockUri = $this->getMockBuilder(Uri::class)->disableOriginalConstructor()->getMock(); - $mockUri->expects($this->any())->method('withFragment')->will($this->returnCallback(function ($fragment) use ($requestUri, $mockUri) { + $mockUri->expects($this->any())->method('withFragment')->willReturnCallback(function ($fragment) use ($requestUri, $mockUri) { $newUri = explode('#', $requestUri)[0] . '#' . $fragment; $modifiedMockUri = $this->getMockBuilder(Uri::class)->disableOriginalConstructor()->getMock(); - $modifiedMockUri->expects($this->any())->method('__toString')->will($this->returnValue($newUri)); + $modifiedMockUri->expects($this->any())->method('__toString')->willReturn($newUri); return $modifiedMockUri; - })); - $mockUri->expects($this->any())->method('__toString')->will($this->returnValue($requestUri)); - $mockHttpRequest->expects($this->any())->method('getUri')->will($this->returnValue($mockUri)); + }); + $mockUri->expects($this->any())->method('__toString')->willReturn($requestUri); + $mockHttpRequest->expects($this->any())->method('getUri')->willReturn($mockUri); - $this->formViewHelper->expects($this->any())->method('hasArgument')->with('section')->will($this->returnValue($sectionArgument !== null)); + $this->formViewHelper->expects($this->any())->method('hasArgument')->with('section')->willReturn($sectionArgument !== null); $this->formViewHelper->_set('arguments', ['section' => $sectionArgument]); Assert::assertSame($expectedResult, $this->formViewHelper->_call('getFormActionUri')); diff --git a/composer.json b/composer.json index 56771369..5794f0c8 100755 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "description": "Extensible and flexible API for building web forms", "require": { "php": "^8.2", - "neos/flow": "^8.0 || ^9.0" + "neos/flow": "^8.4 || ^9.0" }, "replace": { "typo3/form": "self.version"