From ed48a0a88ebc4ebdce8d4da538bcee91009a07c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Fri, 15 May 2020 10:34:55 +0200 Subject: [PATCH 1/3] Bump phpstan --- tests/Definition/Fixture/TemplatingTest.php | 2 +- tests/Definition/Value/FixtureMethodCallValueTest.php | 4 ++-- tests/Definition/Value/FixturePropertyValueTest.php | 2 +- tests/FixtureBuilder/BareFixtureSetTest.php | 4 ++-- tests/FixtureBuilder/ExpressionLanguage/TokenTest.php | 2 +- tests/Generator/Instantiator/InstantiatorRegistryTest.php | 6 +++--- tests/Generator/ResolvedFixtureSetTest.php | 3 +-- .../Resolver/Fixture/TemplateFixtureBagResolverTest.php | 7 ++----- .../Resolver/Fixture/TemplatingFixtureBagTest.php | 2 +- .../Resolver/ParameterResolverIntegrationTest.php | 2 +- tests/Generator/Resolver/UniqueValuesPoolTest.php | 2 +- .../Chainable/FixtureMethodCallReferenceResolverTest.php | 8 ++++---- .../Resolver/Value/Chainable/ListValueResolverTest.php | 2 +- .../Value/Chainable/OptionalValueResolverTest.php | 2 +- tests/ParameterBagTest.php | 2 +- vendor-bin/phpstan/composer.json | 2 +- 16 files changed, 24 insertions(+), 28 deletions(-) diff --git a/tests/Definition/Fixture/TemplatingTest.php b/tests/Definition/Fixture/TemplatingTest.php index 7934a35b4..34b91130f 100644 --- a/tests/Definition/Fixture/TemplatingTest.php +++ b/tests/Definition/Fixture/TemplatingTest.php @@ -27,7 +27,7 @@ class TemplatingTest extends TestCase { /** - * @depends Nelmio\Alice\Definition\ServiceReference\FixtureReferenceTest::testIsImmutable + * @depends \Nelmio\Alice\Definition\ServiceReference\FixtureReferenceTest::testIsImmutable */ public function testIsImmutable() { diff --git a/tests/Definition/Value/FixtureMethodCallValueTest.php b/tests/Definition/Value/FixtureMethodCallValueTest.php index c00db1e0e..76c552ae0 100644 --- a/tests/Definition/Value/FixtureMethodCallValueTest.php +++ b/tests/Definition/Value/FixtureMethodCallValueTest.php @@ -39,8 +39,8 @@ public function testReadAccessorsReturnPropertiesValues() } /** - * @depends Nelmio\Alice\Definition\ServiceReference\FixtureReferenceTest::testIsImmutable - * @depends Nelmio\Alice\Definition\Value\FunctionCallValueTest::testIsImmutable + * @depends \Nelmio\Alice\Definition\ServiceReference\FixtureReferenceTest::testIsImmutable + * @depends \Nelmio\Alice\Definition\Value\FunctionCallValueTest::testIsImmutable */ public function testIsImmutable() { diff --git a/tests/Definition/Value/FixturePropertyValueTest.php b/tests/Definition/Value/FixturePropertyValueTest.php index 8b4099066..2e962f9e5 100644 --- a/tests/Definition/Value/FixturePropertyValueTest.php +++ b/tests/Definition/Value/FixturePropertyValueTest.php @@ -39,7 +39,7 @@ public function testReadAccessorsReturnPropertiesValues() } /** - * @depends Nelmio\Alice\Definition\Value\FixtureReferenceValueTest::testIsImmutable + * @depends \Nelmio\Alice\Definition\Value\FixtureReferenceValueTest::testIsImmutable */ public function testIsImmutable() { diff --git a/tests/FixtureBuilder/BareFixtureSetTest.php b/tests/FixtureBuilder/BareFixtureSetTest.php index e59f89b8e..136275737 100644 --- a/tests/FixtureBuilder/BareFixtureSetTest.php +++ b/tests/FixtureBuilder/BareFixtureSetTest.php @@ -36,8 +36,8 @@ public function testReadAccessorsReturnPropertiesValues() } /** - * @depends Nelmio\Alice\ParameterBagTest::testIsImmutable - * @depends Nelmio\Alice\FixtureBagTest::testIsImmutable + * @depends \Nelmio\Alice\ParameterBagTest::testIsImmutable + * @depends \Nelmio\Alice\FixtureBagTest::testIsImmutable */ public function testIsImmutable() { diff --git a/tests/FixtureBuilder/ExpressionLanguage/TokenTest.php b/tests/FixtureBuilder/ExpressionLanguage/TokenTest.php index 5535d4c13..e10f74bcf 100644 --- a/tests/FixtureBuilder/ExpressionLanguage/TokenTest.php +++ b/tests/FixtureBuilder/ExpressionLanguage/TokenTest.php @@ -33,7 +33,7 @@ public function testReadAccessorsReturnPropertiesValues() } /** - * @depends Nelmio\Alice\FixtureBuilder\ExpressionLanguage\TokenTypeTest::testIsImmutable + * @depends \Nelmio\Alice\FixtureBuilder\ExpressionLanguage\TokenTypeTest::testIsImmutable */ public function testIsImmutable() { diff --git a/tests/Generator/Instantiator/InstantiatorRegistryTest.php b/tests/Generator/Instantiator/InstantiatorRegistryTest.php index 23f6f0bd1..b211fa490 100644 --- a/tests/Generator/Instantiator/InstantiatorRegistryTest.php +++ b/tests/Generator/Instantiator/InstantiatorRegistryTest.php @@ -66,7 +66,7 @@ public function testPassValueResolverAwarenessPropertyToItsInstantiator() $newRegistry = $registry->withValueResolver($resolver); $this->assertEquals(new InstantiatorRegistry([]), $registry); - $this->assertEquals(new InstantiatorRegistry([], $resolver), $newRegistry); + $this->assertEquals(new InstantiatorRegistry([]), $newRegistry); $registry = new InstantiatorRegistry([new FakeChainableInstantiator()]); @@ -74,7 +74,7 @@ public function testPassValueResolverAwarenessPropertyToItsInstantiator() $this->assertEquals(new InstantiatorRegistry([new FakeChainableInstantiator()]), $registry); $this->assertEquals( - new InstantiatorRegistry([new FakeChainableInstantiator()], $resolver), + new InstantiatorRegistry([new FakeChainableInstantiator()]), $newRegistry ); @@ -94,7 +94,7 @@ public function testPassValueResolverAwarenessPropertyToItsInstantiator() $this->assertEquals(new InstantiatorRegistry([$nonAwareInstantiator, $instantiator]), $registry); $this->assertEquals( - new InstantiatorRegistry([$nonAwareInstantiator, new FakeChainableInstantiator()], $resolver), + new InstantiatorRegistry([$nonAwareInstantiator, new FakeChainableInstantiator()]), $newRegistry ); diff --git a/tests/Generator/ResolvedFixtureSetTest.php b/tests/Generator/ResolvedFixtureSetTest.php index 8d06490c4..e96e58c96 100644 --- a/tests/Generator/ResolvedFixtureSetTest.php +++ b/tests/Generator/ResolvedFixtureSetTest.php @@ -13,7 +13,6 @@ namespace Nelmio\Alice\Generator; -use Nelmio\Alice\Definition\Fixture\DummyFixture; use Nelmio\Alice\FixtureBag; use Nelmio\Alice\ObjectBag; use Nelmio\Alice\ParameterBag; @@ -57,7 +56,7 @@ public function testWithersReturnANewModifiedInstance() $newSet ); - $newFixtures = new FixtureBag(['foo' => new DummyFixture('foo')]); + $newFixtures = new FixtureBag(); $newSet = $set->withFixtures($newFixtures); $this->assertEquals( diff --git a/tests/Generator/Resolver/Fixture/TemplateFixtureBagResolverTest.php b/tests/Generator/Resolver/Fixture/TemplateFixtureBagResolverTest.php index d1e4a68fe..4e3f20e3a 100644 --- a/tests/Generator/Resolver/Fixture/TemplateFixtureBagResolverTest.php +++ b/tests/Generator/Resolver/Fixture/TemplateFixtureBagResolverTest.php @@ -190,9 +190,7 @@ public function testResolvesTemplatesFixturesAndReturnsResultingFixtureBag() ) ), $this->getDecoratedFixturesFlag($user1) - ), - (new FlagBag('user1')) - ->withFlag(new ElementFlag('dummy_flag')) + ) ) ) ->with($user5) @@ -300,8 +298,7 @@ public function testTheResolutionIsInvarientToTheOrderInWhichFixturesAreGiven() ) ), $this->getDecoratedFixturesFlag($user1) - ), - (new FlagBag('user1')) + ) ) ) ; diff --git a/tests/Generator/Resolver/Fixture/TemplatingFixtureBagTest.php b/tests/Generator/Resolver/Fixture/TemplatingFixtureBagTest.php index a0bbdbb59..9bedd6919 100644 --- a/tests/Generator/Resolver/Fixture/TemplatingFixtureBagTest.php +++ b/tests/Generator/Resolver/Fixture/TemplatingFixtureBagTest.php @@ -83,7 +83,7 @@ public function testReadAccessorsReturnPropertiesValues() } /** - * @depends Nelmio\Alice\FixtureBagTest::testIsImmutable + * @depends \Nelmio\Alice\FixtureBagTest::testIsImmutable */ public function testIsImmutable() { diff --git a/tests/Generator/Resolver/ParameterResolverIntegrationTest.php b/tests/Generator/Resolver/ParameterResolverIntegrationTest.php index 0e1b605d9..2898698c2 100644 --- a/tests/Generator/Resolver/ParameterResolverIntegrationTest.php +++ b/tests/Generator/Resolver/ParameterResolverIntegrationTest.php @@ -44,7 +44,7 @@ protected function setUp(): void */ public function testResolveParameters( ParameterBag $unresolvedParameters, - ParameterBag $injectedParameters = null, + ?ParameterBag $injectedParameters, ParameterBag $expected ) { $actual = $this->resolver->resolve($unresolvedParameters, $injectedParameters); diff --git a/tests/Generator/Resolver/UniqueValuesPoolTest.php b/tests/Generator/Resolver/UniqueValuesPoolTest.php index c78df7160..a2a6eb0cf 100644 --- a/tests/Generator/Resolver/UniqueValuesPoolTest.php +++ b/tests/Generator/Resolver/UniqueValuesPoolTest.php @@ -29,7 +29,7 @@ public function testDoesNotHaveValueIfValueIsNotCached() } /** - * @depends Nelmio\Alice\Definition\Value\UniqueValueTest::testIsImmutable + * @depends \Nelmio\Alice\Definition\Value\UniqueValueTest::testIsImmutable */ public function testIsImmutable() { diff --git a/tests/Generator/Resolver/Value/Chainable/FixtureMethodCallReferenceResolverTest.php b/tests/Generator/Resolver/Value/Chainable/FixtureMethodCallReferenceResolverTest.php index 6d08129d9..630f3b0b8 100644 --- a/tests/Generator/Resolver/Value/Chainable/FixtureMethodCallReferenceResolverTest.php +++ b/tests/Generator/Resolver/Value/Chainable/FixtureMethodCallReferenceResolverTest.php @@ -85,7 +85,7 @@ public function testReturnsSetWithResolvedValue() { $value = new FixtureMethodCallValue( $reference = new FakeValue(), - $functionCall = new FunctionCallValue('getFoo', [ + new FunctionCallValue('getFoo', [ $arg1 = new FakeValue(), ]) ); @@ -143,7 +143,7 @@ public function testThrowsAResolverExceptionOnError() try { $value = new FixtureMethodCallValue( $reference = new MutableValue(new DummyWithGetter()), - $functionCall = new FunctionCallValue('getFoo') + new FunctionCallValue('getFoo') ); $set = ResolvedFixtureSetFactory::create(new ParameterBag(['foo' => 'bar'])); @@ -185,8 +185,8 @@ public function testThrowsAnExceptionIfResolvedReferenceHasNoSuchMethod() try { $instance = new DummyWithGetter(); $value = new FixtureMethodCallValue( - $reference = new MutableValue($instance), - $functionCall = new FunctionCallValue('getNonExistent') + new MutableValue($instance), + new FunctionCallValue('getNonExistent') ); $set = ResolvedFixtureSetFactory::create(); diff --git a/tests/Generator/Resolver/Value/Chainable/ListValueResolverTest.php b/tests/Generator/Resolver/Value/Chainable/ListValueResolverTest.php index ca8d301e2..d4bbe604f 100644 --- a/tests/Generator/Resolver/Value/Chainable/ListValueResolverTest.php +++ b/tests/Generator/Resolver/Value/Chainable/ListValueResolverTest.php @@ -52,7 +52,7 @@ public function testWithersReturnNewModifiedInstance() $newResolver = $resolver->withValueResolver(new FakeValueResolver()); $this->assertEquals(new ListValueResolver(), $resolver); - $this->assertEquals(new ListValueResolver(new FakeValueResolver(), new FakeValueResolver()), $newResolver); + $this->assertEquals(new ListValueResolver(new FakeValueResolver()), $newResolver); } public function testCanResolveOptionalValues() diff --git a/tests/Generator/Resolver/Value/Chainable/OptionalValueResolverTest.php b/tests/Generator/Resolver/Value/Chainable/OptionalValueResolverTest.php index 810ba10fd..307c41e2f 100644 --- a/tests/Generator/Resolver/Value/Chainable/OptionalValueResolverTest.php +++ b/tests/Generator/Resolver/Value/Chainable/OptionalValueResolverTest.php @@ -48,7 +48,7 @@ public function testWithersReturnNewModifiedInstance() $newResolver = $resolver->withValueResolver(new FakeValueResolver()); $this->assertEquals(new OptionalValueResolver(), $resolver); - $this->assertEquals(new OptionalValueResolver(new FakeValueResolver(), new FakeValueResolver()), $newResolver); + $this->assertEquals(new OptionalValueResolver(new FakeValueResolver()), $newResolver); } public function testCanResolveOptionalValues() diff --git a/tests/ParameterBagTest.php b/tests/ParameterBagTest.php index 925113c9d..1b90381c9 100644 --- a/tests/ParameterBagTest.php +++ b/tests/ParameterBagTest.php @@ -72,7 +72,7 @@ public function testIsImmutable() } /** - * @depends Nelmio\Alice\ParameterTest::testIsImmutable + * @depends \Nelmio\Alice\ParameterTest::testIsImmutable */ public function testWithersReturnNewModifiedObject() { diff --git a/vendor-bin/phpstan/composer.json b/vendor-bin/phpstan/composer.json index c18c99add..9102ef492 100644 --- a/vendor-bin/phpstan/composer.json +++ b/vendor-bin/phpstan/composer.json @@ -1,6 +1,6 @@ { "require-dev": { - "phpstan/phpstan": "^0.11.15" + "phpstan/phpstan": "^0.12" }, "config": { "bin-dir": "bin", From 8f31366f2828834fd87c895728c3949f69a7d55a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Fri, 15 May 2020 10:53:54 +0200 Subject: [PATCH 2/3] Fix a few PHPStan errors --- .../Object/ImmutableByCloneObject.php | 5 +- src/Definition/Object/CompleteObject.php | 2 +- src/Definition/Object/SimpleObject.php | 10 +- .../Chainable/FixtureReferenceResolver.php | 4 +- src/Loader/NativeLoader.php | 2 +- src/Loader/SimpleFilesLoader.php | 3 +- src/ObjectInterface.php | 4 +- .../DefaultIncludeProcessor.php | 3 - src/Throwable/Error/TypeErrorFactory.php | 10 - .../InstantiationExceptionFactory.php | 5 +- src/Throwable/LoadingThrowable.php | 4 +- .../Definition/Object/CompleteObjectTest.php | 3 +- ...estTest.php => SimpleDenormalizerTest.php} | 0 .../Populator/SimpleHydratorTest.php | 268 ------------------ .../Chainable/StringParameterResolverTest.php | 3 +- ...kerFunctionCallValueResolverValueTest.php} | 0 .../Throwable/Error/TypeErrorFactoryTest.php | 12 - ...xpressionLanguageExceptionFactoryTest.php} | 0 18 files changed, 17 insertions(+), 321 deletions(-) rename tests/FixtureBuilder/Denormalizer/{SimpleDenormalizerTestTest.php => SimpleDenormalizerTest.php} (100%) delete mode 100644 tests/Generator/Populator/SimpleHydratorTest.php rename tests/Generator/Resolver/Value/Chainable/{FakerFunctionCallResolverValueTest.php => FakerFunctionCallValueResolverValueTest.php} (100%) rename tests/Throwable/Exception/FixtureBuilder/ExpressionLanguage/{ExpressionLanguageExceptionFactoryFactoryTest.php => ExpressionLanguageExceptionFactoryTest.php} (100%) diff --git a/fixtures/Definition/Object/ImmutableByCloneObject.php b/fixtures/Definition/Object/ImmutableByCloneObject.php index 45a4739c7..7d5f9de73 100644 --- a/fixtures/Definition/Object/ImmutableByCloneObject.php +++ b/fixtures/Definition/Object/ImmutableByCloneObject.php @@ -29,9 +29,8 @@ class ImmutableByCloneObject implements ObjectInterface /** * @param string $id - * @param object $instance */ - public function __construct(string $id, $instance) + public function __construct(string $id, object $instance) { $this->id = $id; $this->instance = $instance; @@ -56,7 +55,7 @@ public function getInstance() /** * @inheritdoc */ - public function withInstance($newInstance) + public function withInstance(object $newInstance) { return new self($this->id, $newInstance); } diff --git a/src/Definition/Object/CompleteObject.php b/src/Definition/Object/CompleteObject.php index 86ba3c141..1a9da062e 100644 --- a/src/Definition/Object/CompleteObject.php +++ b/src/Definition/Object/CompleteObject.php @@ -50,7 +50,7 @@ public function getInstance() /** * @inheritdoc */ - public function withInstance($newInstance) + public function withInstance(object $newInstance) { throw new LogicException('Cannot create a new object from a complete object.'); } diff --git a/src/Definition/Object/SimpleObject.php b/src/Definition/Object/SimpleObject.php index f0696cd2f..768757004 100644 --- a/src/Definition/Object/SimpleObject.php +++ b/src/Definition/Object/SimpleObject.php @@ -14,7 +14,6 @@ namespace Nelmio\Alice\Definition\Object; use Nelmio\Alice\ObjectInterface; -use Nelmio\Alice\Throwable\Error\TypeErrorFactory; /** * Minimalist implementation of ObjectInterface. @@ -31,15 +30,8 @@ final class SimpleObject implements ObjectInterface */ private $instance; - /** - * @param object $instance - */ - public function __construct(string $id, $instance) + public function __construct(string $id, object $instance) { - if (false === is_object($instance)) { - throw TypeErrorFactory::createForObjectArgument($instance); - } - $this->reference = $id; $this->instance = $instance; } diff --git a/src/Generator/Resolver/Value/Chainable/FixtureReferenceResolver.php b/src/Generator/Resolver/Value/Chainable/FixtureReferenceResolver.php index c7956a504..6ba2dc12f 100644 --- a/src/Generator/Resolver/Value/Chainable/FixtureReferenceResolver.php +++ b/src/Generator/Resolver/Value/Chainable/FixtureReferenceResolver.php @@ -156,7 +156,9 @@ private function resolveReferredFixture( $fixtureSet ); } catch (CircularReferenceException $exception) { - if (false === $needsCompleteGeneration && null !== $passIncompleteObject) { + if (!isset($needsCompleteGeneration) + || (false === $needsCompleteGeneration && null !== $passIncompleteObject) + ) { throw $exception; } diff --git a/src/Loader/NativeLoader.php b/src/Loader/NativeLoader.php index 794ae079a..cf5a6fb02 100644 --- a/src/Loader/NativeLoader.php +++ b/src/Loader/NativeLoader.php @@ -182,7 +182,7 @@ * @method GeneratorInterface getGenerator() * @method ParserInterface getParser() * @method DenormalizerInterface getDenormalizer() - * @method FixtureBagDenormalizerInterface getFixtureBagDenormalizer + * @method FixtureBagDenormalizerInterface getFixtureBagDenormalizer() * @method FixtureDenormalizerInterface getFixtureDenormalizer() * @method FlagParserInterface getFlagParser() * @method ConstructorDenormalizerInterface getConstructorDenormalizer() diff --git a/src/Loader/SimpleFilesLoader.php b/src/Loader/SimpleFilesLoader.php index ceefa3ba8..12419c037 100644 --- a/src/Loader/SimpleFilesLoader.php +++ b/src/Loader/SimpleFilesLoader.php @@ -18,7 +18,6 @@ use Nelmio\Alice\IsAServiceTrait; use Nelmio\Alice\ObjectSet; use Nelmio\Alice\Parser\IncludeProcessor\IncludeDataMerger; -use Nelmio\Alice\Parser\IncludeProcessorInterface; use Nelmio\Alice\ParserInterface; final class SimpleFilesLoader implements FilesLoaderInterface @@ -31,7 +30,7 @@ final class SimpleFilesLoader implements FilesLoaderInterface private $dataLoader; /** - * @var IncludeProcessorInterface + * @var IncludeDataMerger */ private $dataMerger; diff --git a/src/ObjectInterface.php b/src/ObjectInterface.php index 0f92f9f74..d6e8349fb 100644 --- a/src/ObjectInterface.php +++ b/src/ObjectInterface.php @@ -32,9 +32,7 @@ public function getId(): string; public function getInstance(); /** - * @param object $newInstance - * * @return static */ - public function withInstance($newInstance); + public function withInstance(object $newInstance); } diff --git a/src/Parser/IncludeProcessor/DefaultIncludeProcessor.php b/src/Parser/IncludeProcessor/DefaultIncludeProcessor.php index 02a8895ac..24958b7a3 100644 --- a/src/Parser/IncludeProcessor/DefaultIncludeProcessor.php +++ b/src/Parser/IncludeProcessor/DefaultIncludeProcessor.php @@ -104,9 +104,6 @@ public function process(ParserInterface $parser, string $file, array $data): arr return $this->dataMerger->mergeInclude($data, $includeData); } - /** - * @param string[] $include - */ private function retrieveIncludeData(ParserInterface $parser, string $file, array $include): array { $data = []; diff --git a/src/Throwable/Error/TypeErrorFactory.php b/src/Throwable/Error/TypeErrorFactory.php index 02e7d8d9a..ff37ffe2f 100644 --- a/src/Throwable/Error/TypeErrorFactory.php +++ b/src/Throwable/Error/TypeErrorFactory.php @@ -23,16 +23,6 @@ */ final class TypeErrorFactory { - public static function createForObjectArgument($instance): TypeError - { - return new TypeError( - sprintf( - 'Expected instance argument to be an object. Got "%s" instead.', - gettype($instance) - ) - ); - } - public static function createForDynamicArrayQuantifier($quantifier): TypeError { return new TypeError( diff --git a/src/Throwable/Exception/Generator/Instantiator/InstantiationExceptionFactory.php b/src/Throwable/Exception/Generator/Instantiator/InstantiationExceptionFactory.php index 0dbdc175d..1bd51d6b2 100644 --- a/src/Throwable/Exception/Generator/Instantiator/InstantiationExceptionFactory.php +++ b/src/Throwable/Exception/Generator/Instantiator/InstantiationExceptionFactory.php @@ -69,10 +69,7 @@ public static function createForCouldNotGetConstructorData( ); } - /** - * @param object $instance - */ - public static function createForInvalidInstanceType(FixtureInterface $fixture, $instance): InstantiationException + public static function createForInvalidInstanceType(FixtureInterface $fixture, ?object $instance): InstantiationException { return new InstantiationException( sprintf( diff --git a/src/Throwable/LoadingThrowable.php b/src/Throwable/LoadingThrowable.php index 7e3c4e67f..b7af4e5fe 100644 --- a/src/Throwable/LoadingThrowable.php +++ b/src/Throwable/LoadingThrowable.php @@ -13,6 +13,8 @@ namespace Nelmio\Alice\Throwable; -interface LoadingThrowable +use Throwable; + +interface LoadingThrowable extends Throwable { } diff --git a/tests/Definition/Object/CompleteObjectTest.php b/tests/Definition/Object/CompleteObjectTest.php index 08f5aae2a..d633cc97b 100644 --- a/tests/Definition/Object/CompleteObjectTest.php +++ b/tests/Definition/Object/CompleteObjectTest.php @@ -18,6 +18,7 @@ use Nelmio\Alice\ObjectInterface; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; +use stdClass; /** * @covers \Nelmio\Alice\Definition\Object\CompleteObject @@ -129,6 +130,6 @@ public function testCannotCreateANewInstance() $this->expectException(\LogicException::class); $this->expectExceptionMessage('Cannot create a new object from a complete object.'); - $object->withInstance(null); + $object->withInstance(new stdClass()); } } diff --git a/tests/FixtureBuilder/Denormalizer/SimpleDenormalizerTestTest.php b/tests/FixtureBuilder/Denormalizer/SimpleDenormalizerTest.php similarity index 100% rename from tests/FixtureBuilder/Denormalizer/SimpleDenormalizerTestTest.php rename to tests/FixtureBuilder/Denormalizer/SimpleDenormalizerTest.php diff --git a/tests/Generator/Populator/SimpleHydratorTest.php b/tests/Generator/Populator/SimpleHydratorTest.php deleted file mode 100644 index 8326572f5..000000000 --- a/tests/Generator/Populator/SimpleHydratorTest.php +++ /dev/null @@ -1,268 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace Nelmio\Alice\Generator\Hydrator; - -use Nelmio\Alice\Definition\Fixture\SimpleFixture; -use Nelmio\Alice\Definition\MethodCallBag; -use Nelmio\Alice\Definition\Object\SimpleObject; -use Nelmio\Alice\Definition\Property; -use Nelmio\Alice\Definition\PropertyBag; -use Nelmio\Alice\Definition\SpecificationBag; -use Nelmio\Alice\Definition\Value\FakeObject; -use Nelmio\Alice\Definition\Value\FakeValue; -use Nelmio\Alice\FixtureBag; -use Nelmio\Alice\Generator\GenerationContext; -use Nelmio\Alice\Generator\HydratorInterface; -use Nelmio\Alice\Generator\ResolvedFixtureSet; -use Nelmio\Alice\Generator\ResolvedFixtureSetFactory; -use Nelmio\Alice\Generator\ResolvedValueWithFixtureSet; -use Nelmio\Alice\Generator\Resolver\Value\FakeValueResolver; -use Nelmio\Alice\Generator\ValueResolverInterface; -use Nelmio\Alice\ObjectBag; -use Nelmio\Alice\ParameterBag; -use Nelmio\Alice\Throwable\Exception\Generator\Resolver\ResolverNotFoundException; -use Nelmio\Alice\Throwable\Exception\RootResolutionException; -use Nelmio\Alice\Throwable\GenerationThrowable; -use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; - -/** - * @covers \Nelmio\Alice\Generator\Hydrator\SimpleHydrator - */ -class SimpleHydratorTest extends TestCase -{ - use ProphecyTrait; - - public function testIsAnHydrator() - { - $this->assertTrue(is_a(SimpleHydrator::class, HydratorInterface::class, true)); - } - - public function testIsValueResolverAware() - { - $this->assertEquals( - (new SimpleHydrator(new FakePropertyHydrator()))->withValueResolver(new FakeValueResolver()), - new SimpleHydrator(new FakePropertyHydrator(), new FakeValueResolver()) - ); - } - - public function testThrowsAnExceptionIfDoesNotHaveAResolver() - { - $hydrator = new SimpleHydrator(new FakePropertyHydrator()); - - $this->expectException(ResolverNotFoundException::class); - $this->expectExceptionMessage('Expected method "Nelmio\Alice\Generator\Hydrator\SimpleHydrator::hydrate" to be called only if it has a resolver.'); - - $hydrator->hydrate(new FakeObject(), ResolvedFixtureSetFactory::create(), new GenerationContext()); - } - - public function testAddsObjectToFixtureSet() - { - $object = new SimpleObject('dummy', new \stdClass()); - $set = ResolvedFixtureSetFactory::create( - null, - $fixtures = (new FixtureBag())->with( - new SimpleFixture( - 'dummy', - \stdClass::class, - new SpecificationBag( - null, - new PropertyBag(), - new MethodCallBag() - ) - ) - ) - ); - $expected = new ResolvedFixtureSet( - new ParameterBag(), - $fixtures, - new ObjectBag(['dummy' => $object]) - ); - - $hydrator = new SimpleHydrator(new FakePropertyHydrator(), new FakeValueResolver()); - $actual = $hydrator->hydrate($object, $set, new GenerationContext()); - - $this->assertEquals($expected, $actual); - } - - public function testHydratesObjectWithTheGivenProperties() - { - $object = new SimpleObject('dummy', new \stdClass()); - $set = ResolvedFixtureSetFactory::create( - null, - $fixtures = (new FixtureBag())->with( - new SimpleFixture( - 'dummy', - \stdClass::class, - new SpecificationBag( - null, - (new PropertyBag()) - ->with($username = new Property('username', 'Bob')) - ->with($group = new Property('group', 'Badass')), - new MethodCallBag() - ) - ) - ) - ); - $context = new GenerationContext(); - $context->markIsResolvingFixture('foo'); - - $hydratorProphecy = $this->prophesize(PropertyHydratorInterface::class); - $newInstance = new \stdClass(); - $newInstance->username = 'Bob'; - $newObject = $object->withInstance($newInstance); - $hydratorProphecy->hydrate($object, $username, $context)->willReturn($newObject); - - $secondNewInstance = clone $newInstance; - $secondNewInstance->group = 'Badass'; - $secondNewObject = $object->withInstance($secondNewInstance); - $hydratorProphecy->hydrate($newObject, $group, $context)->willReturn($secondNewObject); - /** @var PropertyHydratorInterface $hydrator */ - $hydrator = $hydratorProphecy->reveal(); - - $expected = new ResolvedFixtureSet( - new ParameterBag(), - $fixtures, - new ObjectBag(['dummy' => $secondNewObject]) - ); - - $hydrator = new SimpleHydrator($hydrator, new FakeValueResolver()); - $actual = $hydrator->hydrate($object, $set, $context); - - $this->assertEquals($expected, $actual); - - $hydratorProphecy->hydrate(Argument::cetera())->shouldHaveBeenCalledTimes(2); - } - - public function testResolvesAllPropertyValues() - { - $object = new SimpleObject('dummy', new \stdClass()); - $set = ResolvedFixtureSetFactory::create( - null, - $fixtures = (new FixtureBag())->with( - $fixture = new SimpleFixture( - 'dummy', - \stdClass::class, - new SpecificationBag( - null, - (new PropertyBag()) - ->with($username = new Property('username', $usernameValue = new FakeValue())) - ->with($group = new Property('group', $groupValue = new FakeValue())), - new MethodCallBag() - ) - ) - ) - ); - $context = new GenerationContext(); - $context->markIsResolvingFixture('foo'); - - $resolverProphecy = $this->prophesize(ValueResolverInterface::class); - $setAfterFirstResolution = ResolvedFixtureSetFactory::create(new ParameterBag(['iteration' => 1]), $fixtures); - $resolverProphecy - ->resolve( - $usernameValue, - $fixture, - $set, - [ - '_instances' => $set->getObjects()->toArray(), - ], - $context - ) - ->willReturn( - new ResolvedValueWithFixtureSet('Bob', $setAfterFirstResolution) - ) - ; - - $setAfterSecondResolution = ResolvedFixtureSetFactory::create(new ParameterBag(['iteration' => 2]), $fixtures); - $resolverProphecy - ->resolve( - $groupValue, - $fixture, - $setAfterFirstResolution, - [ - '_instances' => $set->getObjects()->toArray(), - 'username' => 'Bob', - ], - $context - ) - ->willReturn( - new ResolvedValueWithFixtureSet('Badass', $setAfterSecondResolution) - ) - ; - /** @var ValueResolverInterface $resolver */ - $resolver = $resolverProphecy->reveal(); - - $hydratorProphecy = $this->prophesize(PropertyHydratorInterface::class); - $newInstance = new \stdClass(); - $newInstance->username = 'Bob'; - $newObject = $object->withInstance($newInstance); - $hydratorProphecy->hydrate($object, $username->withValue('Bob'), $context)->willReturn($newObject); - - $secondNewInstance = clone $newInstance; - $secondNewInstance->group = 'Badass'; - $secondNewObject = $object->withInstance($secondNewInstance); - $hydratorProphecy->hydrate($newObject, $group->withValue('Badass'), $context)->willReturn($secondNewObject); - /** @var PropertyHydratorInterface $hydrator */ - $hydrator = $hydratorProphecy->reveal(); - - $expected = new ResolvedFixtureSet( - new ParameterBag(['iteration' => 2]), - $fixtures, - new ObjectBag(['dummy' => $secondNewObject]) - ); - - $hydrator = new SimpleHydrator($hydrator, $resolver); - $actual = $hydrator->hydrate($object, $set, $context); - - $this->assertEquals($expected, $actual); - } - - public function testThrowsAGenerationThrowableIfResolutionFails() - { - $object = new SimpleObject('dummy', new \stdClass()); - $set = ResolvedFixtureSetFactory::create( - null, - $fixtures = (new FixtureBag())->with( - $fixture = new SimpleFixture( - 'dummy', - \stdClass::class, - new SpecificationBag( - null, - (new PropertyBag()) - ->with(new Property('username', $usernameValue = new FakeValue())) - ->with(new Property('group', $groupValue = new FakeValue())), - new MethodCallBag() - ) - ) - ) - ); - - $resolverProphecy = $this->prophesize(ValueResolverInterface::class); - $resolverProphecy - ->resolve(Argument::cetera()) - ->willThrow(RootResolutionException::class) - ; - /** @var ValueResolverInterface $resolver */ - $resolver = $resolverProphecy->reveal(); - - $hydrator = new SimpleHydrator(new FakePropertyHydrator(), $resolver); - try { - $hydrator->hydrate($object, $set, new GenerationContext()); - $this->fail('Expected exception to be thrown.'); - } catch (GenerationThrowable $throwable) { - // Expected result - } - } -} diff --git a/tests/Generator/Resolver/Parameter/Chainable/StringParameterResolverTest.php b/tests/Generator/Resolver/Parameter/Chainable/StringParameterResolverTest.php index ed2132d5a..053bb0f38 100644 --- a/tests/Generator/Resolver/Parameter/Chainable/StringParameterResolverTest.php +++ b/tests/Generator/Resolver/Parameter/Chainable/StringParameterResolverTest.php @@ -11,11 +11,10 @@ declare(strict_types=1); -namespace Nelmio\Alice\Generator\Resolver\Parameter; +namespace Nelmio\Alice\Generator\Resolver\Parameter\Chainable; use Nelmio\Alice\Generator\Resolver\ChainableParameterResolverInterface; use Nelmio\Alice\Generator\Resolver\FakeParameterResolver; -use Nelmio\Alice\Generator\Resolver\Parameter\Chainable\StringParameterResolver; use Nelmio\Alice\Generator\Resolver\ParameterResolverAwareInterface; use Nelmio\Alice\Generator\Resolver\ParameterResolverInterface; use Nelmio\Alice\Generator\Resolver\ResolvingContext; diff --git a/tests/Generator/Resolver/Value/Chainable/FakerFunctionCallResolverValueTest.php b/tests/Generator/Resolver/Value/Chainable/FakerFunctionCallValueResolverValueTest.php similarity index 100% rename from tests/Generator/Resolver/Value/Chainable/FakerFunctionCallResolverValueTest.php rename to tests/Generator/Resolver/Value/Chainable/FakerFunctionCallValueResolverValueTest.php diff --git a/tests/Throwable/Error/TypeErrorFactoryTest.php b/tests/Throwable/Error/TypeErrorFactoryTest.php index 9773af178..91e3a3973 100644 --- a/tests/Throwable/Error/TypeErrorFactoryTest.php +++ b/tests/Throwable/Error/TypeErrorFactoryTest.php @@ -24,18 +24,6 @@ */ class TypeErrorFactoryTest extends TestCase { - public function testCreateForObjectArgument() - { - $error = TypeErrorFactory::createForObjectArgument(10); - - $this->assertEquals( - 'Expected instance argument to be an object. Got "integer" instead.', - $error->getMessage() - ); - $this->assertEquals(0, $error->getCode()); - $this->assertNull($error->getPrevious()); - } - public function testCreateForDynamicArrayQuantifier() { $error = TypeErrorFactory::createForDynamicArrayQuantifier(new stdClass()); diff --git a/tests/Throwable/Exception/FixtureBuilder/ExpressionLanguage/ExpressionLanguageExceptionFactoryFactoryTest.php b/tests/Throwable/Exception/FixtureBuilder/ExpressionLanguage/ExpressionLanguageExceptionFactoryTest.php similarity index 100% rename from tests/Throwable/Exception/FixtureBuilder/ExpressionLanguage/ExpressionLanguageExceptionFactoryFactoryTest.php rename to tests/Throwable/Exception/FixtureBuilder/ExpressionLanguage/ExpressionLanguageExceptionFactoryTest.php From cda58df50480a214aa9470311e6e87d2710012ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Fri, 15 May 2020 11:15:52 +0200 Subject: [PATCH 3/3] Fix test --- tests/Definition/Object/SimpleObjectTest.php | 21 -------------------- 1 file changed, 21 deletions(-) diff --git a/tests/Definition/Object/SimpleObjectTest.php b/tests/Definition/Object/SimpleObjectTest.php index e49394ab5..67e25da82 100644 --- a/tests/Definition/Object/SimpleObjectTest.php +++ b/tests/Definition/Object/SimpleObjectTest.php @@ -85,25 +85,4 @@ public function testNamedConstructor() $this->assertEquals(new SimpleObject($reference, $originalInstance), $object); $this->assertEquals(new SimpleObject($reference, $originalNewInstance), $newObject); } - - /** - * @dataProvider provideInvalidInstances - */ - public function testThrowsAnErrorIfInstanceIsNotAnObject($instance) - { - $this->expectException(\TypeError::class); - $this->expectExceptionMessageMatches('/^Expected instance argument to be an object. Got ".+?" instead\.$/'); - - new SimpleObject('user0', $instance); - } - - public function provideInvalidInstances() - { - return [ - 'null' => [null], - 'string' => ['string value'], - 'int' => [10], - 'float' => [1.01], - ]; - } }