Esempio n. 1
0
    public function testWriteDocBlock()
    {
        $this->class->setDescription("My\n\n  Doc\n    Block");
        $this->writer->writeClass($this->class);
        $expected = <<<EOF
<?php

/**
 * My
 *
 *   Doc
 *     Block
 */
class MyClass
{
}

EOF;
        $this->assertFileSame($expected, $this->tempDir . '/MyClass.php');
    }
Esempio n. 2
0
    /**
     * {@inheritdoc}
     */
    public function generateFactoryClass($path = null, $className = null)
    {
        Assert::nullOrStringNotEmpty($path, 'The path to the generated factory file must be a non-empty string or null. Got: %s');
        Assert::nullOrStringNotEmpty($className, 'The class name of the generated factory must be a non-empty string or null. Got: %s');
        $path = Path::makeAbsolute($path ?: $this->config->get(Config::FACTORY_OUT_FILE), $this->rootDir);
        $className = $className ?: $this->config->get(Config::FACTORY_OUT_CLASS);
        $dispatcher = $this->context->getEventDispatcher();
        $class = new Clazz($className);
        $class->setFilePath($path);
        $class->setDescription(<<<'EOF'
Creates Puli's core services.

This class was auto-generated by Puli.

IMPORTANT: Before modifying the code below, set the "factory.auto-generate"
configuration key to false:

    $ puli config factory.auto-generate false

Otherwise any modifications will be overwritten!
EOF
);
        $this->addCreateRepositoryMethod($class);
        $this->addCreateDiscoveryMethod($class);
        $this->addCreateUrlGeneratorMethod($class);
        $this->addGetModuleOrderMethod($class);
        if ($dispatcher->hasListeners(PuliEvents::GENERATE_FACTORY)) {
            $dispatcher->dispatch(PuliEvents::GENERATE_FACTORY, new GenerateFactoryEvent($class));
        }
        $this->classWriter->writeClass($class);
    }
Esempio n. 3
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testSetDescriptionFailsIfNoString()
 {
     $this->class->setDescription(1234);
 }