Exemplo n.º 1
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);
 }
Exemplo n.º 2
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();
 }
Exemplo n.º 3
0
 /**
  * Array containing configuration.
  *
  * e.g.
  * [
  *  'finder' => ['in'=>'absolute/path/to/src']
  *  'license' => 'mit',
  *  'parameters => ['author'=>'AuthorName']
  * ]
  * All paths given in the array should be absolute paths.
  * At this point licenser can`t resolve relative paths
  *
  * @param array $configArray
  *
  * @throws \InvalidArgumentException
  *
  * @return Config
  */
 public static function createFromArray($configArray)
 {
     if (isset($configArray['license_content'])) {
         $license = $configArray['license_content'];
     } else {
         $license = isset($configArray['license']) ? $configArray['license'] : 'default';
         $license = self::getLicenseContent($license);
     }
     if (!isset($configArray['finder']['in'])) {
         throw new \LogicException('Invalid configuration, at least one source is required to locate files.');
     }
     if (!isset($configArray['finder']['name'])) {
         $configArray['finder']['name'] = '*.php';
         //default file types
     }
     $parameters = isset($configArray['parameters']) ? $configArray['parameters'] : [];
     $resolvedParameters = self::resolveParameters($parameters);
     $config = Config::create()->setLicense($license)->setParameters($resolvedParameters)->setFinderBuilder(FinderBuilder::create($configArray['finder']));
     return $config;
 }
Exemplo n.º 4
0
 public function testFinderBuilderInvalidMethod()
 {
     self::expectException(\BadFunctionCallException::class);
     FinderBuilder::create()->in(sys_get_temp_dir())->include('*.cls')->build();
 }
Exemplo n.º 5
0
 public function testSetGetFinder()
 {
     $finder = FinderBuilder::create();
     $config = Config::create()->setFinderBuilder($finder);
     self::assertEquals($finder, $config->getFinderBuilder());
 }
Exemplo n.º 6
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));
 }