diff --git a/config/packages/framework.yaml b/config/packages/framework.yaml index b32f52d989..a31bc82c6a 100644 --- a/config/packages/framework.yaml +++ b/config/packages/framework.yaml @@ -1,15 +1,9 @@ framework: secret: '%env(APP_SECRET)%' - #default_locale: en - #csrf_protection: ~ - #http_method_override: true - # uncomment this entire section to enable sessions - #session: - # # With this config, PHP's native session handling is used - # handler_id: ~ + # needs to be disabled because we currently use a different translator with the same service name + translator: + enabled: false - #esi: ~ - #fragments: ~ php_errors: log: true diff --git a/src/phpDocumentor/Application.php b/src/phpDocumentor/Application.php index da4ac12fa3..2ac1739c1f 100644 --- a/src/phpDocumentor/Application.php +++ b/src/phpDocumentor/Application.php @@ -64,26 +64,6 @@ public function __construct(ContainerInterface $container) $this->container = $container; } - /** - * @param null|InputInterface $input - * @param null|OutputInterface $output - * @return mixed - */ - public function run(InputInterface $input = null, OutputInterface $output = null) - { - /** @var ConsoleApplication $app */ - $app = $this['console']; - $app->setAutoExit(false); - - if ($output === null) { - $output = new Console\Output\Output(); - $output->setLogger($this['monolog']); - } - - return parent::run(new ArgvInput(), $output); - } - - /** * Adjust php.ini settings. * diff --git a/src/phpDocumentor/Application/CilexCompatibilityLayer/CilexCompatibilityLayerBundle.php b/src/phpDocumentor/Application/CilexCompatibilityLayer/CilexCompatibilityLayerBundle.php index 537b72d533..2812980c7c 100644 --- a/src/phpDocumentor/Application/CilexCompatibilityLayer/CilexCompatibilityLayerBundle.php +++ b/src/phpDocumentor/Application/CilexCompatibilityLayer/CilexCompatibilityLayerBundle.php @@ -5,6 +5,10 @@ namespace phpDocumentor\Application\CilexCompatibilityLayer; use phpDocumentor\Application; +use phpDocumentor\Command\Helper\ConfigurationHelper; +use phpDocumentor\Command\Helper\LoggerHelper; +use phpDocumentor\Configuration; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\HttpKernel\Bundle\Bundle; final class CilexCompatibilityLayerBundle extends Bundle @@ -18,6 +22,21 @@ public function boot() public function registerCommands(\Symfony\Component\Console\Application $application) { + $application->getHelperSet()->set(new LoggerHelper()); + $application->getHelperSet()->set(new ConfigurationHelper(new Configuration())); + + $application->getDefinition()->addOption( + new InputOption( + 'config', + 'c', + InputOption::VALUE_OPTIONAL, + 'Location of a custom configuration file' + ) + ); + $application->getDefinition()->addOption( + new InputOption('log', null, InputOption::VALUE_OPTIONAL, 'Log file to write to') + ); + if ($this->container->has('phpdocumentor.compatibility.extra_commands')) { $commands = $this->container->get('phpdocumentor.compatibility.extra_commands'); diff --git a/src/phpDocumentor/Command/Command.php b/src/phpDocumentor/Command/Command.php index 6f4a7cc9ec..3988daccce 100644 --- a/src/phpDocumentor/Command/Command.php +++ b/src/phpDocumentor/Command/Command.php @@ -16,6 +16,7 @@ use Symfony\Component\Console\Helper\HelperSet; use Symfony\Component\Console\Helper\ProgressHelper; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; /** * Base command for phpDocumentor commands. @@ -42,6 +43,24 @@ public function getService(string $name) return $this->getContainer()->get($name); } + /** + * Executes a callable piece of code and writes an entry to the log detailing how long it took. + */ + protected function writeTimedLog(OutputInterface $output, $message, $operation, array $arguments = array()) + { + $output->write(sprintf('%-66.66s .. ', $message)); + $timerStart = microtime(true); + + call_user_func_array($operation, $arguments); + + $output->writeln(sprintf('%8.3fs', microtime(true) - $timerStart)); + } + + public function getService(string $name) + { + return $this->getContainer()->get($name); + } + /** * Returns the Progress bar helper. * diff --git a/src/phpDocumentor/Configuration/Loader.php b/src/phpDocumentor/Configuration/Loader.php index c98bc9fa7d..3f2d33c906 100644 --- a/src/phpDocumentor/Configuration/Loader.php +++ b/src/phpDocumentor/Configuration/Loader.php @@ -12,7 +12,7 @@ namespace phpDocumentor\Configuration; use JMS\Serializer\Serializer; -use phpDocumentor\Console\Input\ArgvInput; +use Symfony\Component\Console\Input\ArgvInput; /** * Loads the template and user-defined configuration file from disk and creates a Configuration object from it. diff --git a/src/phpDocumentor/Configuration/ServiceProvider.php b/src/phpDocumentor/Configuration/ServiceProvider.php index c6535db6d6..8cf03983b9 100644 --- a/src/phpDocumentor/Configuration/ServiceProvider.php +++ b/src/phpDocumentor/Configuration/ServiceProvider.php @@ -53,47 +53,15 @@ class ServiceProvider implements ServiceProviderInterface */ public function register(Container $app) { - $this->addMerger($app); - -// $app->extend( -// 'console', -// function (ConsoleApplication $console) { -// $console->getDefinition()->addOption( -// new InputOption( -// 'config', -// 'c', -// InputOption::VALUE_OPTIONAL, -// 'Location of a custom configuration file' -// ) -// ); -// -// return $console; -// } -// ); - $app['config.path.template'] = __DIR__ . '/Resources/phpdoc.tpl.xml'; $app['config.path.user'] = getcwd() . ((file_exists(getcwd() . '/phpdoc.xml')) ? '/phpdoc.xml' : '/phpdoc.dist.xml'); $app['config.class'] = 'phpDocumentor\Configuration'; $app['config'] = function ($app) { - $loader = new Loader($app['serializer'], $app['config.merger']); + $loader = new Loader($app['serializer'], new Merger(new AnnotationReader())); return $loader->load($app['config.path.template'], $app['config.path.user'], $app['config.class']); }; } - - /** - * Initializes and adds the configuration merger object as the 'config.merger' service to the container. - * - * @param Application $container - * - * @return void - */ - private function addMerger(Application $container) - { - $container['config.merger'] = function () { - return new Merger(new AnnotationReader()); - }; - } } diff --git a/src/phpDocumentor/Console/Input/ArgvInput.php b/src/phpDocumentor/Console/Input/ArgvInput.php deleted file mode 100644 index 332fd3e9ed..0000000000 --- a/src/phpDocumentor/Console/Input/ArgvInput.php +++ /dev/null @@ -1,53 +0,0 @@ -logger = $logger; - } - - /** - * Returns the object where is being logged to. - * - * @return Logger - */ - public function getLogger() - { - return $this->logger; - } - - /** - * Executes a callable piece of code and writes an entry to the log detailing how long it took. - * - * @param string $message - * @param callable $operation - * @param array $arguments - * - * @return void - */ - public function writeTimedLog($message, $operation, array $arguments = array()) - { - $this->write(sprintf('%-66.66s .. ', $message)); - $timerStart = microtime(true); - - call_user_func_array($operation, $arguments); - - $this->writeln(sprintf('%8.3fs', microtime(true) - $timerStart)); - } - - /** - * Write an entry to the console and to the provided logger. - * - * @param array|string $messages - * @param bool $newline - * @param int $type - * - * @return void - */ - public function write($messages, $newline = false, $type = 0) - { - $messages = (array) $messages; - - if ($this->getLogger()) { - foreach ($messages as $message) { - $this->getLogger()->info($this->getFormatter()->format(strip_tags($message))); - } - } - - parent::write($messages, $newline, $type); - } -} diff --git a/src/phpDocumentor/Transformer/Command/Project/TransformCommand.php b/src/phpDocumentor/Transformer/Command/Project/TransformCommand.php index d9677769c2..d709ee9339 100644 --- a/src/phpDocumentor/Transformer/Command/Project/TransformCommand.php +++ b/src/phpDocumentor/Transformer/Command/Project/TransformCommand.php @@ -31,7 +31,6 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Filesystem\Filesystem; use Zend\Cache\Storage\StorageInterface; -use Zend\Stdlib\AbstractOptions; /** * Transforms the structure file into the specified output format @@ -185,16 +184,18 @@ protected function execute(InputInterface $input, OutputInterface $output) $projectDescriptor = $this->getBuilder()->getProjectDescriptor(); $mapper = new ProjectDescriptorMapper($this->getCache()); - $output->writeTimedLog('Load cache', array($mapper, 'populate'), array($projectDescriptor)); + $this->writeTimedLog($output,'Load cache', array($mapper, 'populate'), array($projectDescriptor)); foreach ($this->getTemplates($input) as $template) { - $output->writeTimedLog( + $this->writeTimedLog( + $output, 'Preparing template "'. $template .'"', array($transformer->getTemplates(), 'load'), array($template, $transformer) ); } - $output->writeTimedLog( + $this->writeTimedLog( + $output, 'Preparing ' . count($transformer->getTemplates()->getTransformations()) . ' transformations', array($this, 'loadTransformations'), array($transformer) @@ -206,7 +207,7 @@ protected function execute(InputInterface $input, OutputInterface $output) /** @var CompilerPassInterface $pass */ foreach ($this->compiler as $pass) { - $output->writeTimedLog($pass->getDescription(), array($pass, 'execute'), array($projectDescriptor)); + $this->writeTimedLog($output, $pass->getDescription(), array($pass, 'execute'), array($projectDescriptor)); } if ($progress) { @@ -223,7 +224,7 @@ protected function execute(InputInterface $input, OutputInterface $output) */ protected function getCache() { - return $this->getContainer()->offsetGet('descriptor.cache'); + return $this->getContainer()->get('descriptor.cache'); } /** diff --git a/tests/unit/phpDocumentor/ApplicationTest.php b/tests/unit/phpDocumentor/ApplicationTest.php deleted file mode 100644 index 306919c8f5..0000000000 --- a/tests/unit/phpDocumentor/ApplicationTest.php +++ /dev/null @@ -1,213 +0,0 @@ -fixture = new Application(); - } - - /** - * @covers phpDocumentor\Application::__construct - */ - public function testIfStopwatchIsStarted() - { - $this->assertTrue(isset($this->fixture['kernel.timer.start'])); - $this->assertTrue(isset($this->fixture['kernel.stopwatch'])); - } - - /** - * @covers phpDocumentor\Application::__construct - */ - public function testIfVersionIsPopulated() - { - $this->assertRegExp('/^[\d]+\.[\d]+\.[\d]+(\-[\w]+)?$/', Application::$VERSION); - } - - /** - * @covers phpDocumentor\Application::__construct - */ - public function testIfSerializerIsRegistered() - { - $this->assertTrue(isset($this->fixture['serializer'])); - } - - /** - * @covers phpDocumentor\Application::__construct - */ - public function testIfConfigurationIsRegistered() - { - $this->assertTrue(isset($this->fixture['config'])); - $this->assertInstanceOf('phpDocumentor\Configuration', $this->fixture['config']); - } - - /** - * @covers phpDocumentor\Application::__construct - * @covers phpDocumentor\Application::addEventDispatcher - */ - public function testIfEventDispatcherIsRegistered() - { - $this->assertTrue(isset($this->fixture['event_dispatcher'])); - $this->assertInstanceOf('phpDocumentor\Event\Dispatcher', $this->fixture['event_dispatcher']); - } - - /** - * @covers phpDocumentor\Application::__construct - */ - public function testIfTranslatorIsRegistered() - { - $this->assertTrue(isset($this->fixture['translator'])); - } - - /** - * @covers phpDocumentor\Application::__construct - */ - public function testIfDescriptorBuilderIsRegistered() - { - $this->assertTrue(isset($this->fixture['descriptor.builder'])); - } - - /** - * @covers phpDocumentor\Application::__construct - */ - public function testIfParserIsRegistered() - { - $this->assertTrue(isset($this->fixture['parser'])); - } - - /** - * @covers phpDocumentor\Application::__construct - */ - public function testIfPartialsAreRegistered() - { - $this->assertTrue(isset($this->fixture['partials'])); - } - - /** - * @covers phpDocumentor\Application::__construct - */ - public function testIfTransformerIsRegistered() - { - $this->assertTrue(isset($this->fixture['transformer'])); - } - - /** - * @covers phpDocumentor\Application::__construct - */ - public function testIfPluginsAreRegistered() - { - $this->assertTrue(isset($this->fixture['transformer.writer.collection']['checkstyle'])); - } - - /** - * @covers phpDocumentor\Application::__construct - * @covers phpDocumentor\Application::addCommandsForProjectNamespace - */ - public function testIfRunCommandIsRegistered() - { - /** @var ConsoleApplication $console */ - $console = $this->fixture['console']; - $this->assertTrue($console->has('project:run')); - } - - /** - * @covers phpDocumentor\Application::__construct - * @covers phpDocumentor\Application::defineIniSettings - */ - public function testIfMemoryLimitIsDisabled() - { - $this->assertSame('-1', ini_get('memory_limit')); - } - - /** - * Test setting loglevel to logger. - * - * @param string $loglevel - * @param string $expectedLogLevel - * - * @dataProvider loglevelProvider - * @covers phpDocumentor\Application::configureLogger - */ - public function testSetLogLevel($loglevel, $expectedLogLevel) - { - $logger = m::mock('Monolog\Logger') - ->shouldReceive('pushHandler')->with(m::on(function($stream) use($expectedLogLevel) { - if (!$stream instanceof \Monolog\Handler\StreamHandler) { - return false; - } - - return $stream->getLevel() == $expectedLogLevel; - })) - ->shouldReceive('popHandler') - ->getMock(); - $this->fixture->configureLogger($logger, $loglevel); - $this->assertSame($expectedLogLevel, $this->fixture['monolog.level']); - } - - /** - * Data provider for testSetLogLevel - * - * @return array[] - */ - public function loglevelProvider() - { - return array( - array( - 'emergency', - Logger::EMERGENCY, - ), - array( - 'emerg', - Logger::EMERGENCY, - ), - array( - 'alert', - Logger::ALERT, - ), - array( - 'critical', - Logger::CRITICAL, - ), - array( - 'error', - Logger::ERROR, - ), - array( - 'err', - Logger::ERROR, - ), - array( - 'warning', - Logger::WARNING, - ), - array( - 'warn', - Logger::WARNING, - ), - array( - 'notice', - Logger::NOTICE, - ), - array( - 'info', - Logger::INFO, - ), - array( - 'debug', - Logger::DEBUG, - ), - ); - } -} diff --git a/tests/unit/phpDocumentor/BootstrapTest.php b/tests/unit/phpDocumentor/BootstrapTest.php deleted file mode 100644 index 45459316b3..0000000000 --- a/tests/unit/phpDocumentor/BootstrapTest.php +++ /dev/null @@ -1,136 +0,0 @@ - array( - 'vendor' => array( - 'phpDocumentor' => array( - 'phpDocumentor' => array( - 'src' => array( - 'phpDocumentor' => array(), - ), - ), - ), - ), - ), - ); - - /** - * Directory structure when phpdocumentor is installed from git. - * - * @var array - */ - protected $standaloneStructure = array( - 'dummy' => array( - 'vendor' => array(), - 'src' => array( - 'phpDocumentor' => array(), - ), - 'test' => array(), - ), - ); - - /** - * @covers phpDocumentor\Bootstrap::createInstance - */ - public function testCreatingAnInstanceUsingStaticFactoryMethod() - { - $this->assertInstanceOf('phpDocumentor\Bootstrap', Bootstrap::createInstance()); - } - - /** - * @covers phpDocumentor\Bootstrap::initialize - */ - public function testInitializingTheApplication() - { - $bootstrap = Bootstrap::createInstance(); - $this->assertInstanceOf('phpDocumentor\Application', $bootstrap->initialize()); - } - - /** - * @covers phpDocumentor\Bootstrap::findVendorPath - */ - public function testFindVendorPathStandAloneInstall() - { - vfsStream::setup('root', null, $this->standaloneStructure); - $bootstrap = Bootstrap::createInstance(); - - $baseDir = vfsStream::url('root/dummy/src/phpDocumentor'); - $this->assertSame('vfs://root/dummy/src/phpDocumentor/../../vendor', $bootstrap->findVendorPath($baseDir)); - } - - /** - * @covers phpDocumentor\Bootstrap::findVendorPath - */ - public function testFindVendorPathComposerInstalled() - { - $root = vfsStream::setup('root', null, $this->composerInstalledStructure); - vfsStream::newFile('composer.json')->at($root->getChild('dummy')); - - $bootstrap = Bootstrap::createInstance(); - $baseDir = vfsStream::url('root/dummy/vendor/phpDocumentor/phpDocumentor/src/phpDocumentor'); - $this->assertSame( - 'vfs://root/dummy/vendor/phpDocumentor/phpDocumentor/src/phpDocumentor/../../../../../vendor' - , $bootstrap->findVendorPath($baseDir) - ); - } - - /** - * Tests if exception is thrown when no autoloader is present - * - * @expectedException \RuntimeException - * @covers phpDocumentor\Bootstrap::createAutoloader - */ - public function testCreateAutoloaderNoAutoloader() - { - vfsStream::setup('root', null, $this->standaloneStructure); - $bootstrap = Bootstrap::createInstance(); - $bootstrap->createAutoloader(vfsStream::url('root/dummy/vendor')); - } - - /** - * checks autoload.php is required and returned by createAutoloader - * - * @covers phpDocumentor\Bootstrap::createAutoloader - */ - public function testCreateAutoloader() - { - $root = vfsStream::setup('root', null, $this->standaloneStructure); - - /** @var vfsStreamDirectory $firstChild */ - $firstChild = $root->getChild('dummy'); - $secondChild = $firstChild->getChild('vendor'); - - vfsStream::newFile('autoload.php')->withContent('at($secondChild); - - $bootstrap = Bootstrap::createInstance(); - $this->assertTrue($bootstrap->createAutoloader(vfsStream::url('root/dummy/vendor'))); - } - -}