diff --git a/composer.json b/composer.json index 59c4aaaf..224584ec 100644 --- a/composer.json +++ b/composer.json @@ -38,6 +38,7 @@ "laminas/laminas-validator": "^2.15" }, "require-dev": { + "ext-json": "*", "laminas/laminas-coding-standard": "~2.4.0", "laminas/laminas-db": "^2.15.0", "phpunit/phpunit": "^9.5.24", @@ -62,6 +63,7 @@ "scripts": { "check": [ "@cs-check", + "@static-analysis", "@test" ], "cs-check": "phpcs", diff --git a/psalm-baseline.xml b/psalm-baseline.xml index a5ca33e8..86dd97cb 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + ArrayInput @@ -36,9 +36,6 @@ - - $this->inputs - $messages @@ -159,9 +156,6 @@ $this->notEmptyValidator - - $this->implementation === null - $this->prepareRequiredValidationFailureMessage() @@ -171,12 +165,6 @@ $value - - null - - - $implementation - @@ -331,7 +319,7 @@ - + string[] @@ -376,12 +364,10 @@ - + $input $input ['nested' => ['nested-input1', 'nested-input2']] - new stdClass() - new stdClass() public function addMethodArgumentsProvider(): array @@ -396,12 +382,7 @@ $inputTypeData $set - - function ($data) { - function ($inputTypeData) { - function ($inputTypeData) { - fn ($inputTypeData) - + $data $dataTypes['Traversable']($data) @@ -483,8 +464,7 @@ $expectedType - - new stdClass() + testDataVsValid @@ -494,12 +474,7 @@ $set - - function () use ($dataRaw, $dataFiltered) { - function () use ($dataRaw, $dataFiltered) { - function () use ($dataRaw, $dataFiltered, $errorMessage) { - fn () - + $inputFilter @@ -516,81 +491,26 @@ $set[3]() - - method - method - method - method - willReturn - willReturn - willReturn - willReturn - willReturn - with - with - $dataSets - - $baseInputFilter - $baseInputFilter - - - expects - expects - expects - expects - method - method - method - - + allowEmpty allowEmpty allowEmpty allowEmpty continueIfEmpty - setMethods - setMethods - - 'invalid_value' - 'invalid_value' - - - count - count - getFilters - method - method - will - will - - - $provider - $provider - + getPluginManager getPluginManager - + breakOnFailure breakOnFailure - expects - expects - getErrorMessage - getErrorMessage - getFilterChain - getFilterChain - getName - getName - getValidatorChain - isRequired - setValue $chain @@ -600,9 +520,6 @@ - - setMethods - array<string, string> @@ -616,10 +533,6 @@ iterable - - - array - $input @@ -628,7 +541,7 @@ - + UploadedFileInterface @@ -642,40 +555,6 @@ $generator instanceof Generator - - - function () { - - - $filterChain - $filterChain - $validatorChain - $validatorChain - - - $filterChain - $input - $inputFilter - $validatorChain - - - get - getFilterChain - getInputFilterManager - getPluginManager - getPluginManager - getValidatorChain - has - plugin - plugin - - - getFactory - - - static function () { - - InputFilterAwareTrait::class @@ -693,33 +572,15 @@ getInstanceOf - - - - array<string, array{0: class-string<InputInterface>}> - - - - $this->getServiceNotFoundException() - $this->getServiceNotFoundException() - - - getPluginManager - getPluginManager - $dataSets - - $filter1->getValues()['nested']['nestedField1'] - $filter1->getValues()['nested']['nestedField1'] - $inputFilter @@ -766,37 +627,9 @@ isArray - - - $moduleManager - - - $config['input_filters']['abstract_factories'] - $config['service_manager']['aliases'] - $config['service_manager']['factories'] - - - $config['input_filters']['abstract_factories'] - $config['service_manager']['aliases'] - $config['service_manager']['factories'] - - CustomInput - - - FooAbstractFactory - - - canCreate - - - $container - $container - $name - - diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 393f3af4..3f82c7e3 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -4,12 +4,18 @@ namespace Laminas\InputFilter; +use Laminas\ServiceManager\ConfigInterface; + +/** @psalm-import-type ServiceManagerConfigurationType from ConfigInterface */ class ConfigProvider { /** * Return configuration for this component. * - * @return array + * @return array{ + * dependencies: ServiceManagerConfigurationType, + * input_filters: ServiceManagerConfigurationType, + * } */ public function __invoke() { @@ -22,7 +28,7 @@ public function __invoke() /** * Return dependency mappings for this component. * - * @return array + * @return ServiceManagerConfigurationType */ public function getDependencyConfig() { @@ -31,7 +37,7 @@ public function getDependencyConfig() 'InputFilterManager' => InputFilterPluginManager::class, // Legacy Zend Framework aliases - \Zend\InputFilter\InputFilterPluginManager::class => InputFilterPluginManager::class, + 'Zend\InputFilter\InputFilterPluginManager' => InputFilterPluginManager::class, ], 'factories' => [ InputFilterPluginManager::class => InputFilterPluginManagerFactory::class, @@ -42,7 +48,7 @@ public function getDependencyConfig() /** * Get input filter configuration * - * @return array + * @return ServiceManagerConfigurationType */ public function getInputFilterConfig() { diff --git a/src/InputFilterPluginManager.php b/src/InputFilterPluginManager.php index a94da4d3..ba1ef230 100644 --- a/src/InputFilterPluginManager.php +++ b/src/InputFilterPluginManager.php @@ -48,9 +48,9 @@ class InputFilterPluginManager extends AbstractPluginManager 'OptionalInputFilter' => OptionalInputFilter::class, // Legacy Zend Framework aliases - \Zend\InputFilter\InputFilter::class => InputFilter::class, - \Zend\InputFilter\CollectionInputFilter::class => CollectionInputFilter::class, - \Zend\InputFilter\OptionalInputFilter::class => OptionalInputFilter::class, + 'Zend\InputFilter\InputFilter' => InputFilter::class, + 'Zend\InputFilter\CollectionInputFilter' => CollectionInputFilter::class, + 'Zend\InputFilter\OptionalInputFilter' => OptionalInputFilter::class, // v2 normalized FQCNs 'zendinputfilterinputfilter' => InputFilter::class, diff --git a/src/Module.php b/src/Module.php index f79cc4fd..ec1d2a4d 100644 --- a/src/Module.php +++ b/src/Module.php @@ -5,13 +5,19 @@ namespace Laminas\InputFilter; use Laminas\ModuleManager\ModuleManager; +use Laminas\ServiceManager\ConfigInterface; +/** @psalm-import-type ServiceManagerConfigurationType from ConfigInterface */ class Module { /** * Return default laminas-inputfilter configuration for laminas-mvc applications. * - * @return array + * @return array + * @psalm-return array{ + * service_manager: ServiceManagerConfigurationType, + * input_filters: ServiceManagerConfigurationType, + * } */ public function getConfig() { diff --git a/test/ArrayInputTest.php b/test/ArrayInputTest.php index 2eccd3c3..0c7d78b5 100644 --- a/test/ArrayInputTest.php +++ b/test/ArrayInputTest.php @@ -30,7 +30,7 @@ protected function setUp(): void public function testDefaultGetValue(): void { - $this->assertCount(0, $this->input->getValue()); + self::assertCount(0, $this->input->getValue()); } public function testArrayInputMarkedRequiredWithoutAFallbackFailsValidationForEmptyArrays(): void @@ -39,7 +39,7 @@ public function testArrayInputMarkedRequiredWithoutAFallbackFailsValidationForEm $input->setRequired(true); $input->setValue([]); - $this->assertFalse($input->isValid()); + self::assertFalse($input->isValid()); $this->assertRequiredValidationErrorMessage($input); } @@ -52,12 +52,12 @@ public function testArrayInputMarkedRequiredWithoutAFallbackUsesProvidedErrorMes $input->setErrorMessage($expected); $input->setValue([]); - $this->assertFalse($input->isValid()); + self::assertFalse($input->isValid()); $messages = $input->getMessages(); - $this->assertCount(1, $messages); + self::assertCount(1, $messages); $message = array_pop($messages); - $this->assertEquals($expected, $message); + self::assertEquals($expected, $message); } public function testSetValueWithInvalidInputTypeThrowsInvalidArgumentException(): void diff --git a/test/BaseInputFilterTest.php b/test/BaseInputFilterTest.php index 3a019567..20f8acad 100644 --- a/test/BaseInputFilterTest.php +++ b/test/BaseInputFilterTest.php @@ -44,7 +44,7 @@ protected function setUp(): void public function testInputFilterIsEmptyByDefault(): void { $filter = $this->inputFilter; - $this->assertEquals(0, count($filter)); + self::assertCount(0, $filter); } public function testAddWithInvalidInputTypeThrowsInvalidArgumentException(): void @@ -56,7 +56,7 @@ public function testAddWithInvalidInputTypeThrowsInvalidArgumentException(): voi 'expects an instance of Laminas\InputFilter\InputInterface or Laminas\InputFilter\InputFilterInterface ' . 'as its first argument; received "stdClass"' ); - /** @noinspection PhpParamsInspection */ + /** @psalm-suppress InvalidArgument */ $inputFilter->add(new stdClass()); } @@ -116,7 +116,7 @@ public function testSetDataWithInvalidDataTypeThrowsInvalidArgumentException(): $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('expects an array or Traversable argument; received stdClass'); - /** @noinspection PhpParamsInspection */ + /** @psalm-suppress InvalidArgument */ $inputFilter->setData(new stdClass()); } @@ -142,7 +142,7 @@ public function testSetValidationGroupSkipsRecursionWhenInputIsNotAnInputFilter( $r = new ReflectionObject($inputFilter); $p = $r->getProperty('validationGroup'); $p->setAccessible(true); - $this->assertEquals(['fooInput'], $p->getValue($inputFilter)); + self::assertEquals(['fooInput'], $p->getValue($inputFilter)); } public function testSetValidationGroupAllowsSpecifyingArrayOfInputsToNestedInputFilter(): void @@ -166,8 +166,8 @@ public function testSetValidationGroupAllowsSpecifyingArrayOfInputsToNestedInput $r = new ReflectionObject($inputFilter); $p = $r->getProperty('validationGroup'); $p->setAccessible(true); - $this->assertEquals(['nested'], $p->getValue($inputFilter)); - $this->assertEquals(['nested-input1', 'nested-input2'], $p->getValue($nestedInputFilter)); + self::assertEquals(['nested'], $p->getValue($inputFilter)); + self::assertEquals(['nested-input1', 'nested-input2'], $p->getValue($nestedInputFilter)); } public function testSetValidationGroupThrowExceptionIfInputFilterNotExists(): void @@ -221,21 +221,21 @@ public function testAddHasGet( object $expectedInput ): void { $inputFilter = $this->inputFilter; - $this->assertFalse( + self::assertFalse( $inputFilter->has($expectedInputName), "InputFilter shouldn't have an input with the name $expectedInputName yet" ); $currentNumberOfFilters = count($inputFilter); $return = $inputFilter->add($input, $name); - $this->assertSame($inputFilter, $return, "add() must return it self"); + self::assertSame($inputFilter, $return, "add() must return it self"); // **Check input collection state** - $this->assertTrue($inputFilter->has($expectedInputName), "There is no input with name $expectedInputName"); - $this->assertCount($currentNumberOfFilters + 1, $inputFilter, 'Number of filters must be increased by 1'); + self::assertTrue($inputFilter->has($expectedInputName), "There is no input with name $expectedInputName"); + self::assertCount($currentNumberOfFilters + 1, $inputFilter, 'Number of filters must be increased by 1'); $returnInput = $inputFilter->get($expectedInputName); - $this->assertEquals($expectedInput, $returnInput, 'get() does not match the expected input'); + self::assertEquals($expectedInput, $returnInput, 'get() does not match the expected input'); } /** @@ -252,10 +252,10 @@ public function testAddRemove($input, ?string $name, ?string $expectedInputName) $currentNumberOfFilters = count($inputFilter); $return = $inputFilter->remove($expectedInputName); - $this->assertSame($inputFilter, $return, 'remove() must return it self'); + self::assertSame($inputFilter, $return, 'remove() must return it self'); - $this->assertFalse($inputFilter->has($expectedInputName), "There is no input with name $expectedInputName"); - $this->assertCount($currentNumberOfFilters - 1, $inputFilter, 'Number of filters must be decreased by 1'); + self::assertFalse($inputFilter->has($expectedInputName), "There is no input with name $expectedInputName"); + self::assertCount($currentNumberOfFilters - 1, $inputFilter, 'Number of filters must be decreased by 1'); } public function testAddingInputWithNameDoesNotInjectNameInInput(): void @@ -266,8 +266,8 @@ public function testAddingInputWithNameDoesNotInjectNameInInput(): void $inputFilter->add($foo, 'bas'); $test = $inputFilter->get('bas'); - $this->assertSame($foo, $test, 'get() does not match the input added'); - $this->assertEquals('foo', $foo->getName(), 'Input name should not change'); + self::assertSame($foo, $test, 'get() does not match the input added'); + self::assertEquals('foo', $foo->getName(), 'Input name should not change'); } /** @@ -284,11 +284,11 @@ public function testReplace($input, ?string $inputName, object $expectedInput): $currentNumberOfFilters = count($inputFilter); $return = $inputFilter->replace($input, $nameToReplace); - $this->assertSame($inputFilter, $return, 'replace() must return it self'); - $this->assertCount($currentNumberOfFilters, $inputFilter, "Number of filters shouldn't change"); + self::assertSame($inputFilter, $return, 'replace() must return it self'); + self::assertCount($currentNumberOfFilters, $inputFilter, "Number of filters shouldn't change"); $returnInput = $inputFilter->get($nameToReplace); - $this->assertEquals($expectedInput, $returnInput, 'get() does not match the expected input'); + self::assertEquals($expectedInput, $returnInput, 'get() does not match the expected input'); } /** @@ -309,21 +309,21 @@ public function testSetDataAndGetRawValueGetValue( $inputFilter->add($input, $inputName); } $return = $inputFilter->setData($data); - $this->assertSame($inputFilter, $return, 'setData() must return it self'); + self::assertSame($inputFilter, $return, 'setData() must return it self'); // ** Check filter state ** - $this->assertSame($expectedRawValues, $inputFilter->getRawValues(), 'getRawValues() value not match'); + self::assertSame($expectedRawValues, $inputFilter->getRawValues(), 'getRawValues() value not match'); foreach ($expectedRawValues as $inputName => $expectedRawValue) { - $this->assertSame( + self::assertSame( $expectedRawValue, $inputFilter->getRawValue($inputName), 'getRawValue() value not match for input ' . $inputName ); } - $this->assertSame($expectedValues, $inputFilter->getValues(), 'getValues() value not match'); + self::assertSame($expectedValues, $inputFilter->getValues(), 'getValues() value not match'); foreach ($expectedValues as $inputName => $expectedValue) { - $this->assertSame( + self::assertSame( $expectedValue, $inputFilter->getValue($inputName), 'getValue() value not match for input ' . $inputName @@ -332,15 +332,15 @@ public function testSetDataAndGetRawValueGetValue( // ** Check validation state ** // phpcs:disable Generic.Files.LineLength.TooLong - $this->assertEquals($expectedIsValid, $inputFilter->isValid(), 'isValid() value not match'); - $this->assertEquals($expectedInvalidInputs, $inputFilter->getInvalidInput(), 'getInvalidInput() value not match'); - $this->assertEquals($expectedValidInputs, $inputFilter->getValidInput(), 'getValidInput() value not match'); - $this->assertEquals($expectedMessages, $inputFilter->getMessages(), 'getMessages() value not match'); + self::assertEquals($expectedIsValid, $inputFilter->isValid(), 'isValid() value not match'); + self::assertEquals($expectedInvalidInputs, $inputFilter->getInvalidInput(), 'getInvalidInput() value not match'); + self::assertEquals($expectedValidInputs, $inputFilter->getValidInput(), 'getValidInput() value not match'); + self::assertEquals($expectedMessages, $inputFilter->getMessages(), 'getMessages() value not match'); // phpcs:enable Generic.Files.LineLength.TooLong // ** Check unknown fields ** - $this->assertFalse($inputFilter->hasUnknown(), 'hasUnknown() value not match'); - $this->assertEmpty($inputFilter->getUnknown(), 'getUnknown() value not match'); + self::assertFalse($inputFilter->hasUnknown(), 'hasUnknown() value not match'); + self::assertEmpty($inputFilter->getUnknown(), 'getUnknown() value not match'); } /** @@ -384,7 +384,7 @@ public function testResetEmptyValidationGroupRecursively(): void ->enableProxyingToOriginalMethods() ->setConstructorArgs(['flat']) ->getMock(); - $flatInput->expects($this->once()) + $flatInput->expects(self::once()) ->method('setValue') ->with('foo'); // Inputs without value must be reset for to have clean states when use different setData arguments @@ -393,7 +393,7 @@ public function testResetEmptyValidationGroupRecursively(): void ->enableProxyingToOriginalMethods() ->setConstructorArgs(['notSet']) ->getMock(); - $resetInput->expects($this->once()) + $resetInput->expects(self::once()) ->method('resetValue'); $filter = $this->inputFilter; @@ -407,7 +407,7 @@ public function testResetEmptyValidationGroupRecursively(): void $filter->setValidationGroup(['deep' => 'deep-input1']); // reset validation group $filter->setValidationGroup(InputFilterInterface::VALIDATE_ALL); - $this->assertEquals($expectedData, $filter->getValues()); + self::assertEquals($expectedData, $filter->getValues()); } /* @@ -450,7 +450,7 @@ public function testValidationContext($data, ?string $customContext, $expectedCo $filter->setData($data); - $this->assertTrue( + self::assertTrue( $filter->isValid($customContext), 'isValid() value not match. Detail: ' . json_encode($filter->getMessages(), JSON_THROW_ON_ERROR) ); @@ -467,7 +467,7 @@ public function testBuildValidationContextUsingInputGetRawValue(): void $filter->setData($data); - $this->assertTrue( + self::assertTrue( $filter->isValid(), 'isValid() value not match. Detail: ' . json_encode($filter->getMessages(), JSON_THROW_ON_ERROR) ); @@ -491,7 +491,7 @@ public function testContextIsTheSameWhenARequiredInputIsGivenAndOptionalInputIsM $filter->setData($data); - $this->assertTrue( + self::assertTrue( $filter->isValid(), 'isValid() value not match. Detail: ' . json_encode($filter->getMessages(), JSON_THROW_ON_ERROR) ); @@ -506,7 +506,7 @@ public function testValidationSkipsFieldsMarkedNotRequiredWhenNoDataPresent(): v $optionalInput = $this->createMock(InputInterface::class); $optionalInput->method('getName') ->willReturn($optionalInputName); - $optionalInput->expects($this->never()) + $optionalInput->expects(self::never()) ->method('isValid'); $data = []; @@ -514,16 +514,16 @@ public function testValidationSkipsFieldsMarkedNotRequiredWhenNoDataPresent(): v $filter->setData($data); - $this->assertTrue( + self::assertTrue( $filter->isValid(), 'isValid() value not match. Detail . ' . json_encode($filter->getMessages(), JSON_THROW_ON_ERROR) ); - $this->assertArrayNotHasKey( + self::assertArrayNotHasKey( $optionalInputName, $filter->getValidInput(), 'Missing optional fields must not appear as valid input neither invalid input' ); - $this->assertArrayNotHasKey( + self::assertArrayNotHasKey( $optionalInputName, $filter->getInvalidInput(), 'Missing optional fields must not appear as valid input neither invalid input' @@ -542,8 +542,8 @@ public function testUnknown(array $inputs, array $data, bool $hasUnknown, array $inputFilter->setData($data); - $this->assertEquals($getUnknown, $inputFilter->getUnknown(), 'getUnknown() value not match'); - $this->assertEquals($hasUnknown, $inputFilter->hasUnknown(), 'hasUnknown() value not match'); + self::assertEquals($getUnknown, $inputFilter->getUnknown(), 'getUnknown() value not match'); + self::assertEquals($hasUnknown, $inputFilter->hasUnknown(), 'hasUnknown() value not match'); } public function testGetInputs(): void @@ -558,9 +558,9 @@ public function testGetInputs(): void $filters = $filter->getInputs(); - $this->assertCount(2, $filters); - $this->assertEquals('foo', $filters['foo']->getName()); - $this->assertEquals('bar', $filters['bar']->getName()); + self::assertCount(2, $filters); + self::assertEquals('foo', $filters['foo']->getName()); + self::assertEquals('bar', $filters['bar']->getName()); } public function testAddingExistingInputWillMergeIntoExisting(): void @@ -575,7 +575,7 @@ public function testAddingExistingInputWillMergeIntoExisting(): void $foo2->setRequired(false); $filter->add($foo2); - $this->assertFalse($filter->get('foo')->isRequired()); + self::assertFalse($filter->get('foo')->isRequired()); } public function testMerge(): void @@ -590,7 +590,7 @@ public function testMerge(): void $inputFilter->merge($originInputFilter); - $this->assertEquals( + self::assertEquals( [ 'foo', 'bar', @@ -932,11 +932,11 @@ protected function createInputFilterInterfaceMock( $inputFilter->method('getValues') ->willReturn($getValues); if (($isValid === false) || ($isValid === true)) { - $inputFilter->expects($this->once()) + $inputFilter->expects(self::once()) ->method('isValid') ->willReturn($isValid); } else { - $inputFilter->expects($this->never()) + $inputFilter->expects(self::never()) ->method('isValid'); } $inputFilter->method('getMessages') @@ -979,12 +979,12 @@ protected function createInputInterfaceMock( $input->method('breakOnFailure') ->willReturn($breakOnFailure); if (($isValid === false) || ($isValid === true)) { - $input->expects($this->any()) + $input->expects(self::any()) ->method('isValid') ->with($context) ->willReturn($isValid); } else { - $input->expects($this->never()) + $input->expects(self::never()) ->method('isValid') ->with($context); } diff --git a/test/CollectionInputFilterTest.php b/test/CollectionInputFilterTest.php index 564709e7..8545a940 100644 --- a/test/CollectionInputFilterTest.php +++ b/test/CollectionInputFilterTest.php @@ -31,8 +31,7 @@ */ class CollectionInputFilterTest extends TestCase { - /** @var CollectionInputFilter */ - protected $inputFilter; + private CollectionInputFilter $inputFilter; protected function setUp(): void { @@ -47,7 +46,7 @@ public function testSetInputFilterWithInvalidTypeThrowsInvalidArgumentException( $this->expectExceptionMessage( 'expects an instance of Laminas\InputFilter\BaseInputFilter; received "stdClass"' ); - /** @noinspection PhpParamsInspection */ + /** @psalm-suppress InvalidArgument */ $inputFilter->setInputFilter(new stdClass()); } @@ -59,12 +58,12 @@ public function testSetInputFilter($inputFilter, string $expectedType): void { $this->inputFilter->setInputFilter($inputFilter); - $this->assertInstanceOf($expectedType, $this->inputFilter->getInputFilter(), 'getInputFilter() type not match'); + self::assertInstanceOf($expectedType, $this->inputFilter->getInputFilter(), 'getInputFilter() type not match'); } public function testGetDefaultInputFilter(): void { - $this->assertInstanceOf(BaseInputFilter::class, $this->inputFilter->getInputFilter()); + self::assertInstanceOf(BaseInputFilter::class, $this->inputFilter->getInputFilter()); } /** @@ -73,7 +72,7 @@ public function testGetDefaultInputFilter(): void public function testSetRequired(bool $value): void { $this->inputFilter->setIsRequired($value); - $this->assertEquals($value, $this->inputFilter->getIsRequired()); + self::assertEquals($value, $this->inputFilter->getIsRequired()); } /** @@ -88,7 +87,7 @@ public function testSetCount(?int $count, ?array $data, int $expectedCount): voi $this->inputFilter->setData($data); } - $this->assertEquals($expectedCount, $this->inputFilter->getCount(), 'getCount() value not match'); + self::assertEquals($expectedCount, $this->inputFilter->getCount(), 'getCount() value not match'); } public function testGetCountReturnsRightCountOnConsecutiveCallsWithDifferentData(): void @@ -103,9 +102,9 @@ public function testGetCountReturnsRightCountOnConsecutiveCallsWithDifferentData ]; $this->inputFilter->setData($collectionData1); - $this->assertEquals(2, $this->inputFilter->getCount()); + self::assertEquals(2, $this->inputFilter->getCount()); $this->inputFilter->setData($collectionData2); - $this->assertEquals(1, $this->inputFilter->getCount()); + self::assertEquals(1, $this->inputFilter->getCount()); } /** @@ -128,14 +127,14 @@ public function testDataVsValid( } $this->inputFilter->setIsRequired($required); - $this->assertEquals( + self::assertEquals( $expectedValid, $this->inputFilter->isValid(), 'isValid() value not match. Detail . ' . json_encode($this->inputFilter->getMessages(), JSON_THROW_ON_ERROR) ); - $this->assertEquals($expectedRaw, $this->inputFilter->getRawValues(), 'getRawValues() value not match'); - $this->assertEquals($expectedValues, $this->inputFilter->getValues(), 'getValues() value not match'); - $this->assertEquals($expectedMessages, $this->inputFilter->getMessages(), 'getMessages() value not match'); + self::assertEquals($expectedRaw, $this->inputFilter->getRawValues(), 'getRawValues() value not match'); + self::assertEquals($expectedValues, $this->inputFilter->getValues(), 'getValues() value not match'); + self::assertEquals($expectedMessages, $this->inputFilter->getMessages(), 'getMessages() value not match'); } /** @@ -212,7 +211,7 @@ public function testSetValidationGroupUsingFormStyle(): void $colRaw = [$dataRaw]; $colFiltered = [$dataFiltered]; $baseInputFilter = $this->createBaseInputFilterMock(true, $dataRaw, $dataFiltered); - $baseInputFilter->expects($this->once()) + $baseInputFilter->expects(self::once()) ->method('setValidationGroup') ->with($validationGroup); @@ -220,13 +219,13 @@ public function testSetValidationGroupUsingFormStyle(): void $this->inputFilter->setData($colRaw); $this->inputFilter->setValidationGroup($colValidationGroup); - $this->assertTrue( + self::assertTrue( $this->inputFilter->isValid(), 'isValid() value not match. Detail . ' . json_encode($this->inputFilter->getMessages(), JSON_THROW_ON_ERROR) ); - $this->assertEquals($colRaw, $this->inputFilter->getRawValues(), 'getRawValues() value not match'); - $this->assertEquals($colFiltered, $this->inputFilter->getValues(), 'getValues() value not match'); - $this->assertEquals([], $this->inputFilter->getMessages(), 'getMessages() value not match'); + self::assertEquals($colRaw, $this->inputFilter->getRawValues(), 'getRawValues() value not match'); + self::assertEquals($colFiltered, $this->inputFilter->getValues(), 'getValues() value not match'); + self::assertEquals([], $this->inputFilter->getMessages(), 'getMessages() value not match'); } /** @psalm-return array */ @@ -304,7 +303,7 @@ public function testNestingCollectionCountCached(?int $count, bool $expectedIsVa ]; $mainInputFilter->setData($data); - $this->assertSame($expectedIsValid, $mainInputFilter->isValid()); + self::assertSame($expectedIsValid, $mainInputFilter->isValid()); } /** @@ -377,7 +376,7 @@ public function isRequiredProvider(): array * @param mixed[] $getRawValues * @param mixed[] $getValues * @param string[] $getMessages - * @return MockObject|BaseInputFilter + * @return MockObject&BaseInputFilter */ protected function createBaseInputFilterMock( $isValid = null, @@ -385,18 +384,18 @@ protected function createBaseInputFilterMock( $getValues = [], $getMessages = [] ) { - /** @var BaseInputFilter|MockObject $inputFilter */ + /** @var BaseInputFilter&MockObject $inputFilter */ $inputFilter = $this->createMock(BaseInputFilter::class); $inputFilter->method('getRawValues') ->willReturn($getRawValues); $inputFilter->method('getValues') ->willReturn($getValues); if (($isValid === false) || ($isValid === true)) { - $inputFilter->expects($this->once()) + $inputFilter->expects(self::once()) ->method('isValid') ->willReturn($isValid); } else { - $inputFilter->expects($this->never()) + $inputFilter->expects(self::never()) ->method('isValid'); } $inputFilter->method('getMessages') @@ -429,8 +428,8 @@ public function testGetUnknownWhenAllFieldsAreKnownReturnsAnEmptyArray(): void $unknown = $collectionInputFilter->getUnknown(); - $this->assertFalse($collectionInputFilter->hasUnknown()); - $this->assertCount(0, $unknown); + self::assertFalse($collectionInputFilter->hasUnknown()); + self::assertCount(0, $unknown); } public function testGetUnknownFieldIsUnknown(): void @@ -450,8 +449,8 @@ public function testGetUnknownFieldIsUnknown(): void $unknown = $collectionInputFilter->getUnknown(); - $this->assertTrue($collectionInputFilter->hasUnknown()); - $this->assertEquals([['baz' => 'hey'], ['tor' => 'ver']], $unknown); + self::assertTrue($collectionInputFilter->hasUnknown()); + self::assertEquals([['baz' => 'hey'], ['tor' => 'ver']], $unknown); } /** @psalm-return array */ @@ -561,17 +560,17 @@ public function testCollectionValidationDoesNotReuseMessagesBetweenInputs(): voi $messages = $collectionInputFilter->getMessages(); // @codingStandardsIgnoreStart - $this->assertFalse($isValid); - $this->assertCount(2, $messages); + self::assertFalse($isValid); + self::assertCount(2, $messages); - $this->assertArrayHasKey('phone', $messages[0]); - $this->assertCount(1, $messages[0]['phone']); - $this->assertContains('Value is required and can\'t be empty', $messages[0]['phone']); + self::assertArrayHasKey('phone', $messages[0]); + self::assertCount(1, $messages[0]['phone']); + self::assertContains('Value is required and can\'t be empty', $messages[0]['phone']); - $this->assertArrayHasKey('phone', $messages[1]); - $this->assertCount(1, $messages[1]['phone']); - $this->assertNotContains('Value is required and can\'t be empty', $messages[1]['phone']); - $this->assertContains('The input must contain only digits', $messages[1]['phone']); + self::assertArrayHasKey('phone', $messages[1]); + self::assertCount(1, $messages[1]['phone']); + self::assertNotContains('Value is required and can\'t be empty', $messages[1]['phone']); + self::assertContains('The input must contain only digits', $messages[1]['phone']); // @codingStandardsIgnoreEnd } @@ -611,17 +610,17 @@ public function testCollectionValidationUsesCustomInputErrorMessages(): void $isValid = $collectionInputFilter->isValid(); $messages = $collectionInputFilter->getMessages(); - $this->assertFalse($isValid); - $this->assertCount(2, $messages); + self::assertFalse($isValid); + self::assertCount(2, $messages); - $this->assertArrayHasKey('phone', $messages[0]); - $this->assertCount(1, $messages[0]['phone']); - $this->assertContains('CUSTOM ERROR MESSAGE', $messages[0]['phone']); - $this->assertNotContains('Value is required and can\'t be empty', $messages[0]['phone']); + self::assertArrayHasKey('phone', $messages[0]); + self::assertCount(1, $messages[0]['phone']); + self::assertContains('CUSTOM ERROR MESSAGE', $messages[0]['phone']); + self::assertNotContains('Value is required and can\'t be empty', $messages[0]['phone']); - $this->assertArrayHasKey('phone', $messages[1]); - $this->assertCount(1, $messages[1]['phone']); - $this->assertContains('CUSTOM ERROR MESSAGE', $messages[1]['phone']); + self::assertArrayHasKey('phone', $messages[1]); + self::assertCount(1, $messages[1]['phone']); + self::assertContains('CUSTOM ERROR MESSAGE', $messages[1]['phone']); } public function testDuplicatedErrorMessages(): void @@ -703,8 +702,8 @@ public function testDuplicatedErrorMessages(): void ], ] ); - $this->assertFalse($inputFilter->isValid()); - $this->assertEquals([ + self::assertFalse($inputFilter->isValid()); + self::assertEquals([ 'element' => [ 'type1' => [ [ @@ -754,14 +753,14 @@ public function testDuplicatedErrorMessages(): void public function testLazyLoadsANotEmptyValidatorWhenNoneProvided(): void { - $this->assertInstanceOf(NotEmpty::class, $this->inputFilter->getNotEmptyValidator()); + self::assertInstanceOf(NotEmpty::class, $this->inputFilter->getNotEmptyValidator()); } public function testAllowsComposingANotEmptyValidator(): void { $notEmptyValidator = new NotEmpty(); $this->inputFilter->setNotEmptyValidator($notEmptyValidator); - $this->assertSame($notEmptyValidator, $this->inputFilter->getNotEmptyValidator()); + self::assertSame($notEmptyValidator, $this->inputFilter->getNotEmptyValidator()); } public function testUsesMessageFromComposedNotEmptyValidatorWhenRequiredButCollectionIsEmpty(): void @@ -775,9 +774,9 @@ public function testUsesMessageFromComposedNotEmptyValidatorWhenRequiredButColle $this->inputFilter->setData([]); - $this->assertFalse($this->inputFilter->isValid()); + self::assertFalse($this->inputFilter->isValid()); - $this->assertEquals([ + self::assertEquals([ [NotEmpty::IS_EMPTY => $message], ], $this->inputFilter->getMessages()); } @@ -800,7 +799,6 @@ public function testSetDataUsingSetDataAndRunningIsValidReturningSameAsOriginalF ], ]; - /** @var BaseInputFilter $baseInputFilter */ $baseInputFilter = (new BaseInputFilter()) ->add(new Input(), 'bar'); @@ -833,9 +831,8 @@ public function contextProvider(): iterable */ public function testValidationContext(array $data, ?array $customContext, ?array $expectedContext): void { - /** @var MockObject|BaseInputFilter $baseInputFilter */ $baseInputFilter = $this->createMock(BaseInputFilter::class); - $baseInputFilter->expects($this->exactly(count($data))) + $baseInputFilter->expects(self::exactly(count($data))) ->method('isValid') ->with($expectedContext) ->willReturn(true); @@ -843,7 +840,7 @@ public function testValidationContext(array $data, ?array $customContext, ?array $collectionInputFilter = (new CollectionInputFilter())->setInputFilter($baseInputFilter); $collectionInputFilter->setData($data); - $this->assertTrue( + self::assertTrue( $collectionInputFilter->isValid($customContext), 'isValid() value not match. Detail: ' . json_encode( $collectionInputFilter->getMessages(), diff --git a/test/ConfigProviderTest.php b/test/ConfigProviderTest.php index 333c2fcc..5bda132f 100644 --- a/test/ConfigProviderTest.php +++ b/test/ConfigProviderTest.php @@ -18,15 +18,15 @@ public function testProvidesExpectedConfiguration(): void $expected = [ 'aliases' => [ - 'InputFilterManager' => InputFilterPluginManager::class, - \Zend\InputFilter\InputFilterPluginManager::class => InputFilterPluginManager::class, + 'InputFilterManager' => InputFilterPluginManager::class, + 'Zend\InputFilter\InputFilterPluginManager' => InputFilterPluginManager::class, ], 'factories' => [ InputFilterPluginManager::class => InputFilterPluginManagerFactory::class, ], ]; - $this->assertEquals($expected, $provider->getDependencyConfig()); + self::assertEquals($expected, $provider->getDependencyConfig()); } public function testProvidesExpectedInputFilterConfiguration(): void @@ -39,7 +39,7 @@ public function testProvidesExpectedInputFilterConfiguration(): void ], ]; - $this->assertEquals($expected, $provider->getInputFilterConfig()); + self::assertEquals($expected, $provider->getInputFilterConfig()); } public function testInvocationProvidesDependencyConfiguration(): void @@ -50,6 +50,6 @@ public function testInvocationProvidesDependencyConfiguration(): void 'dependencies' => $provider->getDependencyConfig(), 'input_filters' => $provider->getInputFilterConfig(), ]; - $this->assertEquals($expected, $provider()); + self::assertEquals($expected, $provider()); } } diff --git a/test/FactoryTest.php b/test/FactoryTest.php index 5012d7c3..5b0b8727 100644 --- a/test/FactoryTest.php +++ b/test/FactoryTest.php @@ -23,7 +23,6 @@ use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; -use function count; use function sprintf; /** @@ -37,7 +36,7 @@ public function testCreateInputWithInvalidDataTypeThrowsInvalidArgumentException $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('expects an array or Traversable; received "string"'); - /** @noinspection PhpParamsInspection */ + /** @psalm-suppress InvalidArgument */ $factory->createInput('invalid_value'); } @@ -45,7 +44,7 @@ public function testCreateInputWithTypeAsAnUnknownPluginAndNotExistsAsClassNameT { $type = 'foo'; $pluginManager = $this->createMock(InputFilterPluginManager::class); - $pluginManager->expects($this->atLeastOnce()) + $pluginManager->expects(self::atLeastOnce()) ->method('has') ->with($type) ->willReturn(false); @@ -68,7 +67,7 @@ public function testGetInputFilterManagerSettedByItsSetter(): void $factory = new Factory(); /** @psalm-suppress MixedArgumentTypeCoercion */ $factory->setInputFilterManager($pluginManager); - $this->assertSame($pluginManager, $factory->getInputFilterManager()); + self::assertSame($pluginManager, $factory->getInputFilterManager()); } public function testGetInputFilterManagerWhenYouConstructFactoryWithIt(): void @@ -76,7 +75,7 @@ public function testGetInputFilterManagerWhenYouConstructFactoryWithIt(): void $pluginManager = $this->createMock(InputFilterPluginManager::class); /** @psalm-suppress MixedArgumentTypeCoercion */ $factory = new Factory($pluginManager); - $this->assertSame($pluginManager, $factory->getInputFilterManager()); + self::assertSame($pluginManager, $factory->getInputFilterManager()); } public function testCreateInputWithTypeAsAnInvalidPluginInstanceThrowException(): void @@ -245,20 +244,20 @@ public function testCreateInputFilterWithInvalidDataTypeThrowsInvalidArgumentExc $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('expects an array or Traversable; received "string"'); - /** @noinspection PhpParamsInspection */ + /** @psalm-suppress InvalidArgument */ $factory->createInputFilter('invalid_value'); } public function testFactoryComposesFilterChainByDefault(): void { $factory = $this->createDefaultFactory(); - $this->assertInstanceOf(Filter\FilterChain::class, $factory->getDefaultFilterChain()); + self::assertInstanceOf(Filter\FilterChain::class, $factory->getDefaultFilterChain()); } public function testFactoryComposesValidatorChainByDefault(): void { $factory = $this->createDefaultFactory(); - $this->assertInstanceOf(Validator\ValidatorChain::class, $factory->getDefaultValidatorChain()); + self::assertInstanceOf(Validator\ValidatorChain::class, $factory->getDefaultValidatorChain()); } public function testFactoryAllowsInjectingFilterChain(): void @@ -266,7 +265,7 @@ public function testFactoryAllowsInjectingFilterChain(): void $factory = $this->createDefaultFactory(); $filterChain = new Filter\FilterChain(); $factory->setDefaultFilterChain($filterChain); - $this->assertSame($filterChain, $factory->getDefaultFilterChain()); + self::assertSame($filterChain, $factory->getDefaultFilterChain()); } public function testFactoryAllowsInjectingValidatorChain(): void @@ -274,7 +273,7 @@ public function testFactoryAllowsInjectingValidatorChain(): void $factory = $this->createDefaultFactory(); $validatorChain = new Validator\ValidatorChain(); $factory->setDefaultValidatorChain($validatorChain); - $this->assertSame($validatorChain, $factory->getDefaultValidatorChain()); + self::assertSame($validatorChain, $factory->getDefaultValidatorChain()); } public function testFactoryUsesComposedFilterChainWhenCreatingNewInputObjects(): void @@ -289,10 +288,10 @@ public function testFactoryUsesComposedFilterChainWhenCreatingNewInputObjects(): $input = $factory->createInput([ 'name' => 'foo', ]); - $this->assertInstanceOf(InputInterface::class, $input); + self::assertInstanceOf(InputInterface::class, $input); $inputFilterChain = $input->getFilterChain(); - $this->assertNotSame($filterChain, $inputFilterChain); - $this->assertSame($pluginManager, $inputFilterChain->getPluginManager()); + self::assertNotSame($filterChain, $inputFilterChain); + self::assertSame($pluginManager, $inputFilterChain->getPluginManager()); } public function testFactoryUsesComposedValidatorChainWhenCreatingNewInputObjects(): void @@ -306,10 +305,10 @@ public function testFactoryUsesComposedValidatorChainWhenCreatingNewInputObjects $input = $factory->createInput([ 'name' => 'foo', ]); - $this->assertInstanceOf(InputInterface::class, $input); + self::assertInstanceOf(InputInterface::class, $input); $inputValidatorChain = $input->getValidatorChain(); - $this->assertNotSame($validatorChain, $inputValidatorChain); - $this->assertSame($validatorPlugins, $inputValidatorChain->getPluginManager()); + self::assertNotSame($validatorChain, $inputValidatorChain); + self::assertSame($validatorPlugins, $inputValidatorChain->getPluginManager()); } public function testFactoryInjectsComposedFilterAndValidatorChainsIntoInputObjectsWhenCreatingNewInputFilterObjects(): void // phpcs:ignore @@ -330,14 +329,14 @@ public function testFactoryInjectsComposedFilterAndValidatorChainsIntoInputObjec 'name' => 'foo', ], ]); - $this->assertInstanceOf(InputFilterInterface::class, $inputFilter); - $this->assertEquals(1, count($inputFilter)); + self::assertInstanceOf(InputFilterInterface::class, $inputFilter); + self::assertCount(1, $inputFilter); $input = $inputFilter->get('foo'); - $this->assertInstanceOf(InputInterface::class, $input); + self::assertInstanceOf(InputInterface::class, $input); $inputFilterChain = $input->getFilterChain(); $inputValidatorChain = $input->getValidatorChain(); - $this->assertSame($filterPlugins, $inputFilterChain->getPluginManager()); - $this->assertSame($validatorPlugins, $inputValidatorChain->getPluginManager()); + self::assertSame($filterPlugins, $inputFilterChain->getPluginManager()); + self::assertSame($validatorPlugins, $inputValidatorChain->getPluginManager()); } public function testFactoryWillCreateInputWithSuggestedFilters(): void @@ -359,24 +358,24 @@ public function testFactoryWillCreateInputWithSuggestedFilters(): void ], ], ]); - $this->assertInstanceOf(InputInterface::class, $input); - $this->assertEquals('foo', $input->getName()); + self::assertInstanceOf(InputInterface::class, $input); + self::assertEquals('foo', $input->getName()); $chain = $input->getFilterChain(); $index = 0; foreach ($chain as $filter) { switch ($index) { case 0: - $this->assertInstanceOf(Filter\StringTrim::class, $filter); + self::assertInstanceOf(Filter\StringTrim::class, $filter); break; case 1: - $this->assertSame($htmlEntities, $filter); + self::assertSame($htmlEntities, $filter); break; case 2: - $this->assertInstanceOf(Filter\StringToLower::class, $filter); - $this->assertEquals('ISO-8859-1', $filter->getEncoding()); + self::assertInstanceOf(Filter\StringToLower::class, $filter); + self::assertEquals('ISO-8859-1', $filter->getEncoding()); break; default: - $this->fail('Found more filters than expected'); + self::fail('Found more filters than expected'); } $index++; } @@ -402,31 +401,31 @@ public function testFactoryWillCreateInputWithSuggestedValidators(): void ], ], ]); - $this->assertInstanceOf(InputInterface::class, $input); - $this->assertEquals('foo', $input->getName()); + self::assertInstanceOf(InputInterface::class, $input); + self::assertEquals('foo', $input->getName()); $chain = $input->getValidatorChain(); $index = 0; foreach ($chain->getValidators() as $validator) { $validator = $validator['instance']; switch ($index) { case 0: - $this->assertInstanceOf(Validator\NotEmpty::class, $validator); + self::assertInstanceOf(Validator\NotEmpty::class, $validator); break; case 1: - $this->assertSame($digits, $validator); + self::assertSame($digits, $validator); break; case 2: - $this->assertInstanceOf(Validator\StringLength::class, $validator); - $this->assertEquals(3, $validator->getMin()); - $this->assertEquals(5, $validator->getMax()); + self::assertInstanceOf(Validator\StringLength::class, $validator); + self::assertEquals(3, $validator->getMin()); + self::assertEquals(5, $validator->getMax()); break; default: - $this->fail('Found more validators than expected'); + self::fail('Found more validators than expected'); } $index++; } // Assure that previous foreach has been run - $this->assertEquals(3, $index); + self::assertEquals(3, $index); } public function testFactoryWillCreateInputWithSuggestedRequiredFlagAndAlternativeAllowEmptyFlag(): void @@ -437,9 +436,9 @@ public function testFactoryWillCreateInputWithSuggestedRequiredFlagAndAlternativ 'required' => false, 'allow_empty' => false, ]); - $this->assertInstanceOf(InputInterface::class, $input); - $this->assertFalse($input->isRequired()); - $this->assertFalse($input->allowEmpty()); + self::assertInstanceOf(InputInterface::class, $input); + self::assertFalse($input->isRequired()); + self::assertFalse($input->allowEmpty()); } public function testFactoryWillCreateInputWithSuggestedAllowEmptyFlagAndImpliesRequiredFlag(): void @@ -449,9 +448,9 @@ public function testFactoryWillCreateInputWithSuggestedAllowEmptyFlagAndImpliesR 'name' => 'foo', 'allow_empty' => true, ]); - $this->assertInstanceOf(InputInterface::class, $input); - $this->assertTrue($input->allowEmpty()); - $this->assertFalse($input->isRequired()); + self::assertInstanceOf(InputInterface::class, $input); + self::assertTrue($input->allowEmpty()); + self::assertFalse($input->isRequired()); } public function testFactoryWillCreateInputWithSuggestedName(): void @@ -460,8 +459,8 @@ public function testFactoryWillCreateInputWithSuggestedName(): void $input = $factory->createInput([ 'name' => 'foo', ]); - $this->assertInstanceOf(InputInterface::class, $input); - $this->assertEquals('foo', $input->getName()); + self::assertInstanceOf(InputInterface::class, $input); + self::assertEquals('foo', $input->getName()); } public function testFactoryWillCreateInputWithContinueIfEmptyFlag(): void @@ -471,8 +470,8 @@ public function testFactoryWillCreateInputWithContinueIfEmptyFlag(): void 'name' => 'foo', 'continue_if_empty' => true, ]); - $this->assertInstanceOf(InputInterface::class, $input); - $this->assertTrue($input->continueIfEmpty()); + self::assertInstanceOf(InputInterface::class, $input); + self::assertTrue($input->continueIfEmpty()); } public function testFactoryAcceptsInputInterface(): void @@ -484,9 +483,9 @@ public function testFactoryAcceptsInputInterface(): void 'foo' => $input, ]); - $this->assertInstanceOf(InputFilterInterface::class, $inputFilter); - $this->assertTrue($inputFilter->has('foo')); - $this->assertEquals($input, $inputFilter->get('foo')); + self::assertInstanceOf(InputFilterInterface::class, $inputFilter); + self::assertTrue($inputFilter->has('foo')); + self::assertEquals($input, $inputFilter->get('foo')); } public function testFactoryAcceptsInputFilterInterface(): void @@ -498,9 +497,9 @@ public function testFactoryAcceptsInputFilterInterface(): void 'foo' => $input, ]); - $this->assertInstanceOf(InputFilterInterface::class, $inputFilter); - $this->assertTrue($inputFilter->has('foo')); - $this->assertEquals($input, $inputFilter->get('foo')); + self::assertInstanceOf(InputFilterInterface::class, $inputFilter); + self::assertTrue($inputFilter->has('foo')); + self::assertEquals($input, $inputFilter->get('foo')); } public function testFactoryWillCreateInputFilterAndAllInputObjectsFromGivenConfiguration(): void @@ -579,42 +578,42 @@ public function testFactoryWillCreateInputFilterAndAllInputObjectsFromGivenConfi 'continue_if_empty' => true, ], ]); - $this->assertInstanceOf(InputFilter::class, $inputFilter); - $this->assertEquals(5, count($inputFilter)); + self::assertInstanceOf(InputFilter::class, $inputFilter); + self::assertCount(5, $inputFilter); foreach (['foo', 'bar', 'baz', 'bat', 'zomg'] as $name) { $input = $inputFilter->get($name); switch ($name) { case 'foo': - $this->assertInstanceOf(Input::class, $input); - $this->assertFalse($input->isRequired()); - $this->assertEquals(2, count($input->getValidatorChain())); + self::assertInstanceOf(Input::class, $input); + self::assertFalse($input->isRequired()); + self::assertCount(2, $input->getValidatorChain()); break; case 'bar': - $this->assertInstanceOf(Input::class, $input); - $this->assertTrue($input->allowEmpty()); - $this->assertEquals(2, count($input->getFilterChain())); + self::assertInstanceOf(Input::class, $input); + self::assertTrue($input->allowEmpty()); + self::assertCount(2, $input->getFilterChain()); break; case 'baz': - $this->assertInstanceOf(InputFilter::class, $input); - $this->assertEquals(2, count($input)); + self::assertInstanceOf(InputFilter::class, $input); + self::assertCount(2, $input); $foo = $input->get('foo'); - $this->assertInstanceOf(Input::class, $foo); - $this->assertFalse($foo->isRequired()); - $this->assertEquals(2, count($foo->getValidatorChain())); + self::assertInstanceOf(Input::class, $foo); + self::assertFalse($foo->isRequired()); + self::assertCount(2, $foo->getValidatorChain()); $bar = $input->get('bar'); - $this->assertInstanceOf(Input::class, $bar); - $this->assertTrue($bar->allowEmpty()); - $this->assertEquals(2, count($bar->getFilterChain())); + self::assertInstanceOf(Input::class, $bar); + self::assertTrue($bar->allowEmpty()); + self::assertCount(2, $bar->getFilterChain()); break; case 'bat': - $this->assertInstanceOf(CustomInput::class, $input); - $this->assertEquals('bat', $input->getName()); + self::assertInstanceOf(CustomInput::class, $input); + self::assertEquals('bat', $input->getName()); break; case 'zomg': - $this->assertInstanceOf(Input::class, $input); - $this->assertTrue($input->continueIfEmpty()); + self::assertInstanceOf(Input::class, $input); + self::assertTrue($input->continueIfEmpty()); } } } @@ -626,8 +625,8 @@ public function testFactoryWillCreateInputFilterMatchingInputNameWhenNotSpecifie ['name' => 'foo'], ]); - $this->assertTrue($inputFilter->has('foo')); - $this->assertInstanceOf(Input::class, $inputFilter->get('foo')); + self::assertTrue($inputFilter->has('foo')); + self::assertInstanceOf(Input::class, $inputFilter->get('foo')); } public function testFactoryAllowsPassingValidatorChainsInInputSpec(): void @@ -638,9 +637,9 @@ public function testFactoryAllowsPassingValidatorChainsInInputSpec(): void 'name' => 'foo', 'validators' => $chain, ]); - $this->assertInstanceOf(InputInterface::class, $input); + self::assertInstanceOf(InputInterface::class, $input); $test = $input->getValidatorChain(); - $this->assertSame($chain, $test); + self::assertSame($chain, $test); } public function testFactoryAllowsPassingFilterChainsInInputSpec(): void @@ -651,9 +650,9 @@ public function testFactoryAllowsPassingFilterChainsInInputSpec(): void 'name' => 'foo', 'filters' => $chain, ]); - $this->assertInstanceOf(InputInterface::class, $input); + self::assertInstanceOf(InputInterface::class, $input); $test = $input->getFilterChain(); - $this->assertSame($chain, $test); + self::assertSame($chain, $test); } public function testFactoryAcceptsCollectionInputFilter(): void @@ -668,10 +667,10 @@ public function testFactoryAcceptsCollectionInputFilter(): void 'count' => 3, ]); - $this->assertInstanceOf(CollectionInputFilter::class, $inputFilter); - $this->assertInstanceOf(InputFilter::class, $inputFilter->getInputFilter()); - $this->assertTrue($inputFilter->getIsRequired()); - $this->assertEquals(3, $inputFilter->getCount()); + self::assertInstanceOf(CollectionInputFilter::class, $inputFilter); + self::assertInstanceOf(InputFilter::class, $inputFilter->getInputFilter()); + self::assertTrue($inputFilter->getIsRequired()); + self::assertEquals(3, $inputFilter->getCount()); } public function testFactoryWillCreateInputWithErrorMessage(): void @@ -681,7 +680,8 @@ public function testFactoryWillCreateInputWithErrorMessage(): void 'name' => 'foo', 'error_message' => 'My custom error message', ]); - $this->assertEquals('My custom error message', $input->getErrorMessage()); + self::assertInstanceOf(InputInterface::class, $input); + self::assertEquals('My custom error message', $input->getErrorMessage()); } public function testFactoryWillNotGetPrioritySetting(): void @@ -704,9 +704,10 @@ public function testFactoryWillNotGetPrioritySetting(): void ], ], ]); + self::assertInstanceOf(InputInterface::class, $input); // We should have 3 filters - $this->assertEquals(3, $input->getFilterChain()->count()); + self::assertEquals(3, $input->getFilterChain()->count()); // Filters should pop in the following order: // string_to_upper (1001), string_to_lower (1000), string_trim (999) @@ -714,19 +715,19 @@ public function testFactoryWillNotGetPrioritySetting(): void foreach ($input->getFilterChain()->getFilters() as $filter) { switch ($index) { case 0: - $this->assertInstanceOf(Filter\StringToUpper::class, $filter); + self::assertInstanceOf(Filter\StringToUpper::class, $filter); break; case 1: - $this->assertInstanceOf(Filter\StringToLower::class, $filter); + self::assertInstanceOf(Filter\StringToLower::class, $filter); break; case 2: - $this->assertInstanceOf(Filter\StringTrim::class, $filter); + self::assertInstanceOf(Filter\StringTrim::class, $filter); break; } $index++; } - $this->assertSame(3, $index); + self::assertSame(3, $index); } public function testFactoryValidatorsPriority(): void @@ -742,8 +743,8 @@ public function testFactoryValidatorsPriority(): void 'name' => 'Callback', 'priority' => Validator\ValidatorChain::DEFAULT_PRIORITY - 1, // 0 'options' => [ - 'callback' => static function () use (&$order) { - static::assertSame(2, $order); + 'callback' => static function () use (&$order): bool { + self::assertSame(2, $order); ++$order; return true; @@ -755,7 +756,7 @@ public function testFactoryValidatorsPriority(): void 'priority' => Validator\ValidatorChain::DEFAULT_PRIORITY + 1, // 2 'options' => [ 'callback' => static function () use (&$order) { - static::assertSame(0, $order); + self::assertSame(0, $order); ++$order; return true; @@ -765,8 +766,8 @@ public function testFactoryValidatorsPriority(): void [ 'name' => 'Callback', // default priority 1 'options' => [ - 'callback' => static function () use (&$order) { - static::assertSame(1, $order); + 'callback' => static function () use (&$order): bool { + self::assertSame(1, $order); ++$order; return true; @@ -775,9 +776,10 @@ public function testFactoryValidatorsPriority(): void ], ], ]); + self::assertInstanceOf(InputInterface::class, $input); // We should have 3 validators - $this->assertEquals(3, $input->getValidatorChain()->count()); + self::assertEquals(3, $input->getValidatorChain()->count()); $input->setValue(['foo' => false]); self::assertTrue($input->isValid()); @@ -795,8 +797,8 @@ public function testConflictNameWithInputFilterType(): void ] ); - $this->assertInstanceOf(InputFilter::class, $inputFilter); - $this->assertTrue($inputFilter->has('type')); + self::assertInstanceOf(InputFilter::class, $inputFilter); + self::assertTrue($inputFilter->has('type')); } public function testCustomFactoryInCollection(): void @@ -807,7 +809,7 @@ public function testCustomFactoryInCollection(): void 'type' => 'collection', 'input_filter' => new InputFilter(), ]); - $this->assertInstanceOf(TestAsset\CustomFactory::class, $inputFilter->getFactory()); + self::assertInstanceOf(TestAsset\CustomFactory::class, $inputFilter->getFactory()); } public function testCanSetInputErrorMessage(): void @@ -818,7 +820,8 @@ public function testCanSetInputErrorMessage(): void 'type' => Input::class, 'error_message' => 'Custom error message', ]); - $this->assertEquals('Custom error message', $input->getErrorMessage()); + self::assertInstanceOf(InputInterface::class, $input); + self::assertEquals('Custom error message', $input->getErrorMessage()); } public function testSetInputFilterManagerWithServiceManager(): void @@ -840,7 +843,7 @@ public function testSetInputFilterManagerWithoutServiceManager(): void $smMock = $this->createMock(ContainerInterface::class); $inputFilterManager = new InputFilterPluginManager($smMock); $factory = new Factory($inputFilterManager); - $this->assertSame($inputFilterManager, $factory->getInputFilterManager()); + self::assertSame($inputFilterManager, $factory->getInputFilterManager()); } public function testSetInputFilterManagerOnConstruct(): void @@ -848,7 +851,7 @@ public function testSetInputFilterManagerOnConstruct(): void $smMock = $this->createMock(ContainerInterface::class); $inputFilterManager = new InputFilterPluginManager($smMock); $factory = new Factory($inputFilterManager); - $this->assertSame($inputFilterManager, $factory->getInputFilterManager()); + self::assertSame($inputFilterManager, $factory->getInputFilterManager()); } /** @@ -858,9 +861,9 @@ public function testSetsBreakChainOnFailure(): void { $factory = $this->createDefaultFactory(); - $this->assertTrue($factory->createInput(['break_on_failure' => true])->breakOnFailure()); + self::assertTrue($factory->createInput(['break_on_failure' => true])->breakOnFailure()); - $this->assertFalse($factory->createInput(['break_on_failure' => false])->breakOnFailure()); + self::assertFalse($factory->createInput(['break_on_failure' => false])->breakOnFailure()); } public function testCanCreateInputFilterWithNullInputs(): void @@ -877,42 +880,37 @@ public function testCanCreateInputFilterWithNullInputs(): void ], ]); - $this->assertInstanceOf(InputFilter::class, $inputFilter); - $this->assertEquals(2, count($inputFilter)); - $this->assertTrue($inputFilter->has('foo')); - $this->assertFalse($inputFilter->has('bar')); - $this->assertTrue($inputFilter->has('baz')); + self::assertInstanceOf(InputFilter::class, $inputFilter); + self::assertCount(2, $inputFilter); + self::assertTrue($inputFilter->has('foo')); + self::assertFalse($inputFilter->has('bar')); + self::assertTrue($inputFilter->has('baz')); } public function testCanCreateInputFromProvider(): void { - /** @var InputProviderInterface|MockObject $provider */ - $provider = $this->getMockBuilder(InputProviderInterface::class) - ->setMethods(['getInputSpecification']) - ->getMock(); + /** @var InputProviderInterface&MockObject $provider */ + $provider = $this->createMock(InputProviderInterface::class); $provider - ->expects($this->any()) + ->expects(self::any()) ->method('getInputSpecification') - ->will($this->returnValue(['name' => 'foo'])); + ->willReturn(['name' => 'foo']); $factory = $this->createDefaultFactory(); $input = $factory->createInput($provider); - $this->assertInstanceOf(InputInterface::class, $input); + self::assertInstanceOf(InputInterface::class, $input); } public function testCanCreateInputFilterFromProvider(): void { - /** @var InputFilterProviderInterface|MockObject $provider */ - $provider = $this->getMockBuilder(InputFilterProviderInterface::class) - ->setMethods(['getInputFilterSpecification']) - ->getMock(); - + /** @var InputFilterProviderInterface&MockObject $provider */ + $provider = $this->createMock(InputFilterProviderInterface::class); $provider - ->expects($this->any()) + ->expects(self::any()) ->method('getInputFilterSpecification') - ->will($this->returnValue([ + ->willReturn([ 'foo' => [ 'name' => 'foo', 'required' => false, @@ -921,12 +919,12 @@ public function testCanCreateInputFilterFromProvider(): void 'name' => 'baz', 'required' => true, ], - ])); + ]); $factory = $this->createDefaultFactory(); $inputFilter = $factory->createInputFilter($provider); - $this->assertInstanceOf(InputFilterInterface::class, $inputFilter); + self::assertInstanceOf(InputFilterInterface::class, $inputFilter); } public function testSuggestedTypeMayBePluginNameInInputFilterPluginManager(): void @@ -939,7 +937,9 @@ public function testSuggestedTypeMayBePluginNameInInputFilterPluginManager(): vo $input = $factory->createInput([ 'type' => 'bar', ]); - $this->assertSame('bar', $input->getName()); + + self::assertInstanceOf(InputInterface::class, $input); + self::assertSame('bar', $input->getName()); } public function testInputFromPluginManagerMayBeFurtherConfiguredWithSpec(): void @@ -947,7 +947,7 @@ public function testInputFromPluginManagerMayBeFurtherConfiguredWithSpec(): void $pluginManager = new InputFilterPluginManager(new ServiceManager\ServiceManager()); $pluginManager->setService('bar', $barInput = new Input('bar')); $factory = new Factory($pluginManager); - $this->assertTrue($barInput->isRequired()); + self::assertTrue($barInput->isRequired()); $factory->setInputFilterManager($pluginManager); $input = $factory->createInput([ @@ -955,8 +955,9 @@ public function testInputFromPluginManagerMayBeFurtherConfiguredWithSpec(): void 'required' => false, ]); - $this->assertFalse($input->isRequired()); - $this->assertSame('bar', $input->getName()); + self::assertInstanceOf(InputInterface::class, $input); + self::assertFalse($input->isRequired()); + self::assertSame('bar', $input->getName()); } public function testCreateInputFilterConfiguredNameWhenSpecIsIntegerIndexed(): void @@ -969,7 +970,7 @@ public function testCreateInputFilterConfiguredNameWhenSpecIsIntegerIndexed(): v ], ]); - $this->assertTrue($inputFilter->has('foo')); + self::assertTrue($inputFilter->has('foo')); } public function testCreateInputFilterUsesAssociatedNameMappingOverConfiguredName(): void @@ -982,8 +983,8 @@ public function testCreateInputFilterUsesAssociatedNameMappingOverConfiguredName ], ]); - $this->assertTrue($inputFilter->has('foo')); - $this->assertFalse($inputFilter->has('bar')); + self::assertTrue($inputFilter->has('foo')); + self::assertFalse($inputFilter->has('bar')); } public function testCreateInputFilterUsesConfiguredNameForNestedInputFilters(): void @@ -1011,35 +1012,35 @@ public function testCreateInputFilterUsesConfiguredNameForNestedInputFilters(): ], ]); - $this->assertInstanceOf(InputFilter::class, $inputFilter); - $this->assertEquals(2, count($inputFilter)); + self::assertInstanceOf(InputFilter::class, $inputFilter); + self::assertCount(2, $inputFilter); $nestedInputFilter = $inputFilter->get('bar'); - $this->assertInstanceOf(InputFilter::class, $nestedInputFilter); - $this->assertEquals(2, count($nestedInputFilter)); - $this->assertTrue($nestedInputFilter->has('bat')); - $this->assertTrue($nestedInputFilter->has('baz')); + self::assertInstanceOf(InputFilter::class, $nestedInputFilter); + self::assertCount(2, $nestedInputFilter); + self::assertTrue($nestedInputFilter->has('bat')); + self::assertTrue($nestedInputFilter->has('baz')); $collection = $inputFilter->get('foo'); - $this->assertInstanceOf(CollectionInputFilter::class, $collection); + self::assertInstanceOf(CollectionInputFilter::class, $collection); $collectionInputFilter = $collection->getInputFilter(); - $this->assertInstanceOf(InputFilter::class, $collectionInputFilter); - $this->assertEquals(1, count($collectionInputFilter)); - $this->assertTrue($collectionInputFilter->has('bat')); + self::assertInstanceOf(InputFilter::class, $collectionInputFilter); + self::assertCount(1, $collectionInputFilter); + self::assertTrue($collectionInputFilter->has('bat')); } public function testClearDefaultFilterChain(): void { $factory = $this->createDefaultFactory(); $factory->clearDefaultFilterChain(); - $this->assertNull($factory->getDefaultFilterChain()); + self::assertNull($factory->getDefaultFilterChain()); } public function testClearDefaultValidatorChain(): void { $factory = $this->createDefaultFactory(); $factory->clearDefaultValidatorChain(); - $this->assertNull($factory->getDefaultValidatorChain()); + self::assertNull($factory->getDefaultValidatorChain()); } public function testWhenCreateInputPullsInputFromThePluginManagerItMustNotOverwriteFilterAndValidatorChains(): void @@ -1083,12 +1084,12 @@ public function testFactoryCanCreateCollectionInputFilterWithRequiredMessage(): 'count' => 3, ]); - $this->assertInstanceOf(CollectionInputFilter::class, $inputFilter); + self::assertInstanceOf(CollectionInputFilter::class, $inputFilter); $notEmptyValidator = $inputFilter->getNotEmptyValidator(); $messageTemplates = $notEmptyValidator->getMessageTemplates(); - $this->assertArrayHasKey(Validator\NotEmpty::IS_EMPTY, $messageTemplates); - $this->assertSame($message, $messageTemplates[Validator\NotEmpty::IS_EMPTY]); + self::assertArrayHasKey(Validator\NotEmpty::IS_EMPTY, $messageTemplates); + self::assertSame($message, $messageTemplates[Validator\NotEmpty::IS_EMPTY]); } protected function createDefaultFactory(): Factory @@ -1104,11 +1105,11 @@ protected function createInputFilterPluginManagerMockForPlugin( $pluginValue ): InputFilterPluginManager { $pluginManager = $this->createMock(InputFilterPluginManager::class); - $pluginManager->expects($this->atLeastOnce()) + $pluginManager->expects(self::atLeastOnce()) ->method('has') ->with($pluginName) ->willReturn(true); - $pluginManager->expects($this->atLeastOnce()) + $pluginManager->expects(self::atLeastOnce()) ->method('get') ->with($pluginName) ->willReturn($pluginValue); diff --git a/test/FileInput/HttpServerFileInputDecoratorTest.php b/test/FileInput/HttpServerFileInputDecoratorTest.php index 94d758a3..870d539a 100644 --- a/test/FileInput/HttpServerFileInputDecoratorTest.php +++ b/test/FileInput/HttpServerFileInputDecoratorTest.php @@ -10,7 +10,6 @@ use LaminasTest\InputFilter\InputTest; use Webmozart\Assert\Assert; -use function count; use function json_encode; use const JSON_THROW_ON_ERROR; @@ -35,7 +34,7 @@ protected function setUp(): void public function testRetrievingValueFiltersTheValue(): void { - $this->markTestSkipped('Test are not enabled in FileInputTest'); + self::markTestSkipped('Test are not enabled in FileInputTest'); } public function testRetrievingValueFiltersTheValueOnlyAfterValidating(): void @@ -46,12 +45,12 @@ public function testRetrievingValueFiltersTheValueOnlyAfterValidating(): void $newValue = ['tmp_name' => 'foo']; $this->input->setFilterChain($this->createFilterChainMock([[$value, $newValue]])); - $this->assertEquals($value, $this->input->getValue()); - $this->assertTrue( + self::assertEquals($value, $this->input->getValue()); + self::assertTrue( $this->input->isValid(), 'isValid() value not match. Detail . ' . json_encode($this->input->getMessages(), JSON_THROW_ON_ERROR) ); - $this->assertEquals($newValue, $this->input->getValue()); + self::assertEquals($newValue, $this->input->getValue()); } public function testCanFilterArrayOfMultiFileData(): void @@ -71,12 +70,12 @@ public function testCanFilterArrayOfMultiFileData(): void [$values[2], $newValue], ])); - $this->assertEquals($values, $this->input->getValue()); - $this->assertTrue( + self::assertEquals($values, $this->input->getValue()); + self::assertTrue( $this->input->isValid(), 'isValid() value not match. Detail . ' . json_encode($this->input->getMessages(), JSON_THROW_ON_ERROR) ); - $this->assertEquals( + self::assertEquals( $filteredValue, $this->input->getValue() ); @@ -90,12 +89,12 @@ public function testCanRetrieveRawValue(): void $newValue = ['tmp_name' => 'new']; $this->input->setFilterChain($this->createFilterChainMock([[$value, $newValue]])); - $this->assertEquals($value, $this->input->getRawValue()); + self::assertEquals($value, $this->input->getRawValue()); } public function testValidationOperatesOnFilteredValue(): void { - $this->markTestSkipped('Test is not enabled in FileInputTest'); + self::markTestSkipped('Test is not enabled in FileInputTest'); } public function testValidationOperatesBeforeFiltering(): void @@ -112,21 +111,21 @@ public function testValidationOperatesBeforeFiltering(): void $this->input->setFilterChain($this->createFilterChainMock([[$badValue, $filteredValue]])); $this->input->setValidatorChain($this->createValidatorChainMock([[$badValue, null, false]])); - $this->assertFalse($this->input->isValid()); - $this->assertEquals($badValue, $this->input->getValue()); + self::assertFalse($this->input->isValid()); + self::assertEquals($badValue, $this->input->getValue()); } public function testAutoPrependUploadValidatorIsOnByDefault(): void { $input = new FileInput('foo'); - $this->assertTrue($input->getAutoPrependUploadValidator()); + self::assertTrue($input->getAutoPrependUploadValidator()); } public function testUploadValidatorIsAddedWhenIsValidIsCalled(): void { $this->input->setAutoPrependUploadValidator(true); - $this->assertTrue($this->input->getAutoPrependUploadValidator()); - $this->assertTrue($this->input->isRequired()); + self::assertTrue($this->input->getAutoPrependUploadValidator()); + self::assertTrue($this->input->isRequired()); $this->input->setValue([ 'tmp_name' => __FILE__, 'name' => 'foo', @@ -134,60 +133,58 @@ public function testUploadValidatorIsAddedWhenIsValidIsCalled(): void 'error' => 0, ]); $validatorChain = $this->input->getValidatorChain(); - $this->assertEquals(0, count($validatorChain->getValidators())); + self::assertCount(0, $validatorChain->getValidators()); - $this->assertFalse($this->input->isValid()); + self::assertFalse($this->input->isValid()); $validators = $validatorChain->getValidators(); - $this->assertEquals(1, count($validators)); - $this->assertInstanceOf(Validator\File\UploadFile::class, $validators[0]['instance']); + self::assertCount(1, $validators); + self::assertInstanceOf(Validator\File\UploadFile::class, $validators[0]['instance']); } public function testUploadValidatorIsNotAddedWhenIsValidIsCalled(): void { - $this->assertFalse($this->input->getAutoPrependUploadValidator()); - $this->assertTrue($this->input->isRequired()); + self::assertFalse($this->input->getAutoPrependUploadValidator()); + self::assertTrue($this->input->isRequired()); $this->input->setValue(['tmp_name' => 'bar']); $validatorChain = $this->input->getValidatorChain(); - $this->assertEquals(0, count($validatorChain->getValidators())); + self::assertCount(0, $validatorChain->getValidators()); - $this->assertTrue( + self::assertTrue( $this->input->isValid(), 'isValid() value not match. Detail . ' . json_encode($this->input->getMessages(), JSON_THROW_ON_ERROR) ); - $this->assertEquals(0, count($validatorChain->getValidators())); + self::assertCount(0, $validatorChain->getValidators()); } public function testRequiredUploadValidatorValidatorNotAddedWhenOneExists(): void { $this->input->setAutoPrependUploadValidator(true); - $this->assertTrue($this->input->getAutoPrependUploadValidator()); - $this->assertTrue($this->input->isRequired()); + self::assertTrue($this->input->getAutoPrependUploadValidator()); + self::assertTrue($this->input->isRequired()); $this->input->setValue(['tmp_name' => 'bar']); - $uploadMock = $this->getMockBuilder(Validator\File\UploadFile::class) - ->setMethods(['isValid']) - ->getMock(); - $uploadMock->expects($this->exactly(1)) + $uploadMock = $this->createMock(Validator\File\UploadFile::class); + $uploadMock->expects(self::exactly(1)) ->method('isValid') - ->will($this->returnValue(true)); + ->willReturn(true); $validatorChain = $this->input->getValidatorChain(); $validatorChain->prependValidator($uploadMock); - $this->assertTrue( + self::assertTrue( $this->input->isValid(), 'isValid() value not match. Detail . ' . json_encode($this->input->getMessages(), JSON_THROW_ON_ERROR) ); $validators = $validatorChain->getValidators(); - $this->assertEquals(1, count($validators)); - $this->assertEquals($uploadMock, $validators[0]['instance']); + self::assertCount(1, $validators); + self::assertEquals($uploadMock, $validators[0]['instance']); } public function testValidationsRunWithoutFileArrayDueToAjaxPost(): void { $this->input->setAutoPrependUploadValidator(true); - $this->assertTrue($this->input->getAutoPrependUploadValidator()); - $this->assertTrue($this->input->isRequired()); + self::assertTrue($this->input->getAutoPrependUploadValidator()); + self::assertTrue($this->input->isRequired()); $this->input->setValue(''); $expectedNormalizedValue = [ @@ -198,14 +195,14 @@ public function testValidationsRunWithoutFileArrayDueToAjaxPost(): void 'error' => UPLOAD_ERR_NO_FILE, ]; $this->input->setValidatorChain($this->createValidatorChainMock([[$expectedNormalizedValue, null, false]])); - $this->assertFalse($this->input->isValid()); + self::assertFalse($this->input->isValid()); } public function testValidationsRunWithoutFileArrayIsSend(): void { $this->input->setAutoPrependUploadValidator(true); - $this->assertTrue($this->input->getAutoPrependUploadValidator()); - $this->assertTrue($this->input->isRequired()); + self::assertTrue($this->input->getAutoPrependUploadValidator()); + self::assertTrue($this->input->isRequired()); $this->input->setValue([]); $expectedNormalizedValue = [ 'tmp_name' => '', @@ -215,19 +212,19 @@ public function testValidationsRunWithoutFileArrayIsSend(): void 'error' => UPLOAD_ERR_NO_FILE, ]; $this->input->setValidatorChain($this->createValidatorChainMock([[$expectedNormalizedValue, null, false]])); - $this->assertFalse($this->input->isValid()); + self::assertFalse($this->input->isValid()); } /** @param mixed $value */ public function testNotEmptyValidatorAddedWhenIsValidIsCalled($value = null): void { - $this->markTestSkipped('Test is not enabled in FileInputTest'); + self::markTestSkipped('Test is not enabled in FileInputTest'); } /** @param mixed $value */ public function testRequiredNotEmptyValidatorNotAddedWhenOneExists($value = null): void { - $this->markTestSkipped('Test is not enabled in FileInputTest'); + self::markTestSkipped('Test is not enabled in FileInputTest'); } /** @@ -242,7 +239,7 @@ public function testFallbackValueVsIsValidRules( ?bool $isValid = null, $expectedValue = null ): void { - $this->markTestSkipped('Input::setFallbackValue is not implemented on FileInput'); + self::markTestSkipped('Input::setFallbackValue is not implemented on FileInput'); } /** @param null|string|string[] $fallbackValue */ @@ -250,13 +247,13 @@ public function testFallbackValueVsIsValidRulesWhenValueNotSet( ?bool $required = null, $fallbackValue = null ): void { - $this->markTestSkipped('Input::setFallbackValue is not implemented on FileInput'); + self::markTestSkipped('Input::setFallbackValue is not implemented on FileInput'); } public function testIsEmptyFileNotArray(): void { $rawValue = 'file'; - $this->assertTrue($this->input->isEmptyFile($rawValue)); + self::assertTrue($this->input->isEmptyFile($rawValue)); } public function testIsEmptyFileUploadNoFile(): void @@ -265,7 +262,7 @@ public function testIsEmptyFileUploadNoFile(): void 'tmp_name' => '', 'error' => UPLOAD_ERR_NO_FILE, ]; - $this->assertTrue($this->input->isEmptyFile($rawValue)); + self::assertTrue($this->input->isEmptyFile($rawValue)); } public function testIsEmptyFileOk(): void @@ -274,7 +271,7 @@ public function testIsEmptyFileOk(): void 'tmp_name' => 'name', 'error' => UPLOAD_ERR_OK, ]; - $this->assertFalse($this->input->isEmptyFile($rawValue)); + self::assertFalse($this->input->isEmptyFile($rawValue)); } public function testIsEmptyMultiFileUploadNoFile(): void @@ -285,7 +282,7 @@ public function testIsEmptyMultiFileUploadNoFile(): void 'error' => UPLOAD_ERR_NO_FILE, ], ]; - $this->assertTrue($this->input->isEmptyFile($rawValue)); + self::assertTrue($this->input->isEmptyFile($rawValue)); } public function testIsEmptyFileMultiFileOk(): void @@ -300,7 +297,7 @@ public function testIsEmptyFileMultiFileOk(): void 'error' => UPLOAD_ERR_OK, ], ]; - $this->assertFalse($this->input->isEmptyFile($rawValue)); + self::assertFalse($this->input->isEmptyFile($rawValue)); } public function testDefaultInjectedUploadValidatorRespectsRelease2Convention(): void @@ -311,7 +308,7 @@ public function testDefaultInjectedUploadValidatorRespectsRelease2Convention(): $pluginManager->setInvokableClass('fileuploadfile', TestAsset\FileUploadMock::class); $input->setValue(''); - $this->assertTrue($input->isValid()); + self::assertTrue($input->isValid()); } /** @@ -326,9 +323,9 @@ public function testFileInputMerge(): void $target->setAutoPrependUploadValidator(false); $return = $target->merge($source); - $this->assertSame($target, $return, 'merge() must return it self'); + self::assertSame($target, $return, 'merge() must return it self'); - $this->assertEquals( + self::assertEquals( true, $target->getAutoPrependUploadValidator(), 'getAutoPrependUploadValidator() value not match' diff --git a/test/FileInput/PsrFileInputDecoratorTest.php b/test/FileInput/PsrFileInputDecoratorTest.php index 1850a1fb..c3a7a60d 100644 --- a/test/FileInput/PsrFileInputDecoratorTest.php +++ b/test/FileInput/PsrFileInputDecoratorTest.php @@ -11,7 +11,6 @@ use LaminasTest\InputFilter\InputTest; use Psr\Http\Message\UploadedFileInterface; -use function count; use function in_array; use function json_encode; @@ -38,7 +37,7 @@ protected function setUp(): void public function testRetrievingValueFiltersTheValue(): void { - $this->markTestSkipped('Test is not enabled in PsrFileInputTest'); + self::markTestSkipped('Test is not enabled in PsrFileInputTest'); } public function testRetrievingValueFiltersTheValueOnlyAfterValidating(): void @@ -59,12 +58,12 @@ public function testRetrievingValueFiltersTheValueOnlyAfterValidating(): void ], ])); - $this->assertEquals($upload, $this->input->getValue()); - $this->assertTrue( + self::assertEquals($upload, $this->input->getValue()); + self::assertTrue( $this->input->isValid(), 'isValid() value not match. Detail . ' . json_encode($this->input->getMessages(), JSON_THROW_ON_ERROR) ); - $this->assertEquals($filteredUpload, $this->input->getValue()); + self::assertEquals($filteredUpload, $this->input->getValue()); } public function testCanFilterArrayOfMultiFileData(): void @@ -90,12 +89,12 @@ public function testCanFilterArrayOfMultiFileData(): void [$values[2], $filteredValues[2]], ])); - $this->assertEquals($values, $this->input->getValue()); - $this->assertTrue( + self::assertEquals($values, $this->input->getValue()); + self::assertTrue( $this->input->isValid(), 'isValid() value not match. Detail . ' . json_encode($this->input->getMessages(), JSON_THROW_ON_ERROR) ); - $this->assertEquals( + self::assertEquals( $filteredValues, $this->input->getValue() ); @@ -111,12 +110,12 @@ public function testCanRetrieveRawValue(): void $filteredValue = $this->createMock(UploadedFileInterface::class); $this->input->setFilterChain($this->createFilterChainMock([[$value, $filteredValue]])); - $this->assertEquals($value, $this->input->getRawValue()); + self::assertEquals($value, $this->input->getRawValue()); } public function testValidationOperatesOnFilteredValue(): void { - $this->markTestSkipped('Test is not enabled in PsrFileInputTest'); + self::markTestSkipped('Test is not enabled in PsrFileInputTest'); } public function testValidationOperatesBeforeFiltering(): void @@ -132,21 +131,21 @@ public function testValidationOperatesBeforeFiltering(): void $this->input->setFilterChain($this->createFilterChainMock([[$badValue, $filteredValue]])); $this->input->setValidatorChain($this->createValidatorChainMock([[$badValue, null, false]])); - $this->assertFalse($this->input->isValid()); - $this->assertEquals($badValue, $this->input->getValue()); + self::assertFalse($this->input->isValid()); + self::assertEquals($badValue, $this->input->getValue()); } public function testAutoPrependUploadValidatorIsOnByDefault(): void { $input = new FileInput('foo'); - $this->assertTrue($input->getAutoPrependUploadValidator()); + self::assertTrue($input->getAutoPrependUploadValidator()); } public function testUploadValidatorIsAddedDuringIsValidWhenAutoPrependUploadValidatorIsEnabled(): void { $this->input->setAutoPrependUploadValidator(true); - $this->assertTrue($this->input->getAutoPrependUploadValidator()); - $this->assertTrue($this->input->isRequired()); + self::assertTrue($this->input->getAutoPrependUploadValidator()); + self::assertTrue($this->input->isRequired()); $uploadedFile = $this->createMock(UploadedFileInterface::class); $uploadedFile->expects(self::atLeast(1)) @@ -156,18 +155,18 @@ public function testUploadValidatorIsAddedDuringIsValidWhenAutoPrependUploadVali $this->input->setValue($uploadedFile); $validatorChain = $this->input->getValidatorChain(); - $this->assertCount(0, $validatorChain->getValidators()); + self::assertCount(0, $validatorChain->getValidators()); - $this->assertFalse($this->input->isValid()); + self::assertFalse($this->input->isValid()); $validators = $validatorChain->getValidators(); - $this->assertCount(1, $validators); - $this->assertInstanceOf(Validator\File\UploadFile::class, $validators[0]['instance']); + self::assertCount(1, $validators); + self::assertInstanceOf(Validator\File\UploadFile::class, $validators[0]['instance']); } public function testUploadValidatorIsNotAddedByDefaultDuringIsValidWhenAutoPrependUploadValidatorIsDisabled(): void { - $this->assertFalse($this->input->getAutoPrependUploadValidator()); - $this->assertTrue($this->input->isRequired()); + self::assertFalse($this->input->getAutoPrependUploadValidator()); + self::assertTrue($this->input->isRequired()); $uploadedFile = $this->createMock(UploadedFileInterface::class); $uploadedFile->expects(self::atLeast(1)) @@ -176,20 +175,20 @@ public function testUploadValidatorIsNotAddedByDefaultDuringIsValidWhenAutoPrepe $this->input->setValue($uploadedFile); $validatorChain = $this->input->getValidatorChain(); - $this->assertEquals(0, count($validatorChain->getValidators())); + self::assertCount(0, $validatorChain->getValidators()); - $this->assertTrue( + self::assertTrue( $this->input->isValid(), 'isValid() value not match. Detail . ' . json_encode($this->input->getMessages(), JSON_THROW_ON_ERROR) ); - $this->assertEquals(0, count($validatorChain->getValidators())); + self::assertCount(0, $validatorChain->getValidators()); } public function testRequiredUploadValidatorValidatorNotAddedWhenOneExists(): void { $this->input->setAutoPrependUploadValidator(true); - $this->assertTrue($this->input->getAutoPrependUploadValidator()); - $this->assertTrue($this->input->isRequired()); + self::assertTrue($this->input->getAutoPrependUploadValidator()); + self::assertTrue($this->input->isRequired()); $upload = $this->createMock(UploadedFileInterface::class); $upload->expects(self::atLeast(1)) @@ -206,26 +205,26 @@ public function testRequiredUploadValidatorValidatorNotAddedWhenOneExists(): voi $validatorChain = $this->input->getValidatorChain(); $validatorChain->prependValidator($validator); - $this->assertTrue( + self::assertTrue( $this->input->isValid(), 'isValid() value not match. Detail . ' . json_encode($this->input->getMessages(), JSON_THROW_ON_ERROR) ); $validators = $validatorChain->getValidators(); - $this->assertEquals(1, count($validators)); - $this->assertEquals($validator, $validators[0]['instance']); + self::assertCount(1, $validators); + self::assertEquals($validator, $validators[0]['instance']); } /** @param mixed $value */ public function testNotEmptyValidatorAddedWhenIsValidIsCalled($value = null): void { - $this->markTestSkipped('Test is not enabled in PsrFileInputTest'); + self::markTestSkipped('Test is not enabled in PsrFileInputTest'); } /** @param mixed $value */ public function testRequiredNotEmptyValidatorNotAddedWhenOneExists($value = null): void { - $this->markTestSkipped('Test is not enabled in PsrFileInputTest'); + self::markTestSkipped('Test is not enabled in PsrFileInputTest'); } /** @@ -240,7 +239,7 @@ public function testFallbackValueVsIsValidRules( ?bool $isValid = null, $expectedValue = null ): void { - $this->markTestSkipped('Input::setFallbackValue is not implemented on PsrFileInput'); + self::markTestSkipped('Input::setFallbackValue is not implemented on PsrFileInput'); } /** @param null|string|string[] $fallbackValue */ @@ -248,7 +247,7 @@ public function testFallbackValueVsIsValidRulesWhenValueNotSet( ?bool $required = null, $fallbackValue = null ): void { - $this->markTestSkipped('Input::setFallbackValue is not implemented on PsrFileInput'); + self::markTestSkipped('Input::setFallbackValue is not implemented on PsrFileInput'); } public function testIsEmptyFileUploadNoFile(): void @@ -257,7 +256,7 @@ public function testIsEmptyFileUploadNoFile(): void $upload->expects(self::atLeast(1)) ->method('getError') ->willReturn(UPLOAD_ERR_NO_FILE); - $this->assertTrue($this->input->isEmptyFile($upload)); + self::assertTrue($this->input->isEmptyFile($upload)); } public function testIsEmptyFileOk(): void @@ -266,7 +265,7 @@ public function testIsEmptyFileOk(): void $upload->expects(self::atLeast(1)) ->method('getError') ->willReturn(UPLOAD_ERR_OK); - $this->assertFalse($this->input->isEmptyFile($upload)); + self::assertFalse($this->input->isEmptyFile($upload)); } public function testIsEmptyMultiFileUploadNoFile(): void @@ -278,7 +277,7 @@ public function testIsEmptyMultiFileUploadNoFile(): void $rawValue = [$upload]; - $this->assertTrue($this->input->isEmptyFile($rawValue)); + self::assertTrue($this->input->isEmptyFile($rawValue)); } public function testIsEmptyFileMultiFileOk(): void @@ -292,7 +291,7 @@ public function testIsEmptyFileMultiFileOk(): void $rawValue[] = $upload; } - $this->assertFalse($this->input->isEmptyFile($rawValue)); + self::assertFalse($this->input->isEmptyFile($rawValue)); } /** @@ -307,9 +306,9 @@ public function testPsrFileInputMerge(): void $target->setAutoPrependUploadValidator(false); $return = $target->merge($source); - $this->assertSame($target, $return, 'merge() must return it self'); + self::assertSame($target, $return, 'merge() must return it self'); - $this->assertEquals( + self::assertEquals( true, $target->getAutoPrependUploadValidator(), 'getAutoPrependUploadValidator() value not match' diff --git a/test/InputFilterAbstractServiceFactoryTest.php b/test/InputFilterAbstractServiceFactoryTest.php index f986ddc3..1275bf96 100644 --- a/test/InputFilterAbstractServiceFactoryTest.php +++ b/test/InputFilterAbstractServiceFactoryTest.php @@ -5,34 +5,32 @@ namespace LaminasTest\InputFilter; use Laminas\Filter; +use Laminas\Filter\FilterChain; use Laminas\Filter\FilterPluginManager; use Laminas\InputFilter\FileInput; +use Laminas\InputFilter\InputFilter; use Laminas\InputFilter\InputFilterAbstractServiceFactory; use Laminas\InputFilter\InputFilterInterface; use Laminas\InputFilter\InputFilterPluginManager; +use Laminas\InputFilter\InputInterface; use Laminas\ServiceManager\ServiceManager; use Laminas\Validator; +use Laminas\Validator\ValidatorChain; use Laminas\Validator\ValidatorInterface; use Laminas\Validator\ValidatorPluginManager; use LaminasTest\InputFilter\TestAsset\Foo; use PHPUnit\Framework\TestCase; use function call_user_func_array; -use function count; /** * @covers \Laminas\InputFilter\InputFilterAbstractServiceFactory */ class InputFilterAbstractServiceFactoryTest extends TestCase { - /** @var ServiceManager */ - protected $services; - - /** @var InputFilterPluginManager */ - protected $filters; - - /** @var InputFilterAbstractServiceFactory */ - protected $factory; + private ServiceManager $services; + private InputFilterPluginManager $filters; + private InputFilterAbstractServiceFactory $factory; protected function setUp(): void { @@ -47,7 +45,7 @@ public function testCannotCreateServiceIfNoConfigServicePresent(): void { $method = 'canCreate'; $args = [$this->services, 'filter']; - $this->assertFalse(call_user_func_array([$this->factory, $method], $args)); + self::assertFalse(call_user_func_array([$this->factory, $method], $args)); } public function testCannotCreateServiceIfConfigServiceDoesNotHaveInputFiltersConfiguration(): void @@ -56,7 +54,7 @@ public function testCannotCreateServiceIfConfigServiceDoesNotHaveInputFiltersCon $method = 'canCreate'; $args = [$this->services, 'filter']; - $this->assertFalse(call_user_func_array([$this->factory, $method], $args)); + self::assertFalse(call_user_func_array([$this->factory, $method], $args)); } public function testCannotCreateServiceIfConfigInputFiltersDoesNotContainMatchingServiceName(): void @@ -66,7 +64,7 @@ public function testCannotCreateServiceIfConfigInputFiltersDoesNotContainMatchin ]); $method = 'canCreate'; $args = [$this->services, 'filter']; - $this->assertFalse(call_user_func_array([$this->factory, $method], $args)); + self::assertFalse(call_user_func_array([$this->factory, $method], $args)); } public function testCanCreateServiceIfConfigInputFiltersContainsMatchingServiceName(): void @@ -78,7 +76,7 @@ public function testCanCreateServiceIfConfigInputFiltersContainsMatchingServiceN ]); $method = 'canCreate'; $args = [$this->services, 'filter']; - $this->assertTrue(call_user_func_array([$this->factory, $method], $args)); + self::assertTrue(call_user_func_array([$this->factory, $method], $args)); } public function testCreatesInputFilterInstance(): void @@ -91,7 +89,7 @@ public function testCreatesInputFilterInstance(): void $method = '__invoke'; $args = [$this->services, 'filter']; $filter = call_user_func_array([$this->factory, $method], $args); - $this->assertInstanceOf(InputFilterInterface::class, $filter); + self::assertInstanceOf(InputFilterInterface::class, $filter); } /** @@ -100,7 +98,7 @@ public function testCreatesInputFilterInstance(): void public function testUsesConfiguredValidationAndFilterManagerServicesWhenCreatingInputFilter(): void { $filters = new FilterPluginManager($this->services); - $filter = static function () { + $filter = static function (): void { }; $filters->setService('foo', $filter); @@ -130,21 +128,25 @@ public function testUsesConfiguredValidationAndFilterManagerServicesWhenCreating $method = '__invoke'; $args = [$this->services, 'filter']; $inputFilter = call_user_func_array([$this->factory, $method], $args); - $this->assertTrue($inputFilter->has('input')); + self::assertInstanceOf(InputFilterInterface::class, $inputFilter); + self::assertTrue($inputFilter->has('input')); $input = $inputFilter->get('input'); + self::assertInstanceOf(InputInterface::class, $input); $filterChain = $input->getFilterChain(); - $this->assertSame($filters, $filterChain->getPluginManager()); - $this->assertEquals(1, count($filterChain)); - $this->assertSame($filter, $filterChain->plugin('foo')); - $this->assertEquals(1, count($filterChain)); + self::assertInstanceOf(FilterChain::class, $filterChain); + self::assertSame($filters, $filterChain->getPluginManager()); + self::assertCount(1, $filterChain); + self::assertSame($filter, $filterChain->plugin('foo')); + self::assertCount(1, $filterChain); $validatorChain = $input->getValidatorChain(); - $this->assertSame($validators, $validatorChain->getPluginManager()); - $this->assertEquals(1, count($validatorChain)); - $this->assertSame($validator, $validatorChain->plugin('foo')); - $this->assertEquals(1, count($validatorChain)); + self::assertInstanceOf(ValidatorChain::class, $validatorChain); + self::assertSame($validators, $validatorChain->getPluginManager()); + self::assertCount(1, $validatorChain); + self::assertSame($validator, $validatorChain->plugin('foo')); + self::assertCount(1, $validatorChain); } public function testRetrieveInputFilterFromInputFilterPluginManager(): void @@ -180,7 +182,7 @@ public function testRetrieveInputFilterFromInputFilterPluginManager(): void ->addAbstractFactory(InputFilterAbstractServiceFactory::class); $inputFilter = $this->services->get(InputFilterPluginManager::class)->get('foobar'); - $this->assertInstanceOf(InputFilterInterface::class, $inputFilter); + self::assertInstanceOf(InputFilterInterface::class, $inputFilter); } /** @@ -194,11 +196,12 @@ public function testInjectsInputFilterManagerFromServiceManager(): void ], ]); $this->filters->addAbstractFactory(TestAsset\FooAbstractFactory::class); - $filter = $this->factory->__invoke($this->services, 'filter'); + $filter = $this->factory->__invoke($this->services, 'filter'); + self::assertInstanceOf(InputFilter::class, $filter); $inputFilterManager = $filter->getFactory()->getInputFilterManager(); - $this->assertInstanceOf(InputFilterPluginManager::class, $inputFilterManager); - $this->assertInstanceOf(Foo::class, $inputFilterManager->get('foo')); + self::assertInstanceOf(InputFilterPluginManager::class, $inputFilterManager); + self::assertInstanceOf(Foo::class, $inputFilterManager->get('foo')); } public function testAllowsPassingNonPluginManagerContainerToFactoryWithServiceManagerV2(): void @@ -211,9 +214,9 @@ public function testAllowsPassingNonPluginManagerContainerToFactoryWithServiceMa $canCreate = 'canCreate'; $create = '__invoke'; $args = [$this->services, 'filter']; - $this->assertTrue(call_user_func_array([$this->factory, $canCreate], $args)); + self::assertTrue(call_user_func_array([$this->factory, $canCreate], $args)); $inputFilter = call_user_func_array([$this->factory, $create], $args); - $this->assertInstanceOf(InputFilterInterface::class, $inputFilter); + self::assertInstanceOf(InputFilterInterface::class, $inputFilter); } /** @@ -272,16 +275,16 @@ public function testWillUseCustomFiltersWhenProvided(): void ->addAbstractFactory(InputFilterAbstractServiceFactory::class); $inputFilter = $this->services->get(InputFilterPluginManager::class)->get('test'); - $this->assertInstanceOf(InputFilterInterface::class, $inputFilter); + self::assertInstanceOf(InputFilterInterface::class, $inputFilter); $input = $inputFilter->get('a-file-element'); - $this->assertInstanceOf(FileInput::class, $input); + self::assertInstanceOf(FileInput::class, $input); $filters = $input->getFilterChain(); - $this->assertCount(1, $filters); + self::assertCount(1, $filters); $callback = $filters->getFilters()->top(); - $this->assertIsArray($callback); - $this->assertSame($filter, $callback[0]); + self::assertIsArray($callback); + self::assertSame($filter, $callback[0]); } } diff --git a/test/InputFilterPluginManagerFactoryTest.php b/test/InputFilterPluginManagerFactoryTest.php index 5cd35561..6dcafcf7 100644 --- a/test/InputFilterPluginManagerFactoryTest.php +++ b/test/InputFilterPluginManagerFactoryTest.php @@ -21,15 +21,15 @@ public function testFactoryReturnsPluginManager(): void $factory = new InputFilterPluginManagerFactory(); $filters = $factory($container, InputFilterPluginManagerFactory::class); - $this->assertInstanceOf(InputFilterPluginManager::class, $filters); + self::assertInstanceOf(InputFilterPluginManager::class, $filters); $r = new ReflectionObject($filters); $p = $r->getProperty('creationContext'); $p->setAccessible(true); - $this->assertSame($container, $p->getValue($filters)); + self::assertSame($container, $p->getValue($filters)); } - /** @psalm-return array}> */ + /** @psalm-return array */ public function pluginProvider(): array { return [ @@ -54,7 +54,7 @@ public function testFactoryConfiguresPluginManagerUnderContainerInterop(string $ 'test' => $plugin, ], ]); - $this->assertSame($plugin, $filters->get('test')); + self::assertSame($plugin, $filters->get('test')); } public function testConfiguresInputFilterServicesWhenFound(): void @@ -84,11 +84,11 @@ public function testConfiguresInputFilterServicesWhenFound(): void $factory = new InputFilterPluginManagerFactory(); $inputFilters = $factory($container); - $this->assertInstanceOf(InputFilterPluginManager::class, $inputFilters); - $this->assertTrue($inputFilters->has('test')); - $this->assertSame($inputFilter, $inputFilters->get('test')); - $this->assertTrue($inputFilters->has('test-too')); - $this->assertSame($inputFilter, $inputFilters->get('test-too')); + self::assertInstanceOf(InputFilterPluginManager::class, $inputFilters); + self::assertTrue($inputFilters->has('test')); + self::assertSame($inputFilter, $inputFilters->get('test')); + self::assertTrue($inputFilters->has('test-too')); + self::assertSame($inputFilter, $inputFilters->get('test-too')); } public function testDoesNotConfigureInputFilterServicesWhenServiceListenerPresent(): void @@ -104,9 +104,9 @@ public function testDoesNotConfigureInputFilterServicesWhenServiceListenerPresen $factory = new InputFilterPluginManagerFactory(); $inputFilters = $factory($container); - $this->assertInstanceOf(InputFilterPluginManager::class, $inputFilters); - $this->assertFalse($inputFilters->has('test')); - $this->assertFalse($inputFilters->has('test-too')); + self::assertInstanceOf(InputFilterPluginManager::class, $inputFilters); + self::assertFalse($inputFilters->has('test')); + self::assertFalse($inputFilters->has('test-too')); } public function testDoesNotConfigureInputFilterServicesWhenConfigServiceNotPresent(): void @@ -122,7 +122,7 @@ public function testDoesNotConfigureInputFilterServicesWhenConfigServiceNotPrese $factory = new InputFilterPluginManagerFactory(); $inputFilters = $factory($container); - $this->assertInstanceOf(InputFilterPluginManager::class, $inputFilters); + self::assertInstanceOf(InputFilterPluginManager::class, $inputFilters); } public function testDoesNotConfigureInputFilterServicesWhenConfigServiceDoesNotContainInputFiltersConfig(): void @@ -141,7 +141,7 @@ public function testDoesNotConfigureInputFilterServicesWhenConfigServiceDoesNotC $factory = new InputFilterPluginManagerFactory(); $inputFilters = $factory($container); - $this->assertInstanceOf(InputFilterPluginManager::class, $inputFilters); - $this->assertFalse($inputFilters->has('foo')); + self::assertInstanceOf(InputFilterPluginManager::class, $inputFilters); + self::assertFalse($inputFilters->has('foo')); } } diff --git a/test/InputFilterPluginManagerTest.php b/test/InputFilterPluginManagerTest.php index 41ea2c8c..cd09c158 100644 --- a/test/InputFilterPluginManagerTest.php +++ b/test/InputFilterPluginManagerTest.php @@ -4,6 +4,7 @@ namespace LaminasTest\InputFilter; +use Laminas\Filter\FilterChain; use Laminas\Filter\FilterPluginManager; use Laminas\InputFilter\CollectionInputFilter; use Laminas\InputFilter\Exception\RuntimeException; @@ -15,11 +16,13 @@ use Laminas\ServiceManager\Exception\InvalidServiceException; use Laminas\ServiceManager\ServiceLocatorInterface; use Laminas\ServiceManager\ServiceManager; +use Laminas\Validator\ValidatorChain; use Laminas\Validator\ValidatorPluginManager; use LaminasTest\InputFilter\FileInput\TestAsset\InitializableInputFilterInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use ReflectionObject; +use Throwable; use function method_exists; @@ -28,11 +31,8 @@ */ class InputFilterPluginManagerTest extends TestCase { - /** @var InputFilterPluginManager */ - protected $manager; - - /** @var ServiceManager */ - protected $services; + private InputFilterPluginManager $manager; + private ServiceManager $services; protected function setUp(): void { @@ -42,7 +42,7 @@ protected function setUp(): void public function testIsASubclassOfAbstractPluginManager(): void { - $this->assertInstanceOf(AbstractPluginManager::class, $this->manager); + self::assertInstanceOf(AbstractPluginManager::class, $this->manager); } public function testIsNotSharedByDefault(): void @@ -50,7 +50,7 @@ public function testIsNotSharedByDefault(): void $r = new ReflectionObject($this->manager); $p = $r->getProperty('sharedByDefault'); $p->setAccessible(true); - $this->assertFalse($p->getValue($this->manager)); + self::assertFalse($p->getValue($this->manager)); } public function testRegisteringInvalidElementRaisesException(): void @@ -65,7 +65,7 @@ public function testRegisteringInvalidElementRaisesException(): void public function testLoadingInvalidElementRaisesException(): void { - $this->manager->setInvokableClass('test', static::class); + $this->manager->setInvokableClass('test', self::class); $this->expectException($this->getServiceNotFoundException()); $this->manager->get('test'); } @@ -89,7 +89,7 @@ public function testDefaultInvokableClasses(string $alias, string $expectedInsta /** @var object $service */ $service = $this->manager->get($alias); - $this->assertInstanceOf($expectedInstance, $service, 'get() return type not match'); + self::assertInstanceOf($expectedInstance, $service, 'get() return type not match'); } public function testInputFilterInvokableClassSMDependenciesArePopulatedWithoutServiceLocator(): void @@ -98,7 +98,7 @@ public function testInputFilterInvokableClassSMDependenciesArePopulatedWithoutSe $service = $this->manager->get('inputfilter'); $factory = $service->getFactory(); - $this->assertSame( + self::assertSame( $this->manager, $factory->getInputFilterManager(), 'Factory::getInputFilterManager() is not populated with the expected plugin manager' @@ -107,12 +107,8 @@ public function testInputFilterInvokableClassSMDependenciesArePopulatedWithoutSe public function testInputFilterInvokableClassSMDependenciesArePopulatedWithServiceLocator(): void { - $filterManager = $this->getMockBuilder(FilterPluginManager::class) - ->disableOriginalConstructor() - ->getMock(); - $validatorManager = $this->getMockBuilder(ValidatorPluginManager::class) - ->disableOriginalConstructor() - ->getMock(); + $filterManager = $this->createMock(FilterPluginManager::class); + $validatorManager = $this->createMock(ValidatorPluginManager::class); $this->services->setService(FilterPluginManager::class, $filterManager); $this->services->setService(ValidatorPluginManager::class, $validatorManager); @@ -121,21 +117,23 @@ public function testInputFilterInvokableClassSMDependenciesArePopulatedWithServi $service = $this->manager->get('inputfilter'); $factory = $service->getFactory(); - $this->assertSame( + self::assertSame( $this->manager, $factory->getInputFilterManager(), 'Factory::getInputFilterManager() is not populated with the expected plugin manager' ); $defaultFilterChain = $factory->getDefaultFilterChain(); - $this->assertSame( + self::assertInstanceOf(FilterChain::class, $defaultFilterChain); + self::assertSame( $filterManager, $defaultFilterChain->getPluginManager(), 'Factory::getDefaultFilterChain() is not populated with the expected plugin manager' ); $defaultValidatorChain = $factory->getDefaultValidatorChain(); - $this->assertSame( + self::assertInstanceOf(ValidatorChain::class, $defaultValidatorChain); + self::assertSame( $validatorManager, $defaultValidatorChain->getPluginManager(), 'Factory::getDefaultValidatorChain() is not populated with the expected plugin manager' @@ -171,7 +169,7 @@ public function testGet(string $serviceName, object $service): void { $this->manager->setService($serviceName, $service); - $this->assertSame($service, $this->manager->get($serviceName), 'get() value not match'); + self::assertSame($service, $this->manager->get($serviceName), 'get() value not match'); } public function testServicesAreInitiatedIfImplementsInitializableInterface(): void @@ -180,7 +178,7 @@ public function testServicesAreInitiatedIfImplementsInitializableInterface(): vo // Init is called twice. Once during `setService` and once during `get` $mock->expects(self::exactly(2))->method('init'); $this->manager->setService('PluginName', $mock); - $this->assertSame($mock, $this->manager->get('PluginName'), 'get() value not match'); + self::assertSame($mock, $this->manager->get('PluginName'), 'get() value not match'); } public function testPopulateFactoryCanAcceptInputFilterAsFirstArgumentAndWillUseFactoryWhenItDoes(): void @@ -188,7 +186,7 @@ public function testPopulateFactoryCanAcceptInputFilterAsFirstArgumentAndWillUse $inputFilter = new InputFilter(); $this->manager->populateFactory($inputFilter); - $this->assertSame($this->manager, $inputFilter->getFactory()->getInputFilterManager()); + self::assertSame($this->manager, $inputFilter->getFactory()->getInputFilterManager()); } /** @@ -224,6 +222,7 @@ protected function createServiceLocatorInterfaceMock() return $serviceLocator; } + /** @return class-string */ protected function getServiceNotFoundException(): string { if (method_exists($this->manager, 'configure')) { diff --git a/test/InputFilterTest.php b/test/InputFilterTest.php index 37178f57..39470486 100644 --- a/test/InputFilterTest.php +++ b/test/InputFilterTest.php @@ -29,14 +29,14 @@ protected function setUp(): void public function testLazilyComposesAFactoryByDefault(): void { $factory = $this->inputFilter->getFactory(); - $this->assertInstanceOf(Factory::class, $factory); + self::assertInstanceOf(Factory::class, $factory); } public function testCanComposeAFactory(): void { $factory = $this->createFactoryMock(); $this->inputFilter->setFactory($factory); - $this->assertSame($factory, $this->inputFilter->getFactory()); + self::assertSame($factory, $this->inputFilter->getFactory()); } /** @@ -99,12 +99,14 @@ public function testNestedInputFilterShouldAllowNullValueForData(): void ], ], 'nested'); + $expect = ['nested' => ['nestedField1' => null]]; + // Empty set of data $filter1->setData([]); - self::assertNull($filter1->getValues()['nested']['nestedField1']); + self::assertEquals($expect, $filter1->getValues()); // null provided for nested filter $filter1->setData(['nested' => null]); - self::assertNull($filter1->getValues()['nested']['nestedField1']); + self::assertEquals($expect, $filter1->getValues()); } } diff --git a/test/InputTest.php b/test/InputTest.php index 0df8ec9d..cecdce67 100644 --- a/test/InputTest.php +++ b/test/InputTest.php @@ -69,70 +69,70 @@ public function assertRequiredValidationErrorMessage(Input $input, string $messa public function testConstructorRequiresAName(): void { - $this->assertEquals('foo', $this->input->getName()); + self::assertEquals('foo', $this->input->getName()); } public function testInputHasEmptyFilterChainByDefault(): void { $filters = $this->input->getFilterChain(); - $this->assertInstanceOf(FilterChain::class, $filters); - $this->assertEquals(0, count($filters)); + self::assertInstanceOf(FilterChain::class, $filters); + self::assertCount(0, $filters); } public function testInputHasEmptyValidatorChainByDefault(): void { $validators = $this->input->getValidatorChain(); - $this->assertInstanceOf(ValidatorChain::class, $validators); - $this->assertEquals(0, count($validators)); + self::assertInstanceOf(ValidatorChain::class, $validators); + self::assertCount(0, $validators); } public function testCanInjectFilterChain(): void { $chain = $this->createFilterChainMock(); $this->input->setFilterChain($chain); - $this->assertSame($chain, $this->input->getFilterChain()); + self::assertSame($chain, $this->input->getFilterChain()); } public function testCanInjectValidatorChain(): void { $chain = $this->createValidatorChainMock(); $this->input->setValidatorChain($chain); - $this->assertSame($chain, $this->input->getValidatorChain()); + self::assertSame($chain, $this->input->getValidatorChain()); } public function testInputIsMarkedAsRequiredByDefault(): void { - $this->assertTrue($this->input->isRequired()); + self::assertTrue($this->input->isRequired()); } public function testRequiredFlagIsMutable(): void { $this->input->setRequired(false); - $this->assertFalse($this->input->isRequired()); + self::assertFalse($this->input->isRequired()); } public function testInputDoesNotAllowEmptyValuesByDefault(): void { - $this->assertFalse($this->input->allowEmpty()); + self::assertFalse($this->input->allowEmpty()); } public function testAllowEmptyFlagIsMutable(): void { $this->input->setAllowEmpty(true); - $this->assertTrue($this->input->allowEmpty()); + self::assertTrue($this->input->allowEmpty()); } public function testContinueIfEmptyFlagIsFalseByDefault(): void { $input = $this->input; - $this->assertFalse($input->continueIfEmpty()); + self::assertFalse($input->continueIfEmpty()); } public function testContinueIfEmptyFlagIsMutable(): void { $input = $this->input; $input->setContinueIfEmpty(true); - $this->assertTrue($input->continueIfEmpty()); + self::assertTrue($input->continueIfEmpty()); } /** @@ -144,10 +144,10 @@ public function testSetFallbackValue($fallbackValue): void $input = $this->input; $return = $input->setFallbackValue($fallbackValue); - $this->assertSame($input, $return, 'setFallbackValue() must return it self'); + self::assertSame($input, $return, 'setFallbackValue() must return it self'); - $this->assertEquals($fallbackValue, $input->getFallbackValue(), 'getFallbackValue() value not match'); - $this->assertTrue($input->hasFallback(), 'hasFallback() value not match'); + self::assertEquals($fallbackValue, $input->getFallbackValue(), 'getFallbackValue() value not match'); + self::assertTrue($input->hasFallback(), 'hasFallback() value not match'); } /** @@ -159,8 +159,8 @@ public function testClearFallbackValue($fallbackValue): void $input = $this->input; $input->setFallbackValue($fallbackValue); $input->clearFallbackValue(); - $this->assertNull($input->getFallbackValue(), 'getFallbackValue() value not match'); - $this->assertFalse($input->hasFallback(), 'hasFallback() value not match'); + self::assertNull($input->getFallbackValue(), 'getFallbackValue() value not match'); + self::assertFalse($input->hasFallback(), 'hasFallback() value not match'); } /** @@ -184,14 +184,14 @@ public function testFallbackValueVsIsValidRules( $input->setFallbackValue($fallbackValue); $input->setValue($originalValue); - $this->assertTrue( + self::assertTrue( $input->isValid(), 'isValid() should be return always true when fallback value is set. Detail: ' . json_encode($input->getMessages(), JSON_THROW_ON_ERROR) ); - $this->assertEquals([], $input->getMessages(), 'getMessages() should be empty because the input is valid'); - $this->assertSame($expectedValue, $input->getRawValue(), 'getRawValue() value not match'); - $this->assertSame($expectedValue, $input->getValue(), 'getValue() value not match'); + self::assertEquals([], $input->getMessages(), 'getMessages() should be empty because the input is valid'); + self::assertSame($expectedValue, $input->getRawValue(), 'getRawValue() value not match'); + self::assertSame($expectedValue, $input->getValue(), 'getValue() value not match'); } /** @@ -209,14 +209,14 @@ public function testFallbackValueVsIsValidRulesWhenValueNotSet(bool $required, $ $input->setValidatorChain($this->createValidatorChainMock()); $input->setFallbackValue($fallbackValue); - $this->assertTrue( + self::assertTrue( $input->isValid(), 'isValid() should be return always true when fallback value is set. Detail: ' . json_encode($input->getMessages(), JSON_THROW_ON_ERROR) ); - $this->assertEquals([], $input->getMessages(), 'getMessages() should be empty because the input is valid'); - $this->assertSame($expectedValue, $input->getRawValue(), 'getRawValue() value not match'); - $this->assertSame($expectedValue, $input->getValue(), 'getValue() value not match'); + self::assertEquals([], $input->getMessages(), 'getMessages() should be empty because the input is valid'); + self::assertSame($expectedValue, $input->getRawValue(), 'getRawValue() value not match'); + self::assertSame($expectedValue, $input->getValue(), 'getValue() value not match'); } public function testRequiredWithoutFallbackAndValueNotSetThenFail(): void @@ -224,7 +224,7 @@ public function testRequiredWithoutFallbackAndValueNotSetThenFail(): void $input = $this->input; $input->setRequired(true); - $this->assertFalse( + self::assertFalse( $input->isValid(), 'isValid() should be return always false when no fallback value, is required, and not data is set.' ); @@ -237,11 +237,11 @@ public function testRequiredWithoutFallbackAndValueNotSetThenFailReturnsCustomEr $input->setRequired(true); $input->setErrorMessage('FAILED TO VALIDATE'); - $this->assertFalse( + self::assertFalse( $input->isValid(), 'isValid() should be return always false when no fallback value, is required, and not data is set.' ); - $this->assertSame(['FAILED TO VALIDATE'], $input->getMessages()); + self::assertSame(['FAILED TO VALIDATE'], $input->getMessages()); } public function testRequiredWithoutFallbackAndValueNotSetProvidesNotEmptyValidatorIsEmptyErrorMessage(): void @@ -249,7 +249,7 @@ public function testRequiredWithoutFallbackAndValueNotSetProvidesNotEmptyValidat $input = $this->input; $input->setRequired(true); - $this->assertFalse( + self::assertFalse( $input->isValid(), 'isValid() should always return false when no fallback value is present, ' . 'the input is required, and no data is set.' @@ -266,11 +266,8 @@ public function testRequiredWithoutFallbackAndValueNotSetProvidesAttachedNotEmpt NotEmptyValidator::IS_EMPTY => "Custom message", ]; - $notEmpty = $this->getMockBuilder(NotEmptyValidator::class) - ->setMethods(['getOption']) - ->getMock(); - - $notEmpty->expects($this->once()) + $notEmpty = $this->createMock(NotEmptyValidator::class); + $notEmpty->expects(self::once()) ->method('getOption') ->with('messageTemplates') ->willReturn($customMessage); @@ -278,12 +275,12 @@ public function testRequiredWithoutFallbackAndValueNotSetProvidesAttachedNotEmpt $input->getValidatorChain() ->attach($notEmpty); - $this->assertFalse( + self::assertFalse( $input->isValid(), 'isValid() should always return false when no fallback value is present, ' . 'the input is required, and no data is set.' ); - $this->assertEquals($customMessage, $input->getMessages()); + self::assertEquals($customMessage, $input->getMessages()); } public function testRequiredWithoutFallbackAndValueNotSetProvidesCustomErrorMessageWhenSet(): void @@ -292,12 +289,12 @@ public function testRequiredWithoutFallbackAndValueNotSetProvidesCustomErrorMess $input->setRequired(true); $input->setErrorMessage('FAILED TO VALIDATE'); - $this->assertFalse( + self::assertFalse( $input->isValid(), 'isValid() should always return false when no fallback value is present, ' . 'the input is required, and no data is set.' ); - $this->assertSame(['FAILED TO VALIDATE'], $input->getMessages()); + self::assertSame(['FAILED TO VALIDATE'], $input->getMessages()); } public function testNotRequiredWithoutFallbackAndValueNotSetThenIsValid(): void @@ -310,12 +307,12 @@ public function testNotRequiredWithoutFallbackAndValueNotSetThenIsValid(): void // Validator should not to be called $input->getValidatorChain() ->attach($this->createValidatorMock(null, null)); - $this->assertTrue( + self::assertTrue( $input->isValid(), 'isValid() should be return always true when is not required, and no data is set. Detail: ' . json_encode($input->getMessages(), JSON_THROW_ON_ERROR) ); - $this->assertEquals([], $input->getMessages(), 'getMessages() should be empty because the input is valid'); + self::assertEquals([], $input->getMessages(), 'getMessages() should be empty because the input is valid'); } /** @@ -330,12 +327,12 @@ public function testNotEmptyValidatorNotInjectedIfContinueIfEmptyIsTrue($value): $input->isValid(); $validators = $input->getValidatorChain() ->getValidators(); - $this->assertEmpty($validators); + self::assertEmpty($validators); } public function testDefaultGetValue(): void { - $this->assertNull($this->input->getValue()); + self::assertNull($this->input->getValue()); } public function testValueMayBeInjected(): void @@ -343,7 +340,7 @@ public function testValueMayBeInjected(): void $valueRaw = $this->getDummyValue(); $this->input->setValue($valueRaw); - $this->assertEquals($valueRaw, $this->input->getValue()); + self::assertEquals($valueRaw, $this->input->getValue()); } public function testRetrievingValueFiltersTheValue(): void @@ -356,7 +353,7 @@ public function testRetrievingValueFiltersTheValue(): void $this->input->setFilterChain($filterChain); $this->input->setValue($valueRaw); - $this->assertSame($valueFiltered, $this->input->getValue()); + self::assertSame($valueFiltered, $this->input->getValue()); } public function testCanRetrieveRawValue(): void @@ -368,7 +365,7 @@ public function testCanRetrieveRawValue(): void $this->input->setFilterChain($filterChain); $this->input->setValue($valueRaw); - $this->assertEquals($valueRaw, $this->input->getRawValue()); + self::assertEquals($valueRaw, $this->input->getRawValue()); } public function testValidationOperatesOnFilteredValue(): void @@ -385,7 +382,7 @@ public function testValidationOperatesOnFilteredValue(): void $this->input->setValidatorChain($validatorChain); $this->input->setValue($valueRaw); - $this->assertTrue( + self::assertTrue( $this->input->isValid(), 'isValid() value not match. Detail . ' . json_encode($this->input->getMessages(), JSON_THROW_ON_ERROR) ); @@ -393,13 +390,13 @@ public function testValidationOperatesOnFilteredValue(): void public function testBreakOnFailureFlagIsOffByDefault(): void { - $this->assertFalse($this->input->breakOnFailure()); + self::assertFalse($this->input->breakOnFailure()); } public function testBreakOnFailureFlagIsMutable(): void { $this->input->setBreakOnFailure(true); - $this->assertTrue($this->input->breakOnFailure()); + self::assertTrue($this->input->breakOnFailure()); } /** @@ -408,19 +405,19 @@ public function testBreakOnFailureFlagIsMutable(): void */ public function testNotEmptyValidatorAddedWhenIsValidIsCalled($value): void { - $this->assertTrue($this->input->isRequired()); + self::assertTrue($this->input->isRequired()); $this->input->setValue($value); $validatorChain = $this->input->getValidatorChain(); - $this->assertEquals(0, count($validatorChain->getValidators())); + self::assertEquals(0, count($validatorChain->getValidators())); - $this->assertFalse($this->input->isValid()); + self::assertFalse($this->input->isValid()); $messages = $this->input->getMessages(); - $this->assertArrayHasKey('isEmpty', $messages); - $this->assertEquals(1, count($validatorChain->getValidators())); + self::assertArrayHasKey('isEmpty', $messages); + self::assertEquals(1, count($validatorChain->getValidators())); // Assert that NotEmpty validator wasn't added again - $this->assertFalse($this->input->isValid()); - $this->assertEquals(1, count($validatorChain->getValidators())); + self::assertFalse($this->input->isValid()); + self::assertEquals(1, count($validatorChain->getValidators())); } /** @@ -436,11 +433,11 @@ public function testRequiredNotEmptyValidatorNotAddedWhenOneExists($value): void $validatorChain = $this->input->getValidatorChain(); $validatorChain->prependValidator($notEmptyMock); - $this->assertFalse($this->input->isValid()); + self::assertFalse($this->input->isValid()); $validators = $validatorChain->getValidators(); - $this->assertEquals(1, count($validators)); - $this->assertEquals($notEmptyMock, $validators[0]['instance']); + self::assertEquals(1, count($validators)); + self::assertEquals($notEmptyMock, $validators[0]['instance']); } /** @@ -462,11 +459,11 @@ public function testDoNotInjectNotEmptyValidatorIfAnywhereInChain($valueRaw, $va $validatorChain->attach($this->createValidatorMock(true)); $validatorChain->attach($notEmptyMock); - $this->assertFalse($this->input->isValid()); + self::assertFalse($this->input->isValid()); $validators = $validatorChain->getValidators(); - $this->assertEquals(2, count($validators)); - $this->assertEquals($notEmptyMock, $validators[1]['instance']); + self::assertEquals(2, count($validators)); + self::assertEquals($notEmptyMock, $validators[1]['instance']); } /** @@ -490,14 +487,14 @@ public function testIsRequiredVsAllowEmptyVsContinueIfEmptyVsIsValid( ->attach($validator); $this->input->setValue($value); - $this->assertEquals( + self::assertEquals( $expectedIsValid, $this->input->isValid(), 'isValid() value not match. Detail: ' . json_encode($this->input->getMessages(), JSON_THROW_ON_ERROR) ); - $this->assertEquals($expectedMessages, $this->input->getMessages(), 'getMessages() value not match'); - $this->assertEquals($value, $this->input->getRawValue(), 'getRawValue() must return the value always'); - $this->assertEquals($value, $this->input->getValue(), 'getValue() must return the filtered value always'); + self::assertEquals($expectedMessages, $this->input->getMessages(), 'getMessages() value not match'); + self::assertEquals($value, $this->input->getRawValue(), 'getRawValue() must return the value always'); + self::assertEquals($value, $this->input->getValue(), 'getValue() must return the filtered value always'); } /** @@ -507,10 +504,10 @@ public function testIsRequiredVsAllowEmptyVsContinueIfEmptyVsIsValid( public function testSetValuePutInputInTheDesiredState($value): void { $input = $this->input; - $this->assertFalse($input->hasValue(), 'Input should not have value by default'); + self::assertFalse($input->hasValue(), 'Input should not have value by default'); $input->setValue($value); - $this->assertTrue($input->hasValue(), "hasValue() didn't return true when value was set"); + self::assertTrue($input->hasValue(), "hasValue() didn't return true when value was set"); } /** @@ -521,14 +518,14 @@ public function testResetValueReturnsInputValueToDefaultValue($value): void { $input = $this->input; $originalInput = clone $input; - $this->assertFalse($input->hasValue(), 'Input should not have value by default'); + self::assertFalse($input->hasValue(), 'Input should not have value by default'); $input->setValue($value); - $this->assertTrue($input->hasValue(), "hasValue() didn't return true when value was set"); + self::assertTrue($input->hasValue(), "hasValue() didn't return true when value was set"); $return = $input->resetValue(); - $this->assertSame($input, $return, 'resetValue() must return itself'); - $this->assertEquals($originalInput, $input, 'Input was not reset to the default value state'); + self::assertSame($input, $return, 'resetValue() must return itself'); + self::assertEquals($originalInput, $input, 'Input was not reset to the default value state'); } public function testMerge(): void @@ -563,14 +560,14 @@ public function testMerge(): void $target->setValidatorChain($targetValidatorChain); $return = $target->merge($source); - $this->assertSame($target, $return, 'merge() must return it self'); + self::assertSame($target, $return, 'merge() must return it self'); - $this->assertEquals('bazInput', $target->getName(), 'getName() value not match'); - $this->assertEquals('bazErrorMessage', $target->getErrorMessage(), 'getErrorMessage() value not match'); - $this->assertTrue($target->breakOnFailure(), 'breakOnFailure() value not match'); - $this->assertTrue($target->isRequired(), 'isRequired() value not match'); - $this->assertEquals($sourceRawValue, $target->getRawValue(), 'getRawValue() value not match'); - $this->assertTrue($target->hasValue(), 'hasValue() value not match'); + self::assertEquals('bazInput', $target->getName(), 'getName() value not match'); + self::assertEquals('bazErrorMessage', $target->getErrorMessage(), 'getErrorMessage() value not match'); + self::assertTrue($target->breakOnFailure(), 'breakOnFailure() value not match'); + self::assertTrue($target->isRequired(), 'isRequired() value not match'); + self::assertEquals($sourceRawValue, $target->getRawValue(), 'getRawValue() value not match'); + self::assertTrue($target->hasValue(), 'hasValue() value not match'); } /** @@ -580,17 +577,17 @@ public function testInputMergeWithoutValues(): void { $source = new Input(); $source->setContinueIfEmpty(true); - $this->assertFalse($source->hasValue(), 'Source should not have a value'); + self::assertFalse($source->hasValue(), 'Source should not have a value'); $target = $this->input; $target->setContinueIfEmpty(false); - $this->assertFalse($target->hasValue(), 'Target should not have a value'); + self::assertFalse($target->hasValue(), 'Target should not have a value'); $return = $target->merge($source); - $this->assertSame($target, $return, 'merge() must return it self'); + self::assertSame($target, $return, 'merge() must return it self'); - $this->assertTrue($target->continueIfEmpty(), 'continueIfEmpty() value not match'); - $this->assertFalse($target->hasValue(), 'hasValue() value not match'); + self::assertTrue($target->continueIfEmpty(), 'continueIfEmpty() value not match'); + self::assertFalse($target->hasValue(), 'hasValue() value not match'); } /** @@ -604,14 +601,14 @@ public function testInputMergeWithSourceValue(): void $target = $this->input; $target->setContinueIfEmpty(false); - $this->assertFalse($target->hasValue(), 'Target should not have a value'); + self::assertFalse($target->hasValue(), 'Target should not have a value'); $return = $target->merge($source); - $this->assertSame($target, $return, 'merge() must return it self'); + self::assertSame($target, $return, 'merge() must return it self'); - $this->assertTrue($target->continueIfEmpty(), 'continueIfEmpty() value not match'); - $this->assertEquals(['foo'], $target->getRawValue(), 'getRawValue() value not match'); - $this->assertTrue($target->hasValue(), 'hasValue() value not match'); + self::assertTrue($target->continueIfEmpty(), 'continueIfEmpty() value not match'); + self::assertEquals(['foo'], $target->getRawValue(), 'getRawValue() value not match'); + self::assertTrue($target->hasValue(), 'hasValue() value not match'); } /** @@ -621,18 +618,18 @@ public function testInputMergeWithTargetValue(): void { $source = new Input(); $source->setContinueIfEmpty(true); - $this->assertFalse($source->hasValue(), 'Source should not have a value'); + self::assertFalse($source->hasValue(), 'Source should not have a value'); $target = $this->input; $target->setContinueIfEmpty(false); $target->setValue(['foo']); $return = $target->merge($source); - $this->assertSame($target, $return, 'merge() must return it self'); + self::assertSame($target, $return, 'merge() must return it self'); - $this->assertTrue($target->continueIfEmpty(), 'continueIfEmpty() value not match'); - $this->assertEquals(['foo'], $target->getRawValue(), 'getRawValue() value not match'); - $this->assertTrue($target->hasValue(), 'hasValue() value not match'); + self::assertTrue($target->continueIfEmpty(), 'continueIfEmpty() value not match'); + self::assertEquals(['foo'], $target->getRawValue(), 'getRawValue() value not match'); + self::assertTrue($target->hasValue(), 'hasValue() value not match'); } public function testNotEmptyMessageIsTranslated(): void @@ -643,15 +640,15 @@ public function testNotEmptyMessageIsTranslated(): void $notEmpty = new NotEmptyValidator(); $translatedMessage = 'some translation'; - $translator->expects($this->atLeastOnce()) + $translator->expects(self::atLeastOnce()) ->method('translate') ->with($notEmpty->getMessageTemplates()[NotEmptyValidator::IS_EMPTY]) ->willReturn($translatedMessage); - $this->assertFalse($this->input->isValid()); + self::assertFalse($this->input->isValid()); $messages = $this->input->getMessages(); - $this->assertArrayHasKey('isEmpty', $messages); - $this->assertSame($translatedMessage, $messages['isEmpty']); + self::assertArrayHasKey('isEmpty', $messages); + self::assertSame($translatedMessage, $messages['isEmpty']); } /** @@ -821,8 +818,8 @@ public function emptyValueProvider(): iterable /** * @psalm-return array|object, - * filtered: bool|int|float|string|list|object + * raw: mixed, + * filtered: mixed, * }> */ public function mixedValueProvider(): array @@ -917,10 +914,10 @@ protected function createValidatorChainMock(array $valueMap = [], $messages = [] $validatorChain = $this->createMock(ValidatorChain::class); if (empty($valueMap)) { - $validatorChain->expects($this->never()) + $validatorChain->expects(self::never()) ->method('isValid'); } else { - $validatorChain->expects($this->atLeastOnce()) + $validatorChain->expects(self::atLeastOnce()) ->method('isValid') ->willReturnMap($valueMap); } @@ -944,11 +941,11 @@ protected function createValidatorMock($isValid, $value = 'not-set', $context = $validator = $this->createMock(ValidatorInterface::class); if (($isValid === false) || ($isValid === true)) { - $isValidMethod = $validator->expects($this->once()) + $isValidMethod = $validator->expects(self::once()) ->method('isValid') ->willReturn($isValid); } else { - $isValidMethod = $validator->expects($this->never()) + $isValidMethod = $validator->expects(self::never()) ->method('isValid'); } if ($value !== 'not-set') { diff --git a/test/ModuleTest.php b/test/ModuleTest.php index a5258385..8a1d328b 100644 --- a/test/ModuleTest.php +++ b/test/ModuleTest.php @@ -24,19 +24,19 @@ public function testGetConfigMethodShouldReturnExpectedKeys(): void $config = $this->module->getConfig(); // Service manager - $this->assertArrayHasKey('service_manager', $config); + self::assertArrayHasKey('service_manager', $config); // Input filters - $this->assertArrayHasKey('input_filters', $config); + self::assertArrayHasKey('input_filters', $config); } public function testServiceManagerConfigShouldContainInputFilterManager(): void { $config = $this->module->getConfig(); - $this->assertArrayHasKey( + self::assertArrayHasKey( InputFilterPluginManager::class, - $config['service_manager']['factories'] + $config['service_manager']['factories'] ?? [] ); } @@ -44,9 +44,9 @@ public function testServiceManagerConfigShouldContainAliasForInputFilterManager( { $config = $this->module->getConfig(); - $this->assertArrayHasKey( + self::assertArrayHasKey( 'InputFilterManager', - $config['service_manager']['aliases'] + $config['service_manager']['aliases'] ?? [] ); } @@ -54,9 +54,9 @@ public function testInputFilterConfigShouldContainAbstractServiceFactory(): void { $config = $this->module->getConfig(); - $this->assertContains( + self::assertContains( InputFilterAbstractServiceFactory::class, - $config['input_filters']['abstract_factories'] + $config['input_filters']['abstract_factories'] ?? [] ); } @@ -93,6 +93,7 @@ public function testInitMethodShouldRegisterPluginManagerSpecificationWithServic ->method('getEvent') ->willReturn($event); + /** @psalm-suppress InvalidArgument Prevents dev dependency on the Module manager component */ $this->module->init($moduleManager); } } diff --git a/test/OptionalInputFilterTest.php b/test/OptionalInputFilterTest.php index d26a25ac..16d3d2c3 100644 --- a/test/OptionalInputFilterTest.php +++ b/test/OptionalInputFilterTest.php @@ -19,7 +19,7 @@ class OptionalInputFilterTest extends TestCase { public function testValidatesSuccessfullyWhenSetDataIsNeverCalled(): void { - $this->assertTrue($this->getNestedCarInputFilter()->get('car')->isValid()); + self::assertTrue($this->getNestedCarInputFilter()->get('car')->isValid()); } public function testValidatesSuccessfullyWhenValidNonEmptyDataSetProvided(): void @@ -34,8 +34,8 @@ public function testValidatesSuccessfullyWhenValidNonEmptyDataSetProvided(): voi $inputFilter = $this->getNestedCarInputFilter(); $inputFilter->setData($data); - $this->assertTrue($inputFilter->isValid()); - $this->assertEquals($data, $inputFilter->getValues()); + self::assertTrue($inputFilter->isValid()); + self::assertEquals($data, $inputFilter->getValues()); } public function testValidatesSuccessfullyWhenEmptyDataSetProvided(): void @@ -47,8 +47,8 @@ public function testValidatesSuccessfullyWhenEmptyDataSetProvided(): void $inputFilter = $this->getNestedCarInputFilter(); $inputFilter->setData($data); - $this->assertTrue($inputFilter->isValid()); - $this->assertEquals($data, $inputFilter->getValues()); + self::assertTrue($inputFilter->isValid()); + self::assertEquals($data, $inputFilter->getValues()); } public function testValidatesSuccessfullyWhenNoDataProvided(): void @@ -58,8 +58,8 @@ public function testValidatesSuccessfullyWhenNoDataProvided(): void $inputFilter = $this->getNestedCarInputFilter(); $inputFilter->setData($data); - $this->assertTrue($inputFilter->isValid()); - $this->assertEquals(['car' => null], $inputFilter->getValues()); + self::assertTrue($inputFilter->isValid()); + self::assertEquals(['car' => null], $inputFilter->getValues()); } public function testValidationFailureWhenInvalidDataSetIsProvided(): void @@ -71,7 +71,7 @@ public function testValidationFailureWhenInvalidDataSetIsProvided(): void ], ]); - $this->assertFalse($inputFilter->isValid()); + self::assertFalse($inputFilter->isValid()); $this->assertGetValuesThrows($inputFilter); } @@ -84,8 +84,8 @@ public function testStateIsClearedBetweenValidationAttempts(): void $inputFilter = $this->getNestedCarInputFilter(); $inputFilter->setData($data); - $this->assertTrue($inputFilter->isValid()); - $this->assertEquals($data, $inputFilter->getValues()); + self::assertTrue($inputFilter->isValid()); + self::assertEquals($data, $inputFilter->getValues()); } /** @@ -98,23 +98,23 @@ public function testIteratorBehavesTheSameAsArray(): void $optionalInputFilter->add(new Input('brand')); $optionalInputFilter->setData(['model' => 'Golf']); - $this->assertFalse($optionalInputFilter->isValid()); + self::assertFalse($optionalInputFilter->isValid()); $optionalInputFilter->setData(new ArrayIterator([])); - $this->assertTrue($optionalInputFilter->isValid()); + self::assertTrue($optionalInputFilter->isValid()); $optionalInputFilter->setData([]); - $this->assertTrue($optionalInputFilter->isValid()); + self::assertTrue($optionalInputFilter->isValid()); } protected function assertGetValuesThrows(InputFilterInterface $inputFilter): void { try { $inputFilter->getValues(); - $this->assertTrue(false); + self::fail('No exception was thrown'); // TODO: issue #143 narrow which exception should be thrown } catch (Exception $exception) { - $this->assertTrue(true); + self::assertTrue(true); } } diff --git a/test/TestAsset/FooAbstractFactory.php b/test/TestAsset/FooAbstractFactory.php index 7ae5039a..c17f6370 100644 --- a/test/TestAsset/FooAbstractFactory.php +++ b/test/TestAsset/FooAbstractFactory.php @@ -1,32 +1,27 @@ -canCreate($container, $requestedName ?: $name); - } - public function createServiceWithName(ServiceLocatorInterface $container, $name, $requestedName) - { - return $this($container, $requestedName ?: $name); + return false; } }