Автор: Victor Puertas (vpgugr@gmail.com)
Пример #1
0
 /**
  * Builds the PluginManager with the plugins of a site.
  *
  * Each plugin is added to PluginManager using "name"
  * meta or its classname if that meta do not exists.
  *
  * @return \Yosymfony\Spress\Core\Plugin\PluginManager
  */
 public function build()
 {
     $pm = new PluginManager($this->eventDispatcher);
     if (empty($this->path) === true || file_exists($this->path) === false) {
         return $pm;
     }
     $composerClassname = [];
     $finder = $this->buildFinder();
     foreach ($finder as $file) {
         $classname = $this->getClassname($file);
         if (empty($classname) === true) {
             continue;
         }
         if ($file->getFilename() === $this->composerFilename) {
             $composerClassname[] = $classname;
             continue;
         }
         include_once $file->getRealPath();
         if ($this->isValidClassName($classname) === false) {
             continue;
         }
         $plugin = new $classname();
         $metas = $this->getPluginMetas($plugin);
         $pm->addPlugin($metas['name'], $plugin);
     }
     foreach ($composerClassname as $classname) {
         if ($this->isValidClassName($classname) === true) {
             $plugin = new $classname();
             $metas = $this->getPluginMetas($plugin);
             $pm->addPlugin($metas['name'], $plugin);
         }
     }
     return $pm;
 }
Пример #2
0
 public function testBuildCommands()
 {
     $definition = new CommandDefinition('self-update');
     $definition->setDescription('Update spress.phar to the latest version.');
     $definition->setHelp('The self-update command replace your spress.phar by the latest version.');
     $definition->addOption('all');
     $definition->addArgument('dir');
     $input = $this->getMockBuilder('\\Symfony\\Component\\Console\\Input\\InputInterface')->getMock();
     $input->expects($this->once())->method('getArguments')->will($this->returnValue([]));
     $input->expects($this->once())->method('getOptions')->will($this->returnValue([]));
     $output = $this->getMockBuilder('\\Symfony\\Component\\Console\\Output\\OutputInterface')->getMock();
     $commandPluginMock = $this->getMockBuilder('\\Yosymfony\\Spress\\Plugin\\CommandPlugin')->getMock();
     $commandPluginMock->expects($this->once())->method('getCommandDefinition')->will($this->returnValue($definition));
     $commandPluginMock->expects($this->once())->method('executeCommand');
     $pm = new PluginManager(new EventDispatcher());
     $pm->addPlugin('emptyCommandPlugin', $commandPluginMock);
     $builder = new ConsoleCommandBuilder($pm);
     $symfonyConsoleCommands = $builder->buildCommands();
     $this->assertTrue(is_array($symfonyConsoleCommands));
     $this->assertCount(1, $symfonyConsoleCommands);
     $this->assertContainsOnlyInstancesOf('Symfony\\Component\\Console\\Command\\Command', $symfonyConsoleCommands);
     $symfonyConsoleCommand = $symfonyConsoleCommands[0];
     $this->assertCount(1, $symfonyConsoleCommand->getDefinition()->getOptions());
     $this->assertCount(1, $symfonyConsoleCommand->getDefinition()->getArguments());
     $this->assertEquals('Update spress.phar to the latest version.', $symfonyConsoleCommand->getDescription());
     $this->assertEquals('The self-update command replace your spress.phar by the latest version.', $symfonyConsoleCommand->getHelp());
     $symfonyConsoleCommand->run($input, $output);
 }
Пример #3
0
 public function testCallInitialize()
 {
     $pm = new PluginManager(new EventDispatcher());
     $plugin1 = $this->getMockBuilder('\\Yosymfony\\Spress\\Core\\Plugin\\PluginInterface')->getMock();
     $plugin2 = $this->getMockBuilder('\\Yosymfony\\Spress\\Core\\Plugin\\PluginInterface')->getMock();
     $plugin1->expects($this->once())->method('initialize');
     $plugin2->expects($this->once())->method('initialize');
     $pluginCollection = $pm->getPluginCollection();
     $pluginCollection->add('plugin1', $plugin1);
     $pluginCollection->add('plugin2', $plugin2);
     $pm->callInitialize();
 }
Пример #4
0
 public function testPluginManager()
 {
     $pm = new PluginManager(new EventDispatcher());
     $plugin1 = $this->getMockBuilder('\\Yosymfony\\Spress\\Core\\Plugin\\PluginInterface')->getMock();
     $plugin2 = $this->getMockBuilder('\\Yosymfony\\Spress\\Core\\Plugin\\PluginInterface')->getMock();
     $plugin1->expects($this->once())->method('initialize');
     $plugin2->expects($this->once())->method('initialize');
     $pm->addPlugin('plugin1', $plugin1);
     $pm->setPlugin('plugin2', $plugin2);
     $this->assertEquals(2, $pm->countPlugins());
     $this->assertCount(2, $pm->getPlugins());
     $this->assertContainsOnlyInstancesOf('\\Yosymfony\\Spress\\Core\\Plugin\\PluginInterface', $pm->getPlugins());
     $this->assertTrue($pm->hasPlugin('plugin1'));
     $this->assertFalse($pm->hasPlugin('plugin3'));
     $this->assertInstanceOf('\\Yosymfony\\Spress\\Core\\Plugin\\PluginInterface', $pm->getPlugin('plugin1'));
     $pm->callInitialize();
     $pm->removePlugin('plugin1');
     $this->assertEquals(1, $pm->countPlugins());
     $pm->clearPlugin();
     $this->assertEquals(0, $pm->countPlugins());
 }
Пример #5
0
 protected function getPluginManager(EventDispatcher $dispatcher, array $plugins)
 {
     $pm = new PluginManager($dispatcher);
     $pluginCollection = $pm->getPluginCollection();
     foreach ($plugins as $index => $Plugin) {
         $pluginCollection->add($index, $Plugin);
     }
     return $pm;
 }
Пример #6
0
 private function getPluginManager(EventDispatcher $dispatcher, array $plugins)
 {
     $pm = new PluginManager($dispatcher);
     foreach ($plugins as $index => $Plugin) {
         $pm->addPlugin($index, $Plugin);
     }
     return $pm;
 }