Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
15 changes: 6 additions & 9 deletions spec/Memio/SpecGen/CodeEditor/InsertMethodHandlerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down
35 changes: 15 additions & 20 deletions spec/Memio/SpecGen/CodeEditor/InsertPropertyHandlerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
32 changes: 12 additions & 20 deletions spec/Memio/SpecGen/CodeEditor/InsertUseStatementHandlerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
10 changes: 4 additions & 6 deletions spec/Memio/SpecGen/CodeEditor/InsertUseStatementsHandlerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(<<<OUTPUT

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ function let(CodeEditor $codeEditor)

function it_inserts_the_generated_method(
CodeEditor $codeEditor,
File $file,
FileModel $fileModel,
FullyQualifiedNameModel $fullyQualifiedNameModel,
MethodModel $methodModel,
ObjectModel $objectModel
File $file
) {
$insertUseStatements = Argument::type(InsertUseStatements::class);
$insertMethod = Argument::type(InsertMethod::class);

$generatedMethod = new GeneratedMethod($fileModel->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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading
Loading