function it_needs_line_after_deprecation_if_deprecation_and_api_are_defined(ApiTag $apiTag, Description $description, DeprecationTag $deprecationTag, StructurePhpdoc $structurePhpdoc)
 {
     $structurePhpdoc->getApiTag()->willReturn($apiTag);
     $structurePhpdoc->getDescription()->willReturn($description);
     $structurePhpdoc->getDeprecationTag()->willReturn($deprecationTag);
     $this->needsLineAfter($structurePhpdoc, 'deprecation_tag')->shouldBe(true);
 }
    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $model = $input->getArgument('model');
        $outputFile = sprintf('%s.php', $this->joinPaths($input->getOption('output'), str_replace('\\', DIRECTORY_SEPARATOR, $model)));
        $classObject = Object::make($model);
        $file = File::make($outputFile)->setStructure($classObject);
        $file->addFullyQualifiedName(FullyQualifiedName::make('Doctrine\\ODM\\MongoDB\\Mapping\\Annotations as ODM'));
        $file->addFullyQualifiedName(FullyQualifiedName::make('Hive\\Annotations as H'));
        $fields = array_merge(['id:id'], $input->getArgument('fields'));
        foreach ($fields as $field) {
            if (!preg_match('/(\\w+)(?::(string|boolean|id|reference[s]?)(?:\\[([\\w\\\\]+),(\\w+)\\])?)?(?::(\\w+))?/i', $field, $matches)) {
                continue;
            }
            @(list($all, $name, $type, $referenceType, $linkProperty, $fake) = $matches);
            /** @var Property $property */
            $property = Property::make($name);
            $property->makePublic();
            $property->setPhpdoc(new ODMPropertyPhpdoc($name, $type, $referenceType, $linkProperty, $fake));
            $classObject->addProperty($property);
        }
        $classObject->setPhpdoc(StructurePhpdoc::make()->setDescription(Description::make(<<<'EOF'
This class is generated with the hive console.

@ODM\Document @ODM\HasLifecycleCallbacks
EOF
)));
        $classObject->addMethod(Method::make('validate')->setPhpdoc(MethodPhpdoc::make()->setDescription(Description::make(<<<'EOF'
The validate method can be used to validate properties.

@ODM\PrePersist @ODM\PreUpdate
EOF
))));
        // Generate the code
        $prettyPrinter = Build::prettyPrinter();
        $prettyPrinter->addTemplatePath(realpath($this->joinPaths(dirname(__FILE__), '../../../templates/memio/')));
        $generatedCode = $prettyPrinter->generateCode($file);
        @mkdir(dirname($outputFile), 0755, true);
        file_put_contents($outputFile, html_entity_decode(html_entity_decode($generatedCode)));
        $io = new SymfonyStyle($input, $output);
        $io->success(["Model {$model} created in {$outputFile}"]);
    }
Example #3
0
 public function testWithPhpdoc()
 {
     $object = Contract::make(self::NAME)->setPhpdoc(StructurePhpdoc::make()->setDescription(Description::make('Short description')->addEmptyLine()->addLine('Longer description'))->setDeprecationTag(new DeprecationTag('v2.1', 'Use Object instead'))->setApiTag(new ApiTag('v2.0')));
     $generatedCode = $this->prettyPrinter->generateCode($object);
     $this->assertExpectedCode($generatedCode);
 }
 public function testFull()
 {
     $structurePhpdoc = StructurePhpdoc::make()->setDescription(Description::make('Short description')->addEmptyLine()->addLine('Longer description'))->setDeprecationTag(new DeprecationTag('v2.1', 'Use Object instead'))->setApiTag(new ApiTag('v2.0'));
     $generatedCode = $this->prettyPrinter->generateCode($structurePhpdoc);
     $this->assertExpectedCode($generatedCode);
 }