Ejemplo n.º 1
0
 public function setUp()
 {
     $fileSystem = new Filesystem();
     $temp = sys_get_temp_dir();
     $this->tempDir = $temp . DIRECTORY_SEPARATOR . 'licenser';
     $fileSystem->remove($this->tempDir);
     $fileSystem->mkdir($this->tempDir);
     $this->fixturesDir = __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures';
     $fileSystem->mirror($this->fixturesDir . DIRECTORY_SEPARATOR . 'origin', $this->tempDir, null, ['override' => true]);
     $fileSystem->copy($this->fixturesDir . DIRECTORY_SEPARATOR . 'license', $this->tempDir . DIRECTORY_SEPARATOR . 'license', true);
     $finder = FinderBuilder::create()->in($this->tempDir)->name('*.php');
     $this->config = Config::create()->setFinderBuilder($finder);
     $this->config->setLicense(file_get_contents(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', 'src', 'licenses', 'default'])));
     $this->output = new DummyOutput();
     $this->logger = new ProcessLogger($this->output);
     $this->logger->startProcess();
 }
Ejemplo n.º 2
0
 public function testSetGetParameters()
 {
     $parameters = ['author' => 'AuthorName', 'version' => 'v1.0'];
     $config = Config::create()->setParameters($parameters);
     self::assertEquals($parameters, $config->getParameters());
     self::assertEquals('v1.0', $config->getParameter('version'));
     self::assertTrue($config->hasParameter('version'));
     self::assertFalse($config->hasParameter('name'));
 }
Ejemplo n.º 3
0
 public function testBasicLicenserFromConfig()
 {
     $licenser = self::getMockBuilder(Licenser::class)->disableOriginalConstructor()->getMock();
     $licenser->expects(self::once())->method('process')->with(Licenser::MODE_NORMAL);
     $config = Config::create()->setLicense(file_get_contents(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', '..', 'src', 'licenses', 'default'])))->setFinderBuilder(FinderBuilder::create(['in' => [realpath($this->tempDir)], 'name' => '*.php']));
     $command = self::getMockBuilder(LicenserCommand::class)->setMethods(['buildLicenser'])->getMock();
     $command->expects(self::once())->method('buildLicenser')->with($config)->willReturn($licenser);
     $yamlFile = tempnam(sys_get_temp_dir(), 'licenser');
     $yaml = Yaml::dump(['finder' => ['in' => 'licenser']]);
     file_put_contents($yamlFile, $yaml);
     $input = new ArrayInput(['--config' => realpath($yamlFile)]);
     $output = new DummyOutput();
     $command->run($input, $output);
 }
Ejemplo n.º 4
0
 /**
  * allow source override by command
  * https://github.com/rafrsr/licenser/issues/1
  * Add current path and change the name from *.php to given filename in case of file.
  *
  * @param Config $config
  * @param        $source
  */
 private static function overrideConfigSource(Config $config, $source)
 {
     $source = realpath($source);
     $ins = $config->getFinderBuilder()->getIn();
     //obtaining related path based on "in" directories
     //allowing filter results using the finder config
     foreach ($ins as $in) {
         if (strpos($source, $in) !== false) {
             $path = str_replace($in, null, $source);
             //remove any \ or / in the path start
             $path = preg_replace('/^[\\/\\\\]/', null, $path);
             $path = str_replace('\\', '/', $path);
             //convert \ -> /
             if (is_file($source)) {
                 $path = pathinfo($path, PATHINFO_DIRNAME);
             }
             $config->getFinderBuilder()->clearPath()->path($path);
         }
     }
     if (is_file($source)) {
         $config->getFinderBuilder()->clearName()->name(pathinfo($source, PATHINFO_BASENAME));
     }
 }
Ejemplo n.º 5
0
 public function testCreateFromConfigFileMultiFinder()
 {
     $config = Config::create()->setLicense(file_get_contents(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', 'src', 'licenses', 'default'])))->setFinderBuilder(FinderBuilder::create(['in' => [realpath($this->tempDir)], 'name' => '*.php']));
     $configJs = Config::create()->setLicense(file_get_contents(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', 'src', 'licenses', 'default'])))->setFinderBuilder(FinderBuilder::create(['in' => [realpath(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'src')], 'name' => '*.js']));
     $configFile = $this->buildYml(['finders' => ['php' => ['in' => 'licenser'], 'javascript' => ['in' => 'src', 'name' => '*.js']]]);
     self::assertEquals([$config, $configJs], ConfigFactory::createFromConfigFile($configFile));
 }
Ejemplo n.º 6
0
 public function testSetGetConfig()
 {
     $licenser = Licenser::create($this->config);
     self::assertEquals($licenser->getConfig(), $this->config);
     $newConfig = Config::create();
     $licenser->setConfig($newConfig);
     self::assertEquals($licenser->getConfig(), $newConfig);
 }