From 1042d3112a79eb203acac008bdf0353cbbbbacf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Faugeron?= Date: Tue, 27 Jan 2026 07:37:21 +0000 Subject: [PATCH] chore: upgraded PHP to 8.0 and Memio to 3.0 _AI Disclosure_: used Claude Code (v2.1.20, Opus 4.5), to help with the Memio v3 upgrade. Prompts: ``` I'm trying to upgrade this lib to Memio v3, but running the tests fail: ``` // Running phpspec... Memio/SpecGen/Marshaller/Service/TypeGuesser 71 - it guesses phpspec doubles of implementations of many interfaces expected "Memio\SpecGen\Fixtures\Ty...", but got "Memio\SpecGen\Fixtures\Ty...". Memio/SpecGen/Marshaller/Service/TypeGuesser 76 - it guesses phpspec doubles of implementations of deep interfaces expected "Memio\SpecGen\Fixtures\Ty...", but got "Memio\SpecGen\Fixtures\Ty...". ``` You can run `make lib-qa` or `make phpspec` to check it yoursel ``` ``` now phpstan complains: ``` ------ ------------------------------------------------------------------ Line Memio/SpecGen/GenerateConstructor/GenerateConstructorHandler.php ------ ------------------------------------------------------------------ 57 Call to an undefined static method Memio\Model\Objekt::make(). 58 Call to an undefined static method Memio\Model\File::make(). ------ ------------------------------------------------------------------ ------ ---------------------------------------------------------------- Line Memio/SpecGen/GenerateMethod/GenerateMethodHandler.php ------ ---------------------------------------------------------------- 56 Call to an undefined static method Memio\Model\File::make(). 57 Call to an undefined static method Memio\Model\Objekt::make(). ------ ---------------------------------------------------------------- ``` You can run `make phpstan` to check it ``` ``` you can also check the UPGRADING or CHANGELOG in vendor/memio ``` --- Dockerfile | 4 +-- composer.json | 14 ++++---- .../CodeEditor/InsertMethodHandlerSpec.php | 15 ++++---- .../CodeEditor/InsertPropertyHandlerSpec.php | 35 ++++++++----------- .../InsertUseStatementHandlerSpec.php | 32 +++++++---------- .../InsertUseStatementsHandlerSpec.php | 10 +++--- ...InsertGeneratedConstructorListenerSpec.php | 24 ++++++------- .../LogGeneratedConstructorListenerSpec.php | 17 ++++----- .../InsertGeneratedMethodListenerSpec.php | 20 +++++------ .../LogGeneratedMethodListenerSpec.php | 13 +++---- .../Model/ArgumentCollectionSpec.php | 19 +++++----- .../Marshaller/Service/TypeGuesserSpec.php | 5 ++- .../VariableArgumentMarshallerSpec.php | 7 ++-- .../CodeEditor/InsertMethodHandler.php | 2 +- .../CodeEditor/InsertPropertyHandler.php | 2 +- .../CodeEditor/InsertUseStatementHandler.php | 4 +-- .../CodeEditor/InsertUseStatementsHandler.php | 2 +- .../GenerateConstructorHandler.php | 12 +++---- .../InsertGeneratedConstructorListener.php | 8 ++--- .../LogGeneratedConstructorListener.php | 6 ++-- .../GenerateMethod/GenerateMethodHandler.php | 8 ++--- .../InsertGeneratedMethodListener.php | 6 ++-- .../LogGeneratedMethodListener.php | 8 ++--- .../Marshaller/Model/ArgumentCollection.php | 4 +-- 24 files changed, 131 insertions(+), 146 deletions(-) diff --git a/Dockerfile b/Dockerfile index f6b78a9..ec3fe9e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ # PHP Dev Container # Utility Tools: PHP, bash, Composer ### -FROM php:7.2-cli AS php_dev_container +FROM php:8.0-cli AS php_dev_container # Composer environment variables: # * default user is superuser (root), so allow them @@ -15,7 +15,7 @@ ENV COMPOSER_ALLOW_SUPERUSER=1 \ # Update apt sources to use archived Debian repositories RUN sed -i 's/deb.debian.org/archive.debian.org/g' /etc/apt/sources.list \ - && sed -i 's/security.debian.org/archive.debian.org/g' /etc/apt/sources.list \ + && sed -i '/debian-security/d' /etc/apt/sources.list \ && sed -i '/stretch-updates/d' /etc/apt/sources.list # Install dependencies: diff --git a/composer.json b/composer.json index 5831b8e..6ceb747 100644 --- a/composer.json +++ b/composer.json @@ -26,13 +26,13 @@ }, "require": { "gnugat/redaktilo": "^2.0", - "memio/memio": "^2.0", - "memio/linter": "^2.0", - "memio/validator": "^2.0", - "memio/model": "^2.0.1", - "memio/pretty-printer": "^2.0", - "memio/twig-template-engine": "^2.0.1", - "php": "^7.2 || 8.0.*", + "memio/memio": "^3.0", + "memio/linter": "^3.0", + "memio/validator": "^3.0", + "memio/model": "^3.0", + "memio/pretty-printer": "^3.0", + "memio/twig-template-engine": "^3.0", + "php": "^8.0", "phpspec/phpspec": "^6.3", "symfony/event-dispatcher": "^5.0" }, diff --git a/spec/Memio/SpecGen/CodeEditor/InsertMethodHandlerSpec.php b/spec/Memio/SpecGen/CodeEditor/InsertMethodHandlerSpec.php index c9a7841..432615d 100644 --- a/spec/Memio/SpecGen/CodeEditor/InsertMethodHandlerSpec.php +++ b/spec/Memio/SpecGen/CodeEditor/InsertMethodHandlerSpec.php @@ -44,11 +44,10 @@ function it_supports_insert_method_command(InsertMethod $insertMethod) function it_does_not_insert_a_method_twice( Editor $editor, File $file, - Method $method, PrettyPrinter $prettyPrinter ) { - $insertMethod = new InsertMethod($file->getWrappedObject(), $method->getWrappedObject()); - $method->getName()->willReturn(self::METHOD_NAME); + $method = new Method(self::METHOD_NAME); + $insertMethod = new InsertMethod($file->getWrappedObject(), $method); $editor->hasBelow($file, self::METHOD_PATTERN, 0)->willReturn(true); $prettyPrinter->generateCode($method)->shouldNotBeCalled(); @@ -59,11 +58,10 @@ function it_does_not_insert_a_method_twice( function it_inserts_method_in_empty_class( Editor $editor, File $file, - Method $method, PrettyPrinter $prettyPrinter ) { - $insertMethod = new InsertMethod($file->getWrappedObject(), $method->getWrappedObject()); - $method->getName()->willReturn(self::METHOD_NAME); + $method = new Method(self::METHOD_NAME); + $insertMethod = new InsertMethod($file->getWrappedObject(), $method); $editor->hasBelow($file, self::METHOD_PATTERN, 0)->willReturn(false); $editor->jumpBelow($file, InsertMethodHandler::CLASS_ENDING, 0)->shouldBeCalled(); @@ -78,11 +76,10 @@ function it_inserts_method_in_empty_class( function it_inserts_method_in_class_with_stuff( Editor $editor, File $file, - Method $method, PrettyPrinter $prettyPrinter ) { - $insertMethod = new InsertMethod($file->getWrappedObject(), $method->getWrappedObject()); - $method->getName()->willReturn(self::METHOD_NAME); + $method = new Method(self::METHOD_NAME); + $insertMethod = new InsertMethod($file->getWrappedObject(), $method); $editor->hasBelow($file, self::METHOD_PATTERN, 0)->willReturn(false); $editor->jumpBelow($file, InsertMethodHandler::CLASS_ENDING, 0)->shouldBeCalled(); diff --git a/spec/Memio/SpecGen/CodeEditor/InsertPropertyHandlerSpec.php b/spec/Memio/SpecGen/CodeEditor/InsertPropertyHandlerSpec.php index 88d6fb2..e446c7d 100644 --- a/spec/Memio/SpecGen/CodeEditor/InsertPropertyHandlerSpec.php +++ b/spec/Memio/SpecGen/CodeEditor/InsertPropertyHandlerSpec.php @@ -40,11 +40,10 @@ function it_supports_insert_property_command(InsertProperty $insertProperty) function it_does_not_insert_a_property_twice( Editor $editor, File $file, - PrettyPrinter $prettyPrinter, - Property $property + PrettyPrinter $prettyPrinter ) { - $insertProperty = new InsertProperty($file->getWrappedObject(), $property->getWrappedObject()); - $property->getName()->willReturn('property'); + $property = new Property('property'); + $insertProperty = new InsertProperty($file->getWrappedObject(), $property); $editor->hasBelow($file, '/^ private \$property;$/', 0)->willReturn(true); $prettyPrinter->generateCode($property)->shouldNotBeCalled(); @@ -55,11 +54,10 @@ function it_does_not_insert_a_property_twice( function it_inserts_property_in_empty_class( Editor $editor, File $file, - PrettyPrinter $prettyPrinter, - Property $property + PrettyPrinter $prettyPrinter ) { - $insertProperty = new InsertProperty($file->getWrappedObject(), $property->getWrappedObject()); - $property->getName()->willReturn('property'); + $property = new Property('property'); + $insertProperty = new InsertProperty($file->getWrappedObject(), $property); $editor->hasBelow($file, '/^ private \$property;$/', 0)->willReturn(false); $editor->hasBelow($file, InsertPropertyHandler::PROPERTY, 0)->willReturn(false); @@ -76,11 +74,10 @@ function it_inserts_property_in_empty_class( function it_inserts_property_in_class_with_properties( Editor $editor, File $file, - PrettyPrinter $prettyPrinter, - Property $property + PrettyPrinter $prettyPrinter ) { - $insertProperty = new InsertProperty($file->getWrappedObject(), $property->getWrappedObject()); - $property->getName()->willReturn('property'); + $property = new Property('property'); + $insertProperty = new InsertProperty($file->getWrappedObject(), $property); $editor->hasBelow($file, '/^ private \$property;$/', 0)->willReturn(false); $editor->hasBelow($file, InsertPropertyHandler::PROPERTY, 0)->willReturn(true); @@ -99,11 +96,10 @@ function it_inserts_property_in_class_with_properties( function it_inserts_property_in_class_with_constants( Editor $editor, File $file, - PrettyPrinter $prettyPrinter, - Property $property + PrettyPrinter $prettyPrinter ) { - $insertProperty = new InsertProperty($file->getWrappedObject(), $property->getWrappedObject()); - $property->getName()->willReturn('property'); + $property = new Property('property'); + $insertProperty = new InsertProperty($file->getWrappedObject(), $property); $editor->hasBelow($file, '/^ private \$property;$/', 0)->willReturn(false); $editor->hasBelow($file, InsertPropertyHandler::PROPERTY, 0)->willReturn(false); @@ -122,11 +118,10 @@ function it_inserts_property_in_class_with_constants( function it_inserts_property_in_class_with_methods( Editor $editor, File $file, - PrettyPrinter $prettyPrinter, - Property $property + PrettyPrinter $prettyPrinter ) { - $insertProperty = new InsertProperty($file->getWrappedObject(), $property->getWrappedObject()); - $property->getName()->willReturn('property'); + $property = new Property('property'); + $insertProperty = new InsertProperty($file->getWrappedObject(), $property); $editor->hasBelow($file, '/^ private \$property;$/', 0)->willReturn(false); $editor->hasBelow($file, InsertPropertyHandler::PROPERTY, 0)->willReturn(false); diff --git a/spec/Memio/SpecGen/CodeEditor/InsertUseStatementHandlerSpec.php b/spec/Memio/SpecGen/CodeEditor/InsertUseStatementHandlerSpec.php index e506c9e..fef7ccf 100644 --- a/spec/Memio/SpecGen/CodeEditor/InsertUseStatementHandlerSpec.php +++ b/spec/Memio/SpecGen/CodeEditor/InsertUseStatementHandlerSpec.php @@ -44,12 +44,10 @@ function it_supports_insert_use_statement_command(InsertUseStatement $insertUseS function it_does_not_insert_use_statement_in_same_namespace( Editor $editor, - File $file, - FullyQualifiedName $fullyQualifiedName + File $file ) { - $insertUseStatement = new InsertUseStatement($file->getWrappedObject(), $fullyQualifiedName->getWrappedObject()); - $fullyQualifiedName->getNamespace()->willReturn(self::NAME_SPACE); - $fullyQualifiedName->getFullyQualifiedName()->willReturn(self::FULLY_QUALIFIED_NAME); + $fullyQualifiedName = new FullyQualifiedName(self::FULLY_QUALIFIED_NAME); + $insertUseStatement = new InsertUseStatement($file->getWrappedObject(), $fullyQualifiedName); $editor->hasBelow($file, self::NAME_SPACE_PATTERN, 0)->willReturn(true); $editor->insertBelow($file, self::USE_STATEMENT)->shouldNotBeCalled(); @@ -59,12 +57,10 @@ function it_does_not_insert_use_statement_in_same_namespace( function it_does_not_insert_use_statement_twice( Editor $editor, - File $file, - FullyQualifiedName $fullyQualifiedName + File $file ) { - $insertUseStatement = new InsertUseStatement($file->getWrappedObject(), $fullyQualifiedName->getWrappedObject()); - $fullyQualifiedName->getNamespace()->willReturn(self::NAME_SPACE); - $fullyQualifiedName->getFullyQualifiedName()->willReturn(self::FULLY_QUALIFIED_NAME); + $fullyQualifiedName = new FullyQualifiedName(self::FULLY_QUALIFIED_NAME); + $insertUseStatement = new InsertUseStatement($file->getWrappedObject(), $fullyQualifiedName); $editor->hasBelow($file, self::NAME_SPACE_PATTERN, 0)->willReturn(false); $editor->hasBelow($file, self::USE_STATEMENT_PATTERN, 0)->willReturn(true); @@ -75,12 +71,10 @@ function it_does_not_insert_use_statement_twice( function it_inserts_first_use_statement( Editor $editor, - File $file, - FullyQualifiedName $fullyQualifiedName + File $file ) { - $insertUseStatement = new InsertUseStatement($file->getWrappedObject(), $fullyQualifiedName->getWrappedObject()); - $fullyQualifiedName->getNamespace()->willReturn(self::NAME_SPACE); - $fullyQualifiedName->getFullyQualifiedName()->willReturn(self::FULLY_QUALIFIED_NAME); + $fullyQualifiedName = new FullyQualifiedName(self::FULLY_QUALIFIED_NAME); + $insertUseStatement = new InsertUseStatement($file->getWrappedObject(), $fullyQualifiedName); $editor->hasBelow($file, self::NAME_SPACE_PATTERN, 0)->willReturn(false); $editor->hasBelow($file, self::USE_STATEMENT_PATTERN, 0)->willReturn(false); @@ -95,12 +89,10 @@ function it_inserts_first_use_statement( function it_inserts_use_statement_at_the_end_of_use_statement_block( Editor $editor, - File $file, - FullyQualifiedName $fullyQualifiedName + File $file ) { - $insertUseStatement = new InsertUseStatement($file->getWrappedObject(), $fullyQualifiedName->getWrappedObject()); - $fullyQualifiedName->getNamespace()->willReturn(self::NAME_SPACE); - $fullyQualifiedName->getFullyQualifiedName()->willReturn(self::FULLY_QUALIFIED_NAME); + $fullyQualifiedName = new FullyQualifiedName(self::FULLY_QUALIFIED_NAME); + $insertUseStatement = new InsertUseStatement($file->getWrappedObject(), $fullyQualifiedName); $editor->hasBelow($file, self::NAME_SPACE_PATTERN, 0)->willReturn(false); $editor->hasBelow($file, self::USE_STATEMENT_PATTERN, 0)->willReturn(false); diff --git a/spec/Memio/SpecGen/CodeEditor/InsertUseStatementsHandlerSpec.php b/spec/Memio/SpecGen/CodeEditor/InsertUseStatementsHandlerSpec.php index 46d8990..39e650f 100644 --- a/spec/Memio/SpecGen/CodeEditor/InsertUseStatementsHandlerSpec.php +++ b/spec/Memio/SpecGen/CodeEditor/InsertUseStatementsHandlerSpec.php @@ -41,13 +41,12 @@ function it_supports_insert_use_statements_command(InsertUseStatements $insertUs function it_inserts_the_same_use_statement_once( Editor $editor, File $file, - FullyQualifiedName $fullyQualifiedName, InsertUseStatementHandler $insertUseStatementHandler ) { - $fullyQualifiedNames = [$fullyQualifiedName->getWrappedObject()]; + $fullyQualifiedName = new FullyQualifiedName('Vendor\Project\MyDependency'); + $fullyQualifiedNames = [$fullyQualifiedName]; $insertUseStatements = new InsertUseStatements($file->getWrappedObject(), $fullyQualifiedNames); - $fullyQualifiedName->getFullyQualifiedName()->willReturn('Vendor\Project\MyDependency'); $editor->hasBelow($file, '/^use Vendor\\\\Project\\\\MyDependency;$/', 0)->willReturn(false); $insertUseStatement = Argument::Type(InsertUseStatement::class); $insertUseStatementHandler->handle($insertUseStatement)->shouldBeCalled(); @@ -58,13 +57,12 @@ function it_inserts_the_same_use_statement_once( function it_does_not_insert_the_same_use_statement_twice( Editor $editor, File $file, - FullyQualifiedName $fullyQualifiedName, InsertUseStatementHandler $insertUseStatementHandler ) { - $fullyQualifiedNames = [$fullyQualifiedName->getWrappedObject()]; + $fullyQualifiedName = new FullyQualifiedName('Vendor\Project\MyDependency'); + $fullyQualifiedNames = [$fullyQualifiedName]; $insertUseStatements = new InsertUseStatements($file->getWrappedObject(), $fullyQualifiedNames); - $fullyQualifiedName->getFullyQualifiedName()->willReturn('Vendor\Project\MyDependency'); $editor->hasBelow($file, '/^use Vendor\\\\Project\\\\MyDependency;$/', 0)->willReturn(true); $insertUseStatement = Argument::Type(InsertUseStatement::class); $insertUseStatementHandler->handle($insertUseStatement)->shouldNotBeCalled(); diff --git a/spec/Memio/SpecGen/GenerateConstructor/InsertGeneratedConstructorListenerSpec.php b/spec/Memio/SpecGen/GenerateConstructor/InsertGeneratedConstructorListenerSpec.php index d3d427d..864dd7b 100644 --- a/spec/Memio/SpecGen/GenerateConstructor/InsertGeneratedConstructorListenerSpec.php +++ b/spec/Memio/SpecGen/GenerateConstructor/InsertGeneratedConstructorListenerSpec.php @@ -38,23 +38,23 @@ function let(CodeEditor $codeEditor) function it_inserts_the_generated_method( CodeEditor $codeEditor, - File $file, - FileModel $fileModel, - FullyQualifiedNameModel $fullyQualifiedNameModel, - MethodModel $methodModel, - ObjectModel $objectModel, - PropertyModel $propertyModel + File $file ) { $insertUseStatements = Argument::type(InsertUseStatements::class); $insertProperties = Argument::type(InsertProperties::class); $insertConstructor = Argument::type(InsertConstructor::class); - $generatedConstructor = new GeneratedConstructor($fileModel->getWrappedObject()); - $fileModel->allFullyQualifiedNames()->willReturn([$fullyQualifiedNameModel]); - $fileModel->getFilename()->willReturn(self::FILE_NAME); - $fileModel->getStructure()->willReturn($objectModel); - $objectModel->allProperties()->willReturn([$propertyModel]); - $objectModel->allMethods()->willReturn([$methodModel]); + $fullyQualifiedName = new FullyQualifiedNameModel('Vendor\Project\MyClass'); + $method = new MethodModel(self::METHOD_NAME); + $property = new PropertyModel('myProperty'); + $object = (new ObjectModel('Vendor\Project\MyClass')) + ->addMethod($method) + ->addProperty($property); + $fileModel = (new FileModel(self::FILE_NAME)) + ->addFullyQualifiedName($fullyQualifiedName) + ->setStructure($object); + + $generatedConstructor = new GeneratedConstructor($fileModel); $codeEditor->open(self::FILE_NAME)->willReturn($file); $codeEditor->handle($insertUseStatements)->shouldBeCalled(); diff --git a/spec/Memio/SpecGen/GenerateConstructor/LogGeneratedConstructorListenerSpec.php b/spec/Memio/SpecGen/GenerateConstructor/LogGeneratedConstructorListenerSpec.php index cd49b68..dfb3582 100644 --- a/spec/Memio/SpecGen/GenerateConstructor/LogGeneratedConstructorListenerSpec.php +++ b/spec/Memio/SpecGen/GenerateConstructor/LogGeneratedConstructorListenerSpec.php @@ -30,17 +30,18 @@ function let(ConsoleIO $io) $this->beConstructedWith($io); } - function it_logs_the_generated_constructor(File $file, ConsoleIO $io, Method $method, Objekt $object, Property $property) + function it_logs_the_generated_constructor(ConsoleIO $io) { - $generatedConstructor = new GeneratedConstructor($file->getWrappedObject()); - $file->getStructure()->willReturn($object); - $object->getName()->willReturn(self::CLASS_NAME); - $object->allProperties()->willReturn([$property]); - $object->allMethods()->willReturn([$method]); - $method->getName()->willReturn(self::METHOD_NAME); + $method = new Method(self::METHOD_NAME); + $property = new Property('myProperty'); + $object = (new Objekt('Vendor\Project\\'.self::CLASS_NAME)) + ->addMethod($method) + ->addProperty($property); + $file = (new File('/tmp/test.php'))->setStructure($object); + + $generatedConstructor = new GeneratedConstructor($file); $className = self::CLASS_NAME; - $methodName = self::METHOD_NAME; $propertiesCount = self::PROPERTIES_COUNT; $io->write(<<getWrappedObject()); - $fileModel->allFullyQualifiedNames()->willReturn([$fullyQualifiedNameModel]); - $fileModel->getFilename()->willReturn(self::FILE_NAME); - $fileModel->getStructure()->willReturn($objectModel); - $objectModel->allMethods()->willReturn([$methodModel]); + $fullyQualifiedName = new FullyQualifiedNameModel('Vendor\Project\MyClass'); + $method = new MethodModel(self::METHOD_NAME); + $object = (new ObjectModel('Vendor\Project\MyClass')) + ->addMethod($method); + $fileModel = (new FileModel(self::FILE_NAME)) + ->addFullyQualifiedName($fullyQualifiedName) + ->setStructure($object); + + $generatedMethod = new GeneratedMethod($fileModel); $codeEditor->open(self::FILE_NAME)->willReturn($file); $codeEditor->handle($insertUseStatements)->shouldBeCalled(); diff --git a/spec/Memio/SpecGen/GenerateMethod/LogGeneratedMethodListenerSpec.php b/spec/Memio/SpecGen/GenerateMethod/LogGeneratedMethodListenerSpec.php index c2e3139..b142d6f 100644 --- a/spec/Memio/SpecGen/GenerateMethod/LogGeneratedMethodListenerSpec.php +++ b/spec/Memio/SpecGen/GenerateMethod/LogGeneratedMethodListenerSpec.php @@ -28,13 +28,14 @@ function let(ConsoleIO $io) $this->beConstructedWith($io); } - function it_logs_the_generated_method(File $file, ConsoleIO $io, Method $method, Objekt $object) + function it_logs_the_generated_method(ConsoleIO $io) { - $generatedMethod = new GeneratedMethod($file->getWrappedObject()); - $file->getStructure()->willReturn($object); - $object->getName()->willReturn(self::CLASS_NAME); - $object->allMethods()->willReturn([$method]); - $method->getName()->willReturn(self::METHOD_NAME); + $method = new Method(self::METHOD_NAME); + $object = (new Objekt('Vendor\Project\\'.self::CLASS_NAME)) + ->addMethod($method); + $file = (new File('/tmp/test.php'))->setStructure($object); + + $generatedMethod = new GeneratedMethod($file); $className = self::CLASS_NAME; $methodName = self::METHOD_NAME; diff --git a/spec/Memio/SpecGen/Marshaller/Model/ArgumentCollectionSpec.php b/spec/Memio/SpecGen/Marshaller/Model/ArgumentCollectionSpec.php index efb6ca1..378587e 100644 --- a/spec/Memio/SpecGen/Marshaller/Model/ArgumentCollectionSpec.php +++ b/spec/Memio/SpecGen/Marshaller/Model/ArgumentCollectionSpec.php @@ -13,6 +13,7 @@ use Memio\Model\Argument; use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\Assert; class ArgumentCollectionSpec extends ObjectBehavior { @@ -20,11 +21,11 @@ function it_can_have_arguments() { $this->add('string', 'argument'); - $arguments = $this->all(); + $arguments = $this->all()->getWrappedObject(); $stringArgument = $arguments[0]; - $stringArgument->shouldHaveType(Argument::class); - $stringArgument->getType()->shouldBe('string'); - $stringArgument->getName()->shouldBe('argument'); + Assert::assertInstanceOf(Argument::class, $stringArgument); + Assert::assertSame('string', $stringArgument->type->name); + Assert::assertSame('argument', $stringArgument->name); } function it_prevents_name_duplication() @@ -32,10 +33,10 @@ function it_prevents_name_duplication() $this->add('array', 'argument'); $this->add('string', 'argument'); - $arguments = $this->all(); - $stringArgument = $arguments[0]; - $stringArgument->getName()->shouldBe('argument1'); - $arrayArgument = $arguments[1]; - $arrayArgument->getName()->shouldBe('argument2'); + $arguments = $this->all()->getWrappedObject(); + $firstArgument = $arguments[0]; + Assert::assertSame('argument1', $firstArgument->name); + $secondArgument = $arguments[1]; + Assert::assertSame('argument2', $secondArgument->name); } } diff --git a/spec/Memio/SpecGen/Marshaller/Service/TypeGuesserSpec.php b/spec/Memio/SpecGen/Marshaller/Service/TypeGuesserSpec.php index e2631cd..54bfc63 100644 --- a/spec/Memio/SpecGen/Marshaller/Service/TypeGuesserSpec.php +++ b/spec/Memio/SpecGen/Marshaller/Service/TypeGuesserSpec.php @@ -14,7 +14,6 @@ use Memio\SpecGen\Fixtures\Types\DeepImplementation; use Memio\SpecGen\Fixtures\Types\DeepInterface; use Memio\SpecGen\Fixtures\Types\NoParents; -use Memio\SpecGen\Fixtures\Types\OtherInterface; use Memio\SpecGen\Fixtures\Types\SomeAndOtherImplementation; use Memio\SpecGen\Fixtures\Types\SomeImplementation; use Memio\SpecGen\Fixtures\Types\SomeInterface; @@ -70,11 +69,11 @@ function it_guesses_phpspec_doubles_of_implementations_of_an_interface(SomeImple function it_guesses_phpspec_doubles_of_implementations_of_many_interfaces(SomeAndOtherImplementation $someAndOtherImplementation) { - $this->guess($someAndOtherImplementation)->shouldBe(OtherInterface::class); + $this->guess($someAndOtherImplementation)->shouldBe(SomeInterface::class); } function it_guesses_phpspec_doubles_of_implementations_of_deep_interfaces(DeepImplementation $deepImplementation) { - $this->guess($deepImplementation)->shouldBe(SomeInterface::class); + $this->guess($deepImplementation)->shouldBe(DeepInterface::class); } } diff --git a/spec/Memio/SpecGen/Marshaller/VariableArgumentMarshallerSpec.php b/spec/Memio/SpecGen/Marshaller/VariableArgumentMarshallerSpec.php index 228e5c2..f2ff7b9 100644 --- a/spec/Memio/SpecGen/Marshaller/VariableArgumentMarshallerSpec.php +++ b/spec/Memio/SpecGen/Marshaller/VariableArgumentMarshallerSpec.php @@ -14,6 +14,7 @@ use Memio\SpecGen\Marshaller\Service\NameGuesser; use Memio\SpecGen\Marshaller\Service\TypeGuesser; use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\Assert; class VariableArgumentMarshallerSpec extends ObjectBehavior { @@ -33,9 +34,9 @@ function it_converts_array_of_variables_into_array_of_arguments(NameGuesser $nam $typeGuesser->guess($variable)->willReturn(self::ARGUMENT_TYPE); $nameGuesser->guess(self::ARGUMENT_TYPE)->willReturn(self::ARGUMENT_NAME); - $arguments = $this->marshal($variables); + $arguments = $this->marshal($variables)->getWrappedObject(); $argument = $arguments[0]; - $argument->getType()->shouldBe(self::ARGUMENT_TYPE); - $argument->getName()->shouldBe(self::ARGUMENT_NAME); + Assert::assertSame(self::ARGUMENT_TYPE, $argument->type->name); + Assert::assertSame(self::ARGUMENT_NAME, $argument->name); } } diff --git a/src/Memio/SpecGen/CodeEditor/InsertMethodHandler.php b/src/Memio/SpecGen/CodeEditor/InsertMethodHandler.php index 4581e07..c810845 100644 --- a/src/Memio/SpecGen/CodeEditor/InsertMethodHandler.php +++ b/src/Memio/SpecGen/CodeEditor/InsertMethodHandler.php @@ -36,7 +36,7 @@ public function supports(Command $command): bool public function handle(Command $command): void { - $methodPattern = '/^ public function '.$command->method->getName().'\(/'; + $methodPattern = '/^ public function '.$command->method->name.'\(/'; if ($this->editor->hasBelow($command->file, $methodPattern, 0)) { return; } diff --git a/src/Memio/SpecGen/CodeEditor/InsertPropertyHandler.php b/src/Memio/SpecGen/CodeEditor/InsertPropertyHandler.php index 08ef98d..cf67e86 100644 --- a/src/Memio/SpecGen/CodeEditor/InsertPropertyHandler.php +++ b/src/Memio/SpecGen/CodeEditor/InsertPropertyHandler.php @@ -39,7 +39,7 @@ public function supports(Command $command): bool public function handle(Command $command): void { - $propertyStatement = '/^ private \$'.$command->property->getName().';$/'; + $propertyStatement = '/^ private \$'.$command->property->name.';$/'; if ($this->editor->hasBelow($command->file, $propertyStatement, 0)) { return; } diff --git a/src/Memio/SpecGen/CodeEditor/InsertUseStatementHandler.php b/src/Memio/SpecGen/CodeEditor/InsertUseStatementHandler.php index 339190e..1ff0890 100644 --- a/src/Memio/SpecGen/CodeEditor/InsertUseStatementHandler.php +++ b/src/Memio/SpecGen/CodeEditor/InsertUseStatementHandler.php @@ -35,8 +35,8 @@ public function supports(Command $command): bool public function handle(Command $command): void { - $namespace = $command->fullyQualifiedName->getNamespace(); - $fullyQualifiedName = $command->fullyQualifiedName->getFullyQualifiedName(); + $namespace = $command->fullyQualifiedName->namespace; + $fullyQualifiedName = $command->fullyQualifiedName->fullyQualifiedName; $namespacePattern = '/^namespace '.addslashes($namespace).';$/'; $useStatementPattern = '/^use '.addslashes($fullyQualifiedName).';$/'; if ($this->editor->hasBelow($command->file, $namespacePattern, 0) || $this->editor->hasBelow($command->file, $useStatementPattern, 0)) { diff --git a/src/Memio/SpecGen/CodeEditor/InsertUseStatementsHandler.php b/src/Memio/SpecGen/CodeEditor/InsertUseStatementsHandler.php index ed129c3..1382346 100644 --- a/src/Memio/SpecGen/CodeEditor/InsertUseStatementsHandler.php +++ b/src/Memio/SpecGen/CodeEditor/InsertUseStatementsHandler.php @@ -36,7 +36,7 @@ public function supports(Command $command): bool public function handle(Command $command): void { foreach ($command->fullyQualifiedNames as $fullyQualifiedName) { - $escapedFullyQualifiedClassName = addslashes($fullyQualifiedName->getFullyQualifiedName()); + $escapedFullyQualifiedClassName = addslashes($fullyQualifiedName->fullyQualifiedName); if (!$this->editor->hasBelow($command->file, "/^use $escapedFullyQualifiedClassName;$/", 0)) { $this->insertUseStatementHandler->handle(new InsertUseStatement($command->file, $fullyQualifiedName)); } diff --git a/src/Memio/SpecGen/GenerateConstructor/GenerateConstructorHandler.php b/src/Memio/SpecGen/GenerateConstructor/GenerateConstructorHandler.php index 693faea..bf4bd6b 100644 --- a/src/Memio/SpecGen/GenerateConstructor/GenerateConstructorHandler.php +++ b/src/Memio/SpecGen/GenerateConstructor/GenerateConstructorHandler.php @@ -54,19 +54,19 @@ public function supports(Command $command): bool public function handle(Command $command): void { $method = new Method($command->methodName); - $object = Objekt::make($command->fullyQualifiedName)->addMethod($method); - $file = File::make($command->fileName)->setStructure($object); + $object = (new Objekt($command->fullyQualifiedName))->addMethod($method); + $file = (new File($command->fileName))->setStructure($object); $arguments = $this->variableArgumentMarshaller->marshal($command->arguments); foreach ($arguments as $argument) { - $argumentType = $argument->getType(); - $argumentName = $argument->getName(); + $argumentType = $argument->type->name; + $argumentName = $argument->name; $fullyQualifiedName = new FullyQualifiedName($argumentType); if ($this->shouldAddUseStatement($file, $fullyQualifiedName)) { $file->addFullyQualifiedName($fullyQualifiedName); } $object->addProperty(new Property($argumentName)); $method->addArgument($argument); - $body = $method->getBody(); + $body = $method->body; if (!empty($body)) { $body .= "\n"; } @@ -82,7 +82,7 @@ public function handle(Command $command): void private function shouldAddUseStatement(File $file, FullyQualifiedName $fullyQualifiedName): bool { - $type = $fullyQualifiedName->getFullyQualifiedName(); + $type = $fullyQualifiedName->fullyQualifiedName; if (in_array($type, self::NON_OBJECT_TYPES, true)) { return false; } diff --git a/src/Memio/SpecGen/GenerateConstructor/InsertGeneratedConstructorListener.php b/src/Memio/SpecGen/GenerateConstructor/InsertGeneratedConstructorListener.php index 8bb8619..6cad6be 100644 --- a/src/Memio/SpecGen/GenerateConstructor/InsertGeneratedConstructorListener.php +++ b/src/Memio/SpecGen/GenerateConstructor/InsertGeneratedConstructorListener.php @@ -38,10 +38,10 @@ public function __construct(CodeEditor $codeEditor) public function onGeneratedConstructor( GeneratedConstructor $generatedConstructor ): void { - $fileName = $generatedConstructor->file->getFilename(); - $fullyQualifiedNames = $generatedConstructor->file->allFullyQualifiedNames(); - $allMethods = $generatedConstructor->file->getStructure()->allMethods(); - $allProperties = $generatedConstructor->file->getStructure()->allProperties(); + $fileName = $generatedConstructor->file->filename; + $fullyQualifiedNames = $generatedConstructor->file->fullyQualifiedNames; + $allMethods = $generatedConstructor->file->structure->methods; + $allProperties = $generatedConstructor->file->structure->properties; $method = array_shift($allMethods); // $object should contain only one method, the generated one. $file = $this->codeEditor->open($fileName); diff --git a/src/Memio/SpecGen/GenerateConstructor/LogGeneratedConstructorListener.php b/src/Memio/SpecGen/GenerateConstructor/LogGeneratedConstructorListener.php index fe8e679..87b8ca8 100644 --- a/src/Memio/SpecGen/GenerateConstructor/LogGeneratedConstructorListener.php +++ b/src/Memio/SpecGen/GenerateConstructor/LogGeneratedConstructorListener.php @@ -32,9 +32,9 @@ public function __construct(IO $io) public function onGeneratedConstructor( GeneratedConstructor $generatedConstructor ): void { - $object = $generatedConstructor->file->getStructure(); - $className = $object->getName(); - $propertiesCount = count($object->allProperties()); + $object = $generatedConstructor->file->structure; + $className = $object->fullyQualifiedName->name; + $propertiesCount = count($object->properties); $propertiesWord = (1 === $propertiesCount ? 'property' : 'properties'); $this->io->write(<<methodName); - $file = File::make($command->fileName) - ->setStructure(Objekt::make($command->fullyQualifiedName) + $file = (new File($command->fileName)) + ->setStructure((new Objekt($command->fullyQualifiedName)) ->addMethod($method) ) ; $arguments = $this->variableArgumentMarshaller->marshal($command->arguments); foreach ($arguments as $argument) { - $fullyQualifiedName = new FullyQualifiedName($argument->getType()); + $fullyQualifiedName = new FullyQualifiedName($argument->type->name); if ($this->shouldAddUseStatement($file, $fullyQualifiedName)) { $file->addFullyQualifiedName($fullyQualifiedName); } @@ -75,7 +75,7 @@ public function handle(Command $command): void private function shouldAddUseStatement(File $file, FullyQualifiedName $fullyQualifiedName): bool { - $type = $fullyQualifiedName->getFullyQualifiedName(); + $type = $fullyQualifiedName->fullyQualifiedName; if (in_array($type, self::NON_OBJECT_TYPES, true)) { return false; } diff --git a/src/Memio/SpecGen/GenerateMethod/InsertGeneratedMethodListener.php b/src/Memio/SpecGen/GenerateMethod/InsertGeneratedMethodListener.php index e2add43..ebb96ab 100644 --- a/src/Memio/SpecGen/GenerateMethod/InsertGeneratedMethodListener.php +++ b/src/Memio/SpecGen/GenerateMethod/InsertGeneratedMethodListener.php @@ -35,9 +35,9 @@ public function __construct(CodeEditor $codeEditor) public function onGeneratedMethod(GeneratedMethod $generatedMethod): void { - $fileName = $generatedMethod->file->getFilename(); - $fullyQualifiedNames = $generatedMethod->file->allFullyQualifiedNames(); - $allMethods = $generatedMethod->file->getStructure()->allMethods(); + $fileName = $generatedMethod->file->filename; + $fullyQualifiedNames = $generatedMethod->file->fullyQualifiedNames; + $allMethods = $generatedMethod->file->structure->methods; $method = array_shift($allMethods); // $object should contain only one method, the generated one. $file = $this->codeEditor->open($fileName); diff --git a/src/Memio/SpecGen/GenerateMethod/LogGeneratedMethodListener.php b/src/Memio/SpecGen/GenerateMethod/LogGeneratedMethodListener.php index 9464c91..5dc32b4 100644 --- a/src/Memio/SpecGen/GenerateMethod/LogGeneratedMethodListener.php +++ b/src/Memio/SpecGen/GenerateMethod/LogGeneratedMethodListener.php @@ -31,11 +31,11 @@ public function __construct(IO $io) public function onGeneratedMethod(GeneratedMethod $generatedMethod) { - $object = $generatedMethod->file->getStructure(); - $className = $object->getName(); - $methods = $object->allMethods(); + $object = $generatedMethod->file->structure; + $className = $object->fullyQualifiedName->name; + $methods = $object->methods; $method = array_shift($methods); // $object should contain only one method, the generated one. - $methodName = $method->getName(); + $methodName = $method->name; $this->io->write(<<arguments); for ($i = 0; $i < $argumentsCount; ++$i) { $argument = $this->arguments[$i]; - if ($argument->getName() === $name) { - $this->arguments[$i] = new Argument($argument->getType(), $name.'1'); + if ($argument->name === $name) { + $this->arguments[$i] = new Argument($argument->type->name, $name.'1'); break; } }