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); $editor->hasBelow($file, self::METHOD_PATTERN, 0)->willReturn(false); $editor->jumpBelow($file, InsertMethodHandler::CLASS_ENDING, 0)->shouldBeCalled(); $file->decrementCurrentLineNumber(1)->shouldBeCalled(); $file->getLine()->willReturn(' }'); $editor->insertBelow($file, '')->shouldBeCalled(); $prettyPrinter->generateCode($method)->willReturn(self::GENERATED_CODE); $editor->insertBelow($file, self::GENERATED_CODE)->shouldBeCalled(); $this->handle($insertMethod); }
function it_inserts_use_statement_at_the_end_of_use_statement_block(Editor $editor, File $file, FullyQualifiedName $fullyQualifiedName) { $insertUseStatement = new InsertUseStatement($file->getWrappedObject(), $fullyQualifiedName->getWrappedObject()); $fullyQualifiedName->getNamespace()->willReturn(self::NAME_SPACE); $fullyQualifiedName->getFullyQualifiedName()->willReturn(self::FULLY_QUALIFIED_NAME); $editor->hasBelow($file, self::NAME_SPACE_PATTERN, 0)->willReturn(false); $editor->hasBelow($file, self::USE_STATEMENT_PATTERN, 0)->willReturn(false); $editor->jumpBelow($file, InsertUseStatementHandler::CLASS_ENDING, 0)->shouldBeCalled(); $editor->hasAbove($file, InsertUseStatementHandler::USE_STATEMENT)->willReturn(true); $editor->jumpAbove($file, InsertUseStatementHandler::USE_STATEMENT)->shouldBeCalled(); $editor->insertBelow($file, self::USE_STATEMENT)->shouldBeCalled(); $this->handle($insertUseStatement); }
function it_inserts_constructor_in_class_with_methods_and_other_stuff(Editor $editor, File $file, Method $method, PrettyPrinter $prettyPrinter) { $insertConstructor = new InsertConstructor($file->getWrappedObject(), $method->getWrappedObject()); $editor->hasBelow($file, InsertConstructorHandler::CONSTRUCTOR, 0)->willReturn(false); $editor->hasBelow($file, InsertConstructorHandler::METHOD, 0)->willReturn(true); $editor->jumpBelow($file, InsertConstructorHandler::METHOD, 0)->shouldBeCalled(); $editor->insertAbove($file, '')->shouldBeCalled(); $prettyPrinter->generateCode($method)->willReturn(self::GENERATED_CODE); $editor->insertAbove($file, self::GENERATED_CODE)->shouldBeCalled(); $file->decrementCurrentLineNumber(1)->shouldBeCalled(); $file->getLine()->willReturn(' const CONSTANT = 42;'); $editor->insertBelow($file, '')->shouldBeCalled(); $this->handle($insertConstructor); }
function it_inserts_property_in_class_with_methods(Editor $editor, File $file, PrettyPrinter $prettyPrinter, Property $property) { $insertProperty = new InsertProperty($file->getWrappedObject(), $property->getWrappedObject()); $property->getName()->willReturn('property'); $editor->hasBelow($file, '/^ private \\$property;$/', 0)->willReturn(false); $editor->hasBelow($file, InsertPropertyHandler::PROPERTY, 0)->willReturn(false); $editor->hasBelow($file, InsertPropertyHandler::CONSTANT, 0)->willReturn(false); $editor->jumpBelow($file, InsertPropertyHandler::CLASS_OPENING, 0)->shouldBeCalled(); $prettyPrinter->generateCode($property)->willReturn(' private $property;'); $editor->insertBelow($file, ' private $property;')->shouldBeCalled(); $file->incrementCurrentLineNumber(1)->shouldBeCalled(); $file->getLine()->willReturn(' public function __construct($property)'); $editor->insertAbove($file, '')->shouldBeCalled(); $this->handle($insertProperty); }