diff --git a/src/Generator/Resolver/ParameterResolverInterface.php b/src/Generator/Resolver/ParameterResolverInterface.php index 100836b1..10182d1e 100644 --- a/src/Generator/Resolver/ParameterResolverInterface.php +++ b/src/Generator/Resolver/ParameterResolverInterface.php @@ -18,7 +18,7 @@ use Nelmio\Alice\Throwable\ResolutionThrowable; /** - * More specific version of {@see \Nelmio\Alice\Generator\Resolver\ParameterBagResolverInterface} to resolve a specific + * More specific version of {@see ParameterBagResolverInterface} to resolve a specific * parameter. */ interface ParameterResolverInterface diff --git a/src/Loader/NativeLoader.php b/src/Loader/NativeLoader.php index ff7a424d..e5c00417 100644 --- a/src/Loader/NativeLoader.php +++ b/src/Loader/NativeLoader.php @@ -170,7 +170,7 @@ /** * Loader implementation made to be usable without any dependency injection for quick and easy usage. For more advanced - * usages, use {@see \Nelmio\Alice\Loader\SimpleFileLoader} instead or implement your own loader. + * usages, use {@see SimpleFileLoader} instead or implement your own loader. * * WARNING: because this class is wrapping the whole configuration, the BC break policy is not fully ensured here. Not * methods can be added in minor versions, which could make your application break if you are extending this class and diff --git a/tests/DeepCloneTest.php b/tests/DeepCloneTest.php index bd277a86..ca4630aa 100644 --- a/tests/DeepCloneTest.php +++ b/tests/DeepCloneTest.php @@ -103,7 +103,7 @@ public function testDeepCloneClosure(): void self::assertSame($bar, $fooClone->bar); } - public function provideScalarValues(): iterable + public static function provideScalarValues(): iterable { return [ [null], diff --git a/tests/Definition/Fixture/TemplatingTest.php b/tests/Definition/Fixture/TemplatingTest.php index 0bb955e1..4a8bfc8f 100644 --- a/tests/Definition/Fixture/TemplatingTest.php +++ b/tests/Definition/Fixture/TemplatingTest.php @@ -56,7 +56,7 @@ public function testDetectTemplateFlags(SimpleFixtureWithFlags $fixture, bool $i public function testExtendedFixturesOrderIsInversed(): void { $templating = new Templating( - $this->createFixtureWithFlags( + self::createFixtureWithFlags( (new FlagBag('')) ->withFlag(new ExtendFlag(new FixtureReference('user_base0'))) ->withFlag(new ExtendFlag(new FixtureReference('user_base1'))), @@ -75,11 +75,11 @@ public function testExtendedFixturesOrderIsInversed(): void } } - public function provideFlags(): iterable + public static function provideFlags(): iterable { $emptyFlagBag = new FlagBag('user0'); yield 'empty flagbag' => [ - $this->createFixtureWithFlags($emptyFlagBag), + self::createFixtureWithFlags($emptyFlagBag), false, false, [], @@ -87,7 +87,7 @@ public function provideFlags(): iterable $flagBagWithNonTemplateFlag = $emptyFlagBag->withFlag(new DummyFlag()); yield 'flagbag with non-templating element' => [ - $this->createFixtureWithFlags($flagBagWithNonTemplateFlag), + self::createFixtureWithFlags($flagBagWithNonTemplateFlag), false, false, [], @@ -95,7 +95,7 @@ public function provideFlags(): iterable $templateFlagBag = $emptyFlagBag->withFlag(new TemplateFlag()); yield 'flagbag with template' => [ - $this->createFixtureWithFlags($templateFlagBag), + self::createFixtureWithFlags($templateFlagBag), true, false, [], @@ -105,7 +105,7 @@ public function provideFlags(): iterable ->withFlag(new ExtendFlag(new FixtureReference('user_base0'))) ->withFlag(new ExtendFlag(new FixtureReference('user_base1'))); yield 'flagbag with extends' => [ - $this->createFixtureWithFlags($extendsFlagBag), + self::createFixtureWithFlags($extendsFlagBag), false, true, [ @@ -120,7 +120,7 @@ public function provideFlags(): iterable ->withFlag(new ExtendFlag(new FixtureReference('user_base1'))) ->withFlag(new DummyFlag()); yield 'flagbag with template, extends and non templating flags' => [ - $this->createFixtureWithFlags($templateAndExtendsFlagBag), + self::createFixtureWithFlags($templateAndExtendsFlagBag), true, true, [ @@ -130,7 +130,7 @@ public function provideFlags(): iterable ]; } - private function createFixtureWithFlags(FlagBag $flags): SimpleFixtureWithFlags + private static function createFixtureWithFlags(FlagBag $flags): SimpleFixtureWithFlags { return new SimpleFixtureWithFlags( new SimpleFixture( diff --git a/tests/Definition/Flag/OptionalFlagTest.php b/tests/Definition/Flag/OptionalFlagTest.php index 0f908eff..1bbb63e1 100644 --- a/tests/Definition/Flag/OptionalFlagTest.php +++ b/tests/Definition/Flag/OptionalFlagTest.php @@ -55,7 +55,7 @@ public function testThrowsExceptionIfPercentageValueIsInvalid(int $percentage, ? } } - public function providePercentageValues(): iterable + public static function providePercentageValues(): iterable { yield 'negative value' => [ -1, diff --git a/tests/Definition/RangeNameTest.php b/tests/Definition/RangeNameTest.php index 41114b78..581c3eba 100644 --- a/tests/Definition/RangeNameTest.php +++ b/tests/Definition/RangeNameTest.php @@ -36,7 +36,7 @@ public function testReadAccessorsReturnPropertiesValues(array $input, array $exp self::assertEquals($expected[1], $range->getTo()); } - public function provideRanges(): iterable + public static function provideRanges(): iterable { yield [ [10, 11], diff --git a/tests/Definition/Value/DynamicArrayValueTest.php b/tests/Definition/Value/DynamicArrayValueTest.php index 33c67c28..5584bda8 100644 --- a/tests/Definition/Value/DynamicArrayValueTest.php +++ b/tests/Definition/Value/DynamicArrayValueTest.php @@ -96,7 +96,7 @@ public function testCanBeCastedIntoAString(): void self::assertEquals('10x foo', (string) $value); } - public function provideInputTypes(): iterable + public static function provideInputTypes(): iterable { yield 'null/array' => [ null, @@ -192,7 +192,7 @@ static function (): void { ]; } - public function provideValues(): iterable + public static function provideValues(): iterable { yield 'int value' => [-1, 'string', -1]; yield 'object value' => [new FakeValue(), new FakeValue(), new FakeValue()]; diff --git a/tests/Definition/Value/OptionalValueTest.php b/tests/Definition/Value/OptionalValueTest.php index 99315601..5ef75486 100644 --- a/tests/Definition/Value/OptionalValueTest.php +++ b/tests/Definition/Value/OptionalValueTest.php @@ -124,7 +124,7 @@ public function testCanBeCastedIntoAString(): void self::assertEquals('10%? foo : null', (string) $value); } - public function provideInputValues(): iterable + public static function provideInputValues(): iterable { yield 'null/string/string' => [ null, diff --git a/tests/Definition/Value/ParameterValueTest.php b/tests/Definition/Value/ParameterValueTest.php index 038628d0..979a971c 100644 --- a/tests/Definition/Value/ParameterValueTest.php +++ b/tests/Definition/Value/ParameterValueTest.php @@ -82,7 +82,7 @@ public function testCanBeCastedIntoAString(): void self::assertEquals('<{foo}>', $value); } - public function provideInputValues(): iterable + public static function provideInputValues(): iterable { yield 'null' => [ null, diff --git a/tests/Definition/Value/UniqueValueTest.php b/tests/Definition/Value/UniqueValueTest.php index 980a175a..09ad5dfc 100644 --- a/tests/Definition/Value/UniqueValueTest.php +++ b/tests/Definition/Value/UniqueValueTest.php @@ -106,7 +106,7 @@ public function testCanBeCastedIntoAString(): void self::assertEquals('(unique) foo', (string) $value); } - public function provideValues(): iterable + public static function provideValues(): iterable { yield 'null value' => [null]; yield 'string value' => ['azerty']; diff --git a/tests/FileLocator/DefaultFileLocatorTest.php b/tests/FileLocator/DefaultFileLocatorTest.php index 098a0777..f8151163 100644 --- a/tests/FileLocator/DefaultFileLocatorTest.php +++ b/tests/FileLocator/DefaultFileLocatorTest.php @@ -92,7 +92,7 @@ public function testLocatingFileThrowsExceptionIfTheFileDoesNotExistsInAbsoluteP $this->locator->locate(__DIR__.'/Fixtures/foobar.xml'); } - public function provideAbsolutePaths(): iterable + public static function provideAbsolutePaths(): iterable { return [ ['/foo.xml'], diff --git a/tests/FixtureBuilder/Denormalizer/FlagParser/FlagParserTestCase.php b/tests/FixtureBuilder/Denormalizer/FlagParser/FlagParserTestCase.php index 1671c28b..27629675 100644 --- a/tests/FixtureBuilder/Denormalizer/FlagParser/FlagParserTestCase.php +++ b/tests/FixtureBuilder/Denormalizer/FlagParser/FlagParserTestCase.php @@ -135,47 +135,47 @@ public function markAsInvalidCase(): void self::markTestSkipped('Invalid scenario.'); } - public function provideElements(): iterable + public static function provideElements(): iterable { return Reference::getElements(); } - public function provideMalformedElements(): iterable + public static function provideMalformedElements(): iterable { return Reference::getMalformedElements(); } - public function provideExtends(): iterable + public static function provideExtends(): iterable { return Reference::getExtends(); } - public function provideMalformedExtends(): iterable + public static function provideMalformedExtends(): iterable { return Reference::getMalformedExtends(); } - public function provideOptionals(): iterable + public static function provideOptionals(): iterable { return Reference::getOptionals(); } - public function provideMalformedOptionals(): iterable + public static function provideMalformedOptionals(): iterable { return Reference::getMalformedOptionals(); } - public function provideTemplates(): iterable + public static function provideTemplates(): iterable { return Reference::getTemplates(); } - public function provideUniques(): iterable + public static function provideUniques(): iterable { return Reference::getUniques(); } - public function provideConfigurators(): iterable + public static function provideConfigurators(): iterable { return Reference::getConfigurators(); } diff --git a/tests/FixtureBuilder/Denormalizer/Parameter/SimpleParameterBagDenormalizerTest.php b/tests/FixtureBuilder/Denormalizer/Parameter/SimpleParameterBagDenormalizerTest.php index 1d9ab7de..a1c7ad30 100644 --- a/tests/FixtureBuilder/Denormalizer/Parameter/SimpleParameterBagDenormalizerTest.php +++ b/tests/FixtureBuilder/Denormalizer/Parameter/SimpleParameterBagDenormalizerTest.php @@ -69,7 +69,7 @@ public function testThrowsExceptionIfParametersKeyIsNotAnArray(array $data, stri } } - public function provideDataWithNoParameters(): iterable + public static function provideDataWithNoParameters(): iterable { yield 'no parameters' => [ [], @@ -88,7 +88,7 @@ public function provideDataWithNoParameters(): iterable ]; } - public function provideDataWithInvalidParameterKeys(): iterable + public static function provideDataWithInvalidParameterKeys(): iterable { yield 'string value' => [ [ diff --git a/tests/FixtureBuilder/ExpressionLanguage/Lexer/FunctionTokenizerTest.php b/tests/FixtureBuilder/ExpressionLanguage/Lexer/FunctionTokenizerTest.php index 2f7833bf..704f7546 100644 --- a/tests/FixtureBuilder/ExpressionLanguage/Lexer/FunctionTokenizerTest.php +++ b/tests/FixtureBuilder/ExpressionLanguage/Lexer/FunctionTokenizerTest.php @@ -60,7 +60,7 @@ public function testTokenizeValues($value, $expected): void } } - public function provideValues(): iterable + public static function provideValues(): iterable { yield 'non function' => [ 'foo', diff --git a/tests/FixtureBuilder/ExpressionLanguage/Lexer/LexerIntegrationTest.php b/tests/FixtureBuilder/ExpressionLanguage/Lexer/LexerIntegrationTest.php index 36bbaefb..c2f39706 100644 --- a/tests/FixtureBuilder/ExpressionLanguage/Lexer/LexerIntegrationTest.php +++ b/tests/FixtureBuilder/ExpressionLanguage/Lexer/LexerIntegrationTest.php @@ -79,7 +79,7 @@ public function testCanLexValues(string $value, $expected): void /** * @see https://github.com/nelmio/alice/issues/377 */ - public function provideValues(): iterable + public static function provideValues(): iterable { // simple values yield 'empty string' => [ diff --git a/tests/FixtureBuilder/ExpressionLanguage/Lexer/ReferenceEscaperLexerTest.php b/tests/FixtureBuilder/ExpressionLanguage/Lexer/ReferenceEscaperLexerTest.php index fe78af98..10e682fd 100644 --- a/tests/FixtureBuilder/ExpressionLanguage/Lexer/ReferenceEscaperLexerTest.php +++ b/tests/FixtureBuilder/ExpressionLanguage/Lexer/ReferenceEscaperLexerTest.php @@ -60,7 +60,7 @@ public function testEscapesStringBeforeHandlingItOverToTheDecoratedLexer(string $decoratedLexerProphecy->lex(Argument::any())->shouldHaveBeenCalledTimes(1); } - public function provideValues(): iterable + public static function provideValues(): iterable { yield 'empty string' => ['']; diff --git a/tests/FixtureBuilder/ExpressionLanguage/Lexer/ReferenceLexerTest.php b/tests/FixtureBuilder/ExpressionLanguage/Lexer/ReferenceLexerTest.php index 7dbe2a0f..8fda57b1 100644 --- a/tests/FixtureBuilder/ExpressionLanguage/Lexer/ReferenceLexerTest.php +++ b/tests/FixtureBuilder/ExpressionLanguage/Lexer/ReferenceLexerTest.php @@ -83,7 +83,7 @@ public function testThrowsAnExceptionIfNoMatchingPatternFound(): void $this->lexer->lex('foo'); } - public function provideValues(): iterable + public static function provideValues(): iterable { yield 'method reference' => [ $value = '@user->getUserName()', diff --git a/tests/FixtureBuilder/ExpressionLanguage/Lexer/SubPatternsLexerTest.php b/tests/FixtureBuilder/ExpressionLanguage/Lexer/SubPatternsLexerTest.php index 0cef035c..4d393a0e 100644 --- a/tests/FixtureBuilder/ExpressionLanguage/Lexer/SubPatternsLexerTest.php +++ b/tests/FixtureBuilder/ExpressionLanguage/Lexer/SubPatternsLexerTest.php @@ -114,7 +114,7 @@ public function testThrowsAnExceptionWhenAnInvalidValueIsGiven(): void $lexer->lex(''); } - public function lineBreaksProvider(): iterable + public static function lineBreaksProvider(): iterable { return [ ['\n'], diff --git a/tests/FixtureBuilder/ExpressionLanguage/Parser/FunctionFixtureReferenceParserTest.php b/tests/FixtureBuilder/ExpressionLanguage/Parser/FunctionFixtureReferenceParserTest.php index cedfb07c..24f0620b 100644 --- a/tests/FixtureBuilder/ExpressionLanguage/Parser/FunctionFixtureReferenceParserTest.php +++ b/tests/FixtureBuilder/ExpressionLanguage/Parser/FunctionFixtureReferenceParserTest.php @@ -170,7 +170,7 @@ public function testIfThereIsOnlyOneElementThenReturnTheElementInsteadOfAValueLi self::assertEquals($expected, $actual); } - public function provideOneElementValues(): iterable + public static function provideOneElementValues(): iterable { yield 'one value' => [ new FakeValue(), diff --git a/tests/FixtureBuilder/ExpressionLanguage/Parser/ParserIntegrationTest.php b/tests/FixtureBuilder/ExpressionLanguage/Parser/ParserIntegrationTest.php index 940d9860..72d24103 100644 --- a/tests/FixtureBuilder/ExpressionLanguage/Parser/ParserIntegrationTest.php +++ b/tests/FixtureBuilder/ExpressionLanguage/Parser/ParserIntegrationTest.php @@ -87,7 +87,7 @@ public function testParseValues(string $value, $expected): void self::assertEquals($expected, $actual, var_export($actual, true)); } - public function provideValues(): iterable + public static function provideValues(): iterable { // Simple values yield 'empty string' => [ diff --git a/tests/FixtureBuilder/ExpressionLanguage/Parser/StringMergerParserTest.php b/tests/FixtureBuilder/ExpressionLanguage/Parser/StringMergerParserTest.php index 5ac5e34a..af94bf01 100644 --- a/tests/FixtureBuilder/ExpressionLanguage/Parser/StringMergerParserTest.php +++ b/tests/FixtureBuilder/ExpressionLanguage/Parser/StringMergerParserTest.php @@ -157,7 +157,7 @@ public function testIfThereIsOnlyOneElementThenReturnTheElementInsteadOfAValueLi self::assertEquals($expected, $actual); } - public function provideOneElementValues(): iterable + public static function provideOneElementValues(): iterable { yield 'one value' => [ new FakeValue(), diff --git a/tests/FixtureBuilder/ExpressionLanguage/Parser/TokenParser/Chainable/EscapedValueTokenParserTest.php b/tests/FixtureBuilder/ExpressionLanguage/Parser/TokenParser/Chainable/EscapedValueTokenParserTest.php index 2927eb35..1b56e2f2 100644 --- a/tests/FixtureBuilder/ExpressionLanguage/Parser/TokenParser/Chainable/EscapedValueTokenParserTest.php +++ b/tests/FixtureBuilder/ExpressionLanguage/Parser/TokenParser/Chainable/EscapedValueTokenParserTest.php @@ -81,7 +81,7 @@ public function testTheEscapedValueIsDetokenizedBeforeBeingReturned(): void self::assertEquals($expected, $actual); } - public function provideTokens(): iterable + public static function provideTokens(): iterable { return [ [ diff --git a/tests/FixtureBuilder/ExpressionLanguage/Parser/TokenParser/Chainable/FixtureListReferenceTokenParserTest.php b/tests/FixtureBuilder/ExpressionLanguage/Parser/TokenParser/Chainable/FixtureListReferenceTokenParserTest.php index 79313c85..351712ad 100644 --- a/tests/FixtureBuilder/ExpressionLanguage/Parser/TokenParser/Chainable/FixtureListReferenceTokenParserTest.php +++ b/tests/FixtureBuilder/ExpressionLanguage/Parser/TokenParser/Chainable/FixtureListReferenceTokenParserTest.php @@ -87,7 +87,7 @@ public function testReturnsListOfPossibleValues(): void self::assertEquals($expected, $actual); } - public function provideTokens(): iterable + public static function provideTokens(): iterable { return [ [ diff --git a/tests/FixtureBuilder/ExpressionLanguage/Parser/TokenParser/Chainable/FixtureMethodReferenceTokenParserTest.php b/tests/FixtureBuilder/ExpressionLanguage/Parser/TokenParser/Chainable/FixtureMethodReferenceTokenParserTest.php index bb7794dd..a7dc2f61 100644 --- a/tests/FixtureBuilder/ExpressionLanguage/Parser/TokenParser/Chainable/FixtureMethodReferenceTokenParserTest.php +++ b/tests/FixtureBuilder/ExpressionLanguage/Parser/TokenParser/Chainable/FixtureMethodReferenceTokenParserTest.php @@ -13,6 +13,7 @@ namespace Nelmio\Alice\FixtureBuilder\ExpressionLanguage\Parser\TokenParser\Chainable; +use Closure; use Nelmio\Alice\Definition\Value\FixtureMethodCallValue; use Nelmio\Alice\Definition\Value\FixtureReferenceValue; use Nelmio\Alice\Definition\Value\FunctionCallValue; @@ -109,9 +110,13 @@ public function testThrowsAnExceptionIfMethodReferenceIsMalformed(): void /** * @dataProvider provideParser + * + * @param Closure(self): ParserInterface $decoratedParserFactory */ - public function testThrowsAnExceptionIfParsingReturnsAnUnexpectedResult(ParserInterface $decoratedParser): void + public function testThrowsAnExceptionIfParsingReturnsAnUnexpectedResult(Closure $decoratedParserFactory): void { + $decoratedParser = $decoratedParserFactory($this); + try { $token = new Token('@user->getName()', new TokenType(TokenType::METHOD_REFERENCE_TYPE)); @@ -128,24 +133,36 @@ public function testThrowsAnExceptionIfParsingReturnsAnUnexpectedResult(ParserIn } } - public function provideParser(): iterable + public static function provideParser(): iterable { - $decoratedParserProphecy = $this->prophesize(ParserInterface::class); - $decoratedParserProphecy->parse('@user')->willReturn('foo'); - $decoratedParserProphecy->parse('')->willReturn(new FunctionCallValue('getName')); - - yield 'unexpected reference' => [$decoratedParserProphecy->reveal()]; - - $decoratedParserProphecy = $this->prophesize(ParserInterface::class); - $decoratedParserProphecy->parse('@user')->willReturn(new FixtureReferenceValue('user')); - $decoratedParserProphecy->parse('')->willReturn('foo'); - - yield 'unexpected fixture call' => [$decoratedParserProphecy->reveal()]; - - $decoratedParserProphecy = $this->prophesize(ParserInterface::class); - $decoratedParserProphecy->parse('@user')->willReturn('foo'); - $decoratedParserProphecy->parse('')->willReturn('bar'); - - yield 'unexpected reference and fixture call' => [$decoratedParserProphecy->reveal()]; + yield 'unexpected reference' => [ + function (self $testCase) { + $decoratedParserProphecy = $testCase->prophesize(ParserInterface::class); + $decoratedParserProphecy->parse('@user')->willReturn('foo'); + $decoratedParserProphecy->parse('')->willReturn(new FunctionCallValue('getName')); + + return $decoratedParserProphecy->reveal(); + }, + ]; + + yield 'unexpected fixture call' => [ + function (self $testCase) { + $decoratedParserProphecy = $testCase->prophesize(ParserInterface::class); + $decoratedParserProphecy->parse('@user')->willReturn(new FixtureReferenceValue('user')); + $decoratedParserProphecy->parse('')->willReturn('foo'); + + return $decoratedParserProphecy->reveal(); + }, + ]; + + yield 'unexpected reference and fixture call' => [ + function (self $testCase) { + $decoratedParserProphecy = $testCase->prophesize(ParserInterface::class); + $decoratedParserProphecy->parse('@user')->willReturn('foo'); + $decoratedParserProphecy->parse('')->willReturn('bar'); + + return $decoratedParserProphecy->reveal(); + }, + ]; } } diff --git a/tests/FixtureBuilder/ExpressionLanguage/TokenTypeTest.php b/tests/FixtureBuilder/ExpressionLanguage/TokenTypeTest.php index 83089bfb..a9d39f0d 100644 --- a/tests/FixtureBuilder/ExpressionLanguage/TokenTypeTest.php +++ b/tests/FixtureBuilder/ExpressionLanguage/TokenTypeTest.php @@ -72,7 +72,7 @@ public function testThrowsAnExceptionIfAnInvalidTypeIsGiven(): void new TokenType('unknown'); } - public function provideAcceptableTypes(): iterable + public static function provideAcceptableTypes(): iterable { $reflClass = new ReflectionClass(TokenType::class); $constants = $reflClass->getConstants(); diff --git a/tests/Generator/Hydrator/Property/SymfonyPropertyAccessorHydratorTest.php b/tests/Generator/Hydrator/Property/SymfonyPropertyAccessorHydratorTest.php index 73ef528a..ce8d3ceb 100644 --- a/tests/Generator/Hydrator/Property/SymfonyPropertyAccessorHydratorTest.php +++ b/tests/Generator/Hydrator/Property/SymfonyPropertyAccessorHydratorTest.php @@ -222,7 +222,7 @@ public function testObjectHydrationAgainstMutlipleValues(Property $property): vo self::assertSame($expected, $actual); } - public function provideProperties(): iterable + public static function provideProperties(): iterable { return [ // Accessor methods diff --git a/tests/Generator/NamedArgumentsResolverTest.php b/tests/Generator/NamedArgumentsResolverTest.php index 55ad89b8..46782b97 100644 --- a/tests/Generator/NamedArgumentsResolverTest.php +++ b/tests/Generator/NamedArgumentsResolverTest.php @@ -39,7 +39,7 @@ public function testResolveArguments(string $className, string $methodName, arra ); } - public function provideResolveArgumentsCases(): iterable + public static function provideResolveArgumentsCases(): iterable { yield 'constructor: no named arguments' => [ DummyWithMethods::class, diff --git a/tests/Generator/ObjectGenerator/CompleteObjectGeneratorTest.php b/tests/Generator/ObjectGenerator/CompleteObjectGeneratorTest.php index 99048cfd..ddc44fa8 100644 --- a/tests/Generator/ObjectGenerator/CompleteObjectGeneratorTest.php +++ b/tests/Generator/ObjectGenerator/CompleteObjectGeneratorTest.php @@ -13,6 +13,7 @@ namespace Nelmio\Alice\Generator\ObjectGenerator; +use Closure; use Nelmio\Alice\Definition\Fixture\DummyFixture; use Nelmio\Alice\Definition\Fixture\SimpleFixture; use Nelmio\Alice\Definition\Object\CompleteObject; @@ -106,13 +107,14 @@ public function testUsesDecoratedGeneratorToGenerateTheObjectAndReturnsTheResult public function testReturnsCompleteObjectWheneverItIsPossible( FixtureInterface $fixture, GenerationContext $context, - ObjectGeneratorInterface $decoratedGenerator, + Closure $decoratedGeneratorFactory, ObjectBag $expected ): void { $set = ResolvedFixtureSetFactory::create( null, (new FixtureBag())->with($fixture), ); + $decoratedGenerator = $decoratedGeneratorFactory($this); $generator = new CompleteObjectGenerator($decoratedGenerator); $actual = $generator->generate($fixture, $set, $context); @@ -120,7 +122,7 @@ public function testReturnsCompleteObjectWheneverItIsPossible( self::assertEquals($expected, $actual); } - public function provideSets(): iterable + public static function provideSets(): iterable { yield 'decorated generator generates a complete object => complete object' => (function () { $fixture = new SimpleFixture( @@ -134,18 +136,20 @@ public function provideSets(): iterable $context = new GenerationContext(); - $decoratedGeneratorProphecy = $this->prophesize(ObjectGeneratorInterface::class); - $decoratedGeneratorProphecy - ->generate(Argument::cetera()) - ->willReturn( - (new ObjectBag())->with( - new CompleteObject( - new SimpleObject('dummy', new stdClass()), + $decoratedGeneratorFactory = static function (self $testCase): ObjectGeneratorInterface { + $decoratedGeneratorProphecy = $testCase->prophesize(ObjectGeneratorInterface::class); + $decoratedGeneratorProphecy + ->generate(Argument::cetera()) + ->willReturn( + (new ObjectBag())->with( + new CompleteObject( + new SimpleObject('dummy', new stdClass()), + ), ), - ), - ); - /** @var ObjectGeneratorInterface $decoratedGenerator */ - $decoratedGenerator = $decoratedGeneratorProphecy->reveal(); + ); + + return $decoratedGeneratorProphecy->reveal(); + }; $expected = (new ObjectBag())->with( new CompleteObject( @@ -158,7 +162,7 @@ public function provideSets(): iterable return [ $fixture, $context, - $decoratedGenerator, + $decoratedGeneratorFactory, $expected, ]; })(); @@ -176,16 +180,18 @@ public function provideSets(): iterable $context = new GenerationContext(); $context->setToSecondPass(); - $decoratedGeneratorProphecy = $this->prophesize(ObjectGeneratorInterface::class); - $decoratedGeneratorProphecy - ->generate(Argument::cetera()) - ->willReturn( - (new ObjectBag())->with( - new SimpleObject('dummy', new stdClass()), - ), - ); - /** @var ObjectGeneratorInterface $decoratedGenerator */ - $decoratedGenerator = $decoratedGeneratorProphecy->reveal(); + $decoratedGeneratorFactory = static function (self $testCase): ObjectGeneratorInterface { + $decoratedGeneratorProphecy = $testCase->prophesize(ObjectGeneratorInterface::class); + $decoratedGeneratorProphecy + ->generate(Argument::cetera()) + ->willReturn( + (new ObjectBag())->with( + new SimpleObject('dummy', new stdClass()), + ), + ); + + return $decoratedGeneratorProphecy->reveal(); + }; $expected = (new ObjectBag())->with( new CompleteObject( @@ -196,7 +202,7 @@ public function provideSets(): iterable return [ $fixture, $context, - $decoratedGenerator, + $decoratedGeneratorFactory, $expected, ]; })(); @@ -214,16 +220,18 @@ public function provideSets(): iterable $context = new GenerationContext(); $context->markAsNeedsCompleteGeneration(); - $decoratedGeneratorProphecy = $this->prophesize(ObjectGeneratorInterface::class); - $decoratedGeneratorProphecy - ->generate(Argument::cetera()) - ->willReturn( - (new ObjectBag())->with( - new SimpleObject('dummy', new stdClass()), - ), - ); - /** @var ObjectGeneratorInterface $decoratedGenerator */ - $decoratedGenerator = $decoratedGeneratorProphecy->reveal(); + $decoratedGeneratorFactory = static function (self $testCase): ObjectGeneratorInterface { + $decoratedGeneratorProphecy = $testCase->prophesize(ObjectGeneratorInterface::class); + $decoratedGeneratorProphecy + ->generate(Argument::cetera()) + ->willReturn( + (new ObjectBag())->with( + new SimpleObject('dummy', new stdClass()), + ), + ); + + return $decoratedGeneratorProphecy->reveal(); + }; $expected = (new ObjectBag())->with( new CompleteObject( @@ -234,7 +242,7 @@ public function provideSets(): iterable return [ $fixture, $context, - $decoratedGenerator, + $decoratedGeneratorFactory, $expected, ]; })(); @@ -248,16 +256,18 @@ public function provideSets(): iterable $context = new GenerationContext(); - $decoratedGeneratorProphecy = $this->prophesize(ObjectGeneratorInterface::class); - $decoratedGeneratorProphecy - ->generate(Argument::cetera()) - ->willReturn( - (new ObjectBag())->with( - new SimpleObject('dummy', new stdClass()), - ), - ); - /** @var ObjectGeneratorInterface $decoratedGenerator */ - $decoratedGenerator = $decoratedGeneratorProphecy->reveal(); + $decoratedGeneratorFactory = static function (self $testCase): ObjectGeneratorInterface { + $decoratedGeneratorProphecy = $testCase->prophesize(ObjectGeneratorInterface::class); + $decoratedGeneratorProphecy + ->generate(Argument::cetera()) + ->willReturn( + (new ObjectBag())->with( + new SimpleObject('dummy', new stdClass()), + ), + ); + + return $decoratedGeneratorProphecy->reveal(); + }; $expected = (new ObjectBag())->with( new CompleteObject( @@ -268,7 +278,7 @@ public function provideSets(): iterable return [ $fixture, $context, - $decoratedGenerator, + $decoratedGeneratorFactory, $expected, ]; })(); @@ -285,21 +295,23 @@ public function provideSets(): iterable $context = new GenerationContext(); - $decoratedGeneratorProphecy = $this->prophesize(ObjectGeneratorInterface::class); - $decoratedGeneratorProphecy - ->generate(Argument::cetera()) - ->willReturn( - $expected = (new ObjectBag())->with( - new SimpleObject('dummy', new stdClass()), - ), - ); - /** @var ObjectGeneratorInterface $decoratedGenerator */ - $decoratedGenerator = $decoratedGeneratorProphecy->reveal(); + $expected = (new ObjectBag())->with( + new SimpleObject('dummy', new stdClass()), + ); + + $decoratedGeneratorFactory = static function (self $testCase) use ($expected): ObjectGeneratorInterface { + $decoratedGeneratorProphecy = $testCase->prophesize(ObjectGeneratorInterface::class); + $decoratedGeneratorProphecy + ->generate(Argument::cetera()) + ->willReturn($expected); + + return $decoratedGeneratorProphecy->reveal(); + }; return [ $fixture, $context, - $decoratedGenerator, + $decoratedGeneratorFactory, $expected, ]; })(); diff --git a/tests/Generator/Resolver/Fixture/TemplateFixtureResolverTest.php b/tests/Generator/Resolver/Fixture/TemplateFixtureResolverTest.php index d2155978..09142ba5 100644 --- a/tests/Generator/Resolver/Fixture/TemplateFixtureResolverTest.php +++ b/tests/Generator/Resolver/Fixture/TemplateFixtureResolverTest.php @@ -21,7 +21,7 @@ * * More tests in: * - * @see \Nelmio\Alice\Generator\Resolver\Fixture\TemplateFixtureBagResolverTest + * @see TemplateFixtureBagResolverTest * @internal */ class TemplateFixtureResolverTest extends TestCase diff --git a/tests/Generator/Resolver/Parameter/Chainable/ArrayParameterResolverTest.php b/tests/Generator/Resolver/Parameter/Chainable/ArrayParameterResolverTest.php index dc89868c..ab44cf46 100644 --- a/tests/Generator/Resolver/Parameter/Chainable/ArrayParameterResolverTest.php +++ b/tests/Generator/Resolver/Parameter/Chainable/ArrayParameterResolverTest.php @@ -260,7 +260,7 @@ public function testTheContextPassedToTheInjectedResolverIsAlwaysValid(?Resolvin ); } - public function provideContexts(): iterable + public static function provideContexts(): iterable { return [ 'no context' => [ diff --git a/tests/Generator/Resolver/Parameter/Chainable/RecursiveParameterResolverTest.php b/tests/Generator/Resolver/Parameter/Chainable/RecursiveParameterResolverTest.php index 8c029101..d66b326d 100644 --- a/tests/Generator/Resolver/Parameter/Chainable/RecursiveParameterResolverTest.php +++ b/tests/Generator/Resolver/Parameter/Chainable/RecursiveParameterResolverTest.php @@ -324,7 +324,7 @@ function ($args) { } } - public function provideContexts(): iterable + public static function provideContexts(): iterable { return [ 'no context' => [ diff --git a/tests/Generator/Resolver/ParameterResolverIntegrationTest.php b/tests/Generator/Resolver/ParameterResolverIntegrationTest.php index 5c91e68a..eb362ddc 100644 --- a/tests/Generator/Resolver/ParameterResolverIntegrationTest.php +++ b/tests/Generator/Resolver/ParameterResolverIntegrationTest.php @@ -70,7 +70,7 @@ public function testThrowExceptionWhenResolvingNonExistentParameter(): void ); } - public function provideCircularReferences(): iterable + public static function provideCircularReferences(): iterable { $return = []; @@ -103,7 +103,7 @@ public function provideCircularReferences(): iterable return $return; } - public function provideParameters(): iterable + public static function provideParameters(): iterable { $return = []; diff --git a/tests/Generator/Resolver/UniqueValuesPoolTest.php b/tests/Generator/Resolver/UniqueValuesPoolTest.php index 045a79e5..60793f4f 100644 --- a/tests/Generator/Resolver/UniqueValuesPoolTest.php +++ b/tests/Generator/Resolver/UniqueValuesPoolTest.php @@ -49,7 +49,7 @@ public function testHasObjectValue(UniqueValuesPool $pool, UniqueValue $value, b self::assertTrue($pool->has($value)); } - public function provideHasValueSet(): iterable + public static function provideHasValueSet(): iterable { $baseValue = new UniqueValue('foo', 'temporary value'); @@ -61,25 +61,25 @@ public function provideHasValueSet(): iterable ]; yield '[null value] with `null' => [ - $this->createPoolWithValue(null), + self::createPoolWithValue(null), $baseValue->withValue(null), true, ]; yield '[null value] with `false' => [ - $this->createPoolWithValue(false), + self::createPoolWithValue(false), $baseValue->withValue(null), false, ]; yield '[null value] with empty array' => [ - $this->createPoolWithValue([]), + self::createPoolWithValue([]), $baseValue->withValue(null), false, ]; yield '[null value] with empty string' => [ - $this->createPoolWithValue(''), + self::createPoolWithValue(''), $baseValue->withValue(null), false, ]; @@ -92,56 +92,56 @@ public function provideHasValueSet(): iterable ]; yield '[`true`] with `true`' => [ - $this->createPoolWithValue(true), + self::createPoolWithValue(true), $baseValue->withValue(true), true, ]; yield '[`true`] with `1`' => [ - $this->createPoolWithValue(1), + self::createPoolWithValue(1), $baseValue->withValue(true), false, ]; yield '[`true`] with `-1`' => [ - $this->createPoolWithValue(-1), + self::createPoolWithValue(-1), $baseValue->withValue(true), false, ]; yield '[`true`] with `"1"`' => [ - $this->createPoolWithValue('1'), + self::createPoolWithValue('1'), $baseValue->withValue(true), false, ]; yield '[`true`] with `"-1"`' => [ - $this->createPoolWithValue('-1'), + self::createPoolWithValue('-1'), $baseValue->withValue(true), false, ]; yield '[`true`] with `"alice"`' => [ - $this->createPoolWithValue('alice'), + self::createPoolWithValue('alice'), $baseValue->withValue(true), false, ]; // Check objects yield 'with two equivalent objects' => [ - $this->createPoolWithValue(new stdClass()), + self::createPoolWithValue(new stdClass()), $baseValue->withValue(new stdClass()), true, ]; yield 'with two non-equivalent objects' => [ - $this->createPoolWithValue(new stdClass()), + self::createPoolWithValue(new stdClass()), $baseValue->withValue(StdClassFactory::create(['foo' => 'bar'])), false, ]; yield 'with two equivalent objects (2)' => [ - $this->createPoolWithValue( + self::createPoolWithValue( StdClassFactory::create([ 'relatedDummy' => StdClassFactory::create([ 'foo' => 'bar', @@ -159,7 +159,7 @@ public function provideHasValueSet(): iterable ]; yield 'with two non-equivalent objects (2)' => [ - $this->createPoolWithValue( + self::createPoolWithValue( StdClassFactory::create([ 'relatedDummy' => StdClassFactory::create([ 'foo' => 'bar', @@ -178,43 +178,43 @@ public function provideHasValueSet(): iterable // Checks arrays yield 'two identical arrays' => [ - $this->createPoolWithValue([]), + self::createPoolWithValue([]), $baseValue->withValue([]), true, ]; yield 'two equivalent arrays' => [ - $this->createPoolWithValue([10, 20]), + self::createPoolWithValue([10, 20]), $baseValue->withValue([20, 10]), true, ]; yield 'two equivalent arrays (2)' => [ - $this->createPoolWithValue([10, 'foo' => new stdClass(), 20]), + self::createPoolWithValue([10, 'foo' => new stdClass(), 20]), $baseValue->withValue([20, 10, 'foo' => new stdClass()]), true, ]; yield 'two non-equivalent arrays (2)' => [ - $this->createPoolWithValue([10, 20, 30]), + self::createPoolWithValue([10, 20, 30]), $baseValue->withValue([20, 10]), false, ]; yield 'two non-equivalent arrays (3)' => [ - $this->createPoolWithValue([1]), + self::createPoolWithValue([1]), $baseValue->withValue([true]), false, ]; yield 'two non-equivalent arrays (4)' => [ - $this->createPoolWithValue([10, 'foo' => StdClassFactory::create(['foo' => 'bar']), 20]), + self::createPoolWithValue([10, 'foo' => StdClassFactory::create(['foo' => 'bar']), 20]), $baseValue->withValue([20, 10, 'foo' => new stdClass()]), false, ]; } - private function createPoolWithValue($value): UniqueValuesPool + private static function createPoolWithValue($value): UniqueValuesPool { $pool = new UniqueValuesPool(); $pool->add(new UniqueValue('foo', $value)); diff --git a/tests/Loader/LoaderIntegrationTest.php b/tests/Loader/LoaderIntegrationTest.php index d5619426..ed386a7e 100644 --- a/tests/Loader/LoaderIntegrationTest.php +++ b/tests/Loader/LoaderIntegrationTest.php @@ -1575,7 +1575,7 @@ public function testNewlinesInIdentity(): void ); } - public function provideFixturesToInstantiate(): iterable + public static function provideFixturesToInstantiate(): iterable { yield 'with default constructor – use default constructor' => [ [ @@ -1837,7 +1837,7 @@ public function provideFixturesToInstantiate(): iterable ]; } - public function provideLegacyFixturesToInstantiate(): iterable + public static function provideLegacyFixturesToInstantiate(): iterable { yield 'with named constructor - use factory function' => [ [ @@ -1968,7 +1968,7 @@ public function provideLegacyFixturesToInstantiate(): iterable ]; } - public function provideFixturesToInstantiateWithFactory(): iterable + public static function provideFixturesToInstantiateWithFactory(): iterable { yield 'regular factory' => [ [ @@ -2099,7 +2099,7 @@ public function provideFixturesToInstantiateWithFactory(): iterable ]; } - public function provideFixtureToInstantiateWithDeprecatedConstructor(): iterable + public static function provideFixtureToInstantiateWithDeprecatedConstructor(): iterable { yield 'with named constructor - use factory function' => [ [ @@ -2188,7 +2188,7 @@ public function provideFixtureToInstantiateWithDeprecatedConstructor(): iterable ]; } - public function provideFixturesToHydrate(): iterable + public static function provideFixturesToHydrate(): iterable { yield 'public camelCase property' => [ [ @@ -2322,7 +2322,7 @@ public function provideFixturesToHydrate(): iterable ]; } - public function provideFixturesToGenerate(): iterable + public static function provideFixturesToGenerate(): iterable { yield '[construct] with reference to object with throwable setter and caller' => [ [ diff --git a/tests/ParameterTest.php b/tests/ParameterTest.php index 460ef081..ec2fb4f9 100644 --- a/tests/ParameterTest.php +++ b/tests/ParameterTest.php @@ -57,7 +57,7 @@ public function testWithersReturnNewModifiedInstance(): void self::assertEquals('rab', $newParam->getValue()); } - public function provideValues(): iterable + public static function provideValues(): iterable { return [ 'boolean' => [true],