/**
  * Runs the project configurator.
  *
  * @return void
  */
 public function run()
 {
     $namespace = $this->ask('Namespace', function ($namespace) {
         return $this->validateNamespace($namespace);
     }, 'App');
     $packageName = $this->ask('Package name', function ($packageName) {
         return $this->validatePackageName($packageName);
     }, $this->suggestPackageName($namespace));
     $license = $this->ask('License', function ($license) {
         return trim($license);
     }, 'proprietary');
     $description = $this->ask('Description', function ($description) {
         return trim($description);
     }, '');
     $file = new JsonFile('./composer.json');
     $config = $file->read();
     $config['name'] = $packageName;
     $config['license'] = $license;
     $config['description'] = $description;
     $config['autoload']['psr-4'] = [$namespace . '\\' => 'src/'];
     $config['autoload-dev']['psr-4'] = [$namespace . '\\Tests\\' => 'tests/'];
     unset($config['scripts']['post-root-package-install']);
     $config['extra']['branch-alias']['dev-master'] = '1.0-dev';
     $file->write($config);
     $this->composer->setPackage(Factory::create($this->io, null, true)->getPackage());
     // reload root package
     $filesystem = new Filesystem();
     $filesystem->removeDirectory('./app/Distribution');
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->io = new BufferIO();
     $this->composer = new Composer();
     $this->composer->setPackage(new RootPackage('my/project', '1.0.0', '1.0.0'));
     $this->composer->setPluginManager(new PluginManager($this->io, $this->composer));
     $this->composer->setEventDispatcher(new EventDispatcher($this->composer, $this->io));
 }
Пример #3
0
 public function setUp()
 {
     $this->plugin = $this->getMock('\\ContaoCommunityAlliance\\Composer\\Plugin\\Plugin');
     $this->plugin->expects($this->any())->method('getContaoRoot')->will($this->returnValue('CONTAO_ROOT'));
     $package = new RootPackage('test/me', '0.8.15', '0.8.15.0');
     $package->setType(AbstractInstaller::MODULE_TYPE);
     $this->composer = new Composer();
     $this->composer->setConfig(new Config());
     $this->composer->setPackage($package);
     $this->installerStub = $this->getMockForAbstractClass('\\ContaoCommunityAlliance\\Composer\\Plugin\\AbstractInstaller', array(new NullIO(), $this->composer, $this->plugin));
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->localConfigPath = realpath(__DIR__ . '/../fixtures/local');
     $this->globalConfigPath = realpath(__DIR__ . '/../fixtures/home');
     $this->config = new Config(false, $this->localConfigPath);
     $this->config->merge(['config' => ['home' => $this->globalConfigPath]]);
     $package = new RootPackage('my/project', '1.0.0', '1.0.0');
     $package->setExtra(['my-local-config' => ['foo' => 'bar']]);
     $this->composer = new Composer();
     $this->composer->setConfig($this->config);
     $this->composer->setPackage($package);
     $this->SUT = new ConfigLocator($this->composer);
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->tempDir = __DIR__ . '/temp';
     $this->config = new Config(false, realpath(__DIR__ . '/fixtures/local'));
     $this->config->merge(['config' => ['home' => __DIR__]]);
     $this->io = new BufferIO();
     $this->composer = new Composer();
     $this->composer->setConfig($this->config);
     $this->composer->setPackage(new RootPackage('my/project', '1.0.0', '1.0.0'));
     $this->composer->setPluginManager(new PluginManager($this->io, $this->composer));
     $this->composer->setEventDispatcher(new EventDispatcher($this->composer, $this->io));
     self::cleanTempDir();
     mkdir($this->tempDir);
 }
 /**
  * @inheritdoc
  */
 protected function setUp()
 {
     parent::setUp();
     $this->composer = new Composer();
     $config = new Config();
     $this->composer->setConfig($config);
     /** @var RootPackageInterface|\PHPUnit_Framework_MockObject_MockObject $package */
     $package = $this->getMock('Composer\\Package\\RootPackageInterface');
     $package->expects($this->any())->method('getExtra')->willReturn(array(SharedPackageInstaller::PACKAGE_TYPE => array('vendor-dir' => sys_get_temp_dir() . '/composer-test-vendor-shared')));
     $this->composer->setPackage($package);
     $this->im = $this->getMock('Composer\\Installer\\InstallationManager');
     $this->composer->setInstallationManager($this->im);
     $this->io = $this->getMock('Composer\\IO\\IOInterface');
 }
Пример #7
0
 protected function setUp()
 {
     $this->tempDir = TestUtil::makeTempDir('puli-composer-plugin', __CLASS__);
     $filesystem = new Filesystem();
     $filesystem->mirror(__DIR__ . '/Fixtures/root', $this->tempDir);
     $this->io = $this->getMock('Composer\\IO\\IOInterface');
     $this->config = new Config(false, $this->tempDir);
     $this->config->merge(array('config' => array('vendor-dir' => 'the-vendor')));
     $this->installationManager = $this->getMockBuilder('Composer\\Installer\\InstallationManager')->disableOriginalConstructor()->getMock();
     $this->installationManager->expects($this->any())->method('getInstallPath')->will($this->returnCallback(array($this, 'getInstallPath')));
     $this->rootPackage = new RootPackage('vendor/root', '1.0', '1.0');
     $this->rootPackage->setRequires(array('vendor/package1' => new Link('vendor/root', 'vendor/package1'), 'vendor/package2' => new Link('vendor/root', 'vendor/package2')));
     $this->localRepository = new TestLocalRepository(array(new Package('vendor/package1', '1.0', '1.0'), new Package('vendor/package2', '1.0', '1.0')));
     $this->repositoryManager = new RepositoryManager($this->io, $this->config);
     $this->repositoryManager->setLocalRepository($this->localRepository);
     $this->installPaths = array();
     $this->composer = new Composer();
     $this->composer->setRepositoryManager($this->repositoryManager);
     $this->composer->setInstallationManager($this->installationManager);
     $this->composer->setConfig($this->config);
     $this->composer->setPackage($this->rootPackage);
     $this->puliRunner = $this->getMockBuilder('Puli\\ComposerPlugin\\PuliRunner')->disableOriginalConstructor()->getMock();
     $this->previousWd = getcwd();
     chdir($this->tempDir);
     $this->plugin = new PuliPlugin($this->puliRunner);
 }
 protected function setUp()
 {
     while (false === mkdir($this->tempDir = sys_get_temp_dir() . '/puli-plugin/PuliPluginTest_root' . rand(10000, 99999), 0777, true)) {
     }
     $filesystem = new Filesystem();
     $filesystem->mirror(__DIR__ . '/Fixtures/root', $this->tempDir);
     $this->io = $this->getMock('Composer\\IO\\IOInterface');
     $this->config = new Config(false, $this->tempDir);
     $this->config->merge(array('config' => array('vendor-dir' => 'the-vendor')));
     $this->installationManager = $this->getMockBuilder('Composer\\Installer\\InstallationManager')->disableOriginalConstructor()->getMock();
     $this->installationManager->expects($this->any())->method('getInstallPath')->will($this->returnCallback(array($this, 'getInstallPath')));
     $this->rootPackage = new RootPackage('vendor/root', '1.0', '1.0');
     $this->localRepository = new TestLocalRepository(array(new Package('vendor/package1', '1.0', '1.0'), new Package('vendor/package2', '1.0', '1.0')));
     $this->repositoryManager = new RepositoryManager($this->io, $this->config);
     $this->repositoryManager->setLocalRepository($this->localRepository);
     $this->installPaths = array();
     $this->composer = new Composer();
     $this->composer->setRepositoryManager($this->repositoryManager);
     $this->composer->setInstallationManager($this->installationManager);
     $this->composer->setConfig($this->config);
     $this->composer->setPackage($this->rootPackage);
     $this->puliRunner = $this->getMockBuilder('Puli\\ComposerPlugin\\PuliRunner')->disableOriginalConstructor()->getMock();
     $this->previousWd = getcwd();
     chdir($this->tempDir);
     $this->plugin = new PuliPlugin($this->puliRunner);
 }
 /**
  * @inheritdoc
  */
 protected function setUp()
 {
     parent::setUp();
     $this->fs = new SymlinkFilesystem();
     $this->composer = new Composer();
     $composerConfig = new Config();
     $this->composer->setConfig($composerConfig);
     $this->im = $this->getMock('Composer\\Installer\\InstallationManager');
     $this->composer->setInstallationManager($this->im);
     $this->vendorDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'composer-test-vendor';
     $this->ensureDirectoryExistsAndClear($this->vendorDir);
     $this->binDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'composer-test-bin';
     $this->ensureDirectoryExistsAndClear($this->binDir);
     $this->dependenciesDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'composer-test-dependencies';
     $this->ensureDirectoryExistsAndClear($this->dependenciesDir);
     $this->symlinkDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'composer-test-vendor-shared';
     $composerConfig->merge(array('config' => array('vendor-dir' => $this->vendorDir, 'bin-dir' => $this->binDir)));
     $this->dm = $this->getMockBuilder('Composer\\Downloader\\DownloadManager')->disableOriginalConstructor()->getMock();
     $this->composer->setDownloadManager($this->dm);
     $extraConfig = array(SharedPackageInstaller::PACKAGE_TYPE => array('vendor-dir' => $this->dependenciesDir, 'symlink-dir' => $this->symlinkDir));
     /** @var RootPackage|\PHPUnit_Framework_MockObject_MockObject $package */
     $package = $this->getMock('Composer\\Package\\RootPackageInterface');
     $package->expects($this->any())->method('getExtra')->willReturn($extraConfig);
     $this->composer->setPackage($package);
     $this->repository = $this->getMock('Composer\\Repository\\InstalledRepositoryInterface');
     $this->io = $this->getMock('Composer\\IO\\IOInterface');
     $this->dataManager = $this->getMockBuilder('LEtudiant\\Composer\\Data\\Package\\SharedPackageDataManager')->disableOriginalConstructor()->getMock();
     $vendorDirParams = explode(DIRECTORY_SEPARATOR, $this->vendorDir);
     $this->config = new SharedPackageInstallerConfig(end($vendorDirParams), $this->vendorDir, $extraConfig);
 }
Пример #10
0
 public function testInstall()
 {
     /* @var RootPackageInterface $rootPackage */
     $rootPackage = $this->createRootPackageMock();
     /* @var IOInterface $io */
     $io = $this->io;
     /* @var AssetTypeInterface $type */
     $type = $this->type;
     $vendorDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'composer-test' . DIRECTORY_SEPARATOR . 'vendor';
     $this->composer->setPackage($rootPackage);
     $dm = $this->getMockBuilder('Composer\\Downloader\\DownloadManager')->disableOriginalConstructor()->getMock();
     $this->composer->expects($this->any())->method('getDownloadManager')->will($this->returnValue($dm));
     $library = new AssetInstaller($io, $this->composer, $type);
     /* @var \PHPUnit_Framework_MockObject_MockObject $package */
     $package = $this->createPackageMock('foo-asset/package');
     /* @var PackageInterface $package */
     $packageDir = $vendorDir . '/' . $package->getPrettyName();
     $dm->expects($this->once())->method('download')->with($package, $vendorDir . DIRECTORY_SEPARATOR . 'foo-asset/package');
     $repository = $this->getMock('Composer\\Repository\\InstalledRepositoryInterface');
     $repository->expects($this->once())->method('addPackage')->with($package);
     /* @var InstalledRepositoryInterface $repository */
     $library->install($repository, $package);
     $this->assertFileExists($vendorDir, 'Vendor dir should be created');
     $this->ensureDirectoryExistsAndClear($packageDir);
 }
 /**
  * @inheritdoc
  */
 protected function setUp()
 {
     parent::setUp();
     $this->vendorDir = sys_get_temp_dir() . '/composer-test-vendor-shared';
     if (!is_dir($this->vendorDir)) {
         if (!mkdir($this->vendorDir)) {
             throw new \RuntimeException('Cannot create the temporary vendor dir');
         }
     } else {
         $this->clearPackageData();
     }
     $this->composer = new Composer();
     /** @var RootPackageInterface|\PHPUnit_Framework_MockObject_MockObject $rootPackage */
     $this->rootPackage = $this->getMock('Composer\\Package\\RootPackageInterface');
     $this->composer->setPackage($this->rootPackage);
 }
Пример #12
0
    public function testGetInstallPathWithTargetDir()
    {
        /* @var RootPackageInterface $rootPackage */
        $rootPackage = $this->createRootPackageMock();
        /* @var IOInterface $io */
        $io = $this->io;
        /* @var AssetTypeInterface $type */
        $type = $this->type;

        $this->composer->setPackage($rootPackage);

        $library = new BowerInstaller($io, $this->composer, $type);
        $package = $this->createPackageMock();

        /* @var \PHPUnit_Framework_MockObject_MockObject $package */
        $package
            ->expects($this->once())
            ->method('getTargetDir')
            ->will($this->returnValue('Some/Namespace'));
        $package
            ->expects($this->any())
            ->method('getPrettyName')
            ->will($this->returnValue('foo-asset/bar'));

        /* @var PackageInterface $package */
        $exceptDir = $this->vendorDir.'/'.$package->getPrettyName().'/Some/Namespace';
        $exceptDir = str_replace('\\', '/', $exceptDir);
        $packageDir = $library->getInstallPath($package);
        $packageDir = str_replace('\\', '/', $packageDir);

        $this->assertEquals($exceptDir, $packageDir);
    }
Пример #13
0
 public function testSetGetPackage()
 {
     $composer = new Composer();
     $package = $this->getMock('Composer\\Package\\RootPackageInterface');
     $composer->setPackage($package);
     $this->assertSame($package, $composer->getPackage());
 }
Пример #14
0
 /**
  * Ensures that the installer does not use paths for other packages, which are configured
  * in the root package.
  */
 public function testGetInstallPathDoesNotReturnPathFromUnrelatedPackageThatIsConfiguredInRootPackage()
 {
     $options = array('installer-paths' => array('unrelated/package' => 'another/path'));
     $rootPackage = $this->createRootPackage($options);
     $this->composer->setPackage($rootPackage);
     $package = $this->createPackage('installer/test', array('install-path' => 'public/asset'));
     $this->assertNotEquals('another/path', $this->installer->getInstallPath($package));
 }
 /**
  * Setup.
  */
 protected function setUp()
 {
     parent::setUp();
     $this->vendorDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'composer-test-vendor';
     $this->ensureDirectoryExistsAndClear($this->vendorDir);
     $this->composer = new \Composer\Composer();
     $config = new \Composer\Config();
     $this->composer->setConfig($config);
     /** @var \Composer\Package\RootPackageInterface|\PHPUnit_Framework_MockObject_MockObject $package */
     $package = $this->getMock('Composer\\Package\\RootPackageInterface');
     $package->expects($this->any())->method('getExtra')->willReturn(array(PhpCodesnifferStandardInstaller::PACKAGE_TYPE => array('vendor-dir' => $this->vendorDir)));
     $config->merge(array('config' => array('vendor-dir' => $this->vendorDir)));
     $this->composer->setPackage($package);
     $this->im = $this->getMock('Composer\\Installer\\InstallationManager');
     $this->composer->setInstallationManager($this->im);
     $this->io = $this->getMock('Composer\\IO\\IOInterface');
 }
Пример #16
0
 protected function setUp()
 {
     $this->filesystem = new Filesystem();
     $this->composer = new Composer();
     $this->config = new Config();
     $this->composer->setConfig($this->config);
     $this->package = new RootPackage('raulfraile/ladybug', '1.0.0', '1.0.0');
     $this->composer->setPackage($this->package);
     $this->vendorDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'composer-test-vendor';
     $this->ensureDirectoryExistsAndClear($this->vendorDir);
     $this->binDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'composer-test-bin';
     $this->ensureDirectoryExistsAndClear($this->binDir);
     $this->config->merge(array('config' => array('vendor-dir' => $this->vendorDir, 'bin-dir' => $this->binDir)));
     $this->downloadManager = m::mock('Composer\\Downloader\\DownloadManager');
     $this->composer->setDownloadManager($this->downloadManager);
     $this->repository = m::mock('Composer\\Repository\\InstalledRepositoryInterface');
     $this->io = m::mock('Composer\\IO\\IOInterface');
 }
 public function setUp()
 {
     $composer = new Composer();
     $package = new RootPackage("test", "1", "1");
     $package->setExtra(['opencart-dir' => 'tests/resources/sampleocdir']);
     $composer->setPackage($package);
     $composer->setConfig(new Config());
     $this->openCartExtensionInstaller = new OpenCartExtensionInstaller($this->getMockBuilder('Composer\\IO\\IOInterface')->getMock(), $composer);
 }
 /**
  * @test
  *
  * @depends installDevelopment
  */
 public function installDevelopmentAndSymlinkDisabled()
 {
     /** @var RootPackage|\PHPUnit_Framework_MockObject_MockObject $rootPackage */
     $rootPackage = $this->getMock('Composer\\Package\\RootPackageInterface');
     $rootPackage->expects($this->any())->method('getExtra')->willReturn(array(SharedPackageInstaller::PACKAGE_TYPE => array('vendor-dir' => $this->dependenciesDir, 'symlink-dir' => $this->symlinkDir, 'symlink-enabled' => false)));
     $this->composer->setPackage($rootPackage);
     $library = new SharedPackageInstaller($this->io, $this->composer, $this->fs, $this->dataManager);
     $package = $this->createDevelopmentPackageMock();
     $library->install($this->repository, $package);
     $this->assertFileNotExists($this->symlinkDir, 'Symlink dir should be created');
 }
Пример #19
0
 /**
  * @dataProvider getAssetMainFiles
  */
 public function testMainFiles(array $mainFiles)
 {
     /* @var RootPackageInterface $rootPackage */
     $rootPackage = $this->createRootPackageMock($mainFiles);
     $this->composer->setPackage($rootPackage);
     $package = new Package('foo-asset/bar', '1.0.0', '1.0.0');
     $package = AssetPlugin::addMainFiles($this->composer, $package);
     $extra = $package->getExtra();
     if (isset($mainFiles['asset-main-files'])) {
         $this->assertEquals($extra['bower-asset-main'], $mainFiles['asset-main-files']['foo-asset/bar']);
     } else {
         $this->assertEquals($extra, array());
     }
 }
 /**
  * testGetMultipleWebrootPackagesException
  * 
  * @return void
  * 
  * @expectedException \InvalidArgumentException
  */
 public function testGetMultipleWebrootPackagesException()
 {
     $installer = new WebrootInstaller($this->io, $this->composer);
     $package1 = new Package('fancyguy/webroot-package', '1.0.0', '1.0.0');
     $package1->setType('webroot');
     $package2 = new Package('fancyguy/another-webroot-package', '1.0.0', '1.0.0');
     $package2->setType('webroot');
     $consumerPackage = new RootPackage('foo/bar', '1.0.0', '1.0.0');
     $this->composer->setPackage($consumerPackage);
     $consumerPackage->setExtra(array('webroot-dir' => 'content', 'webroot-package' => 'fancyguy/webroot-package'));
     $consumerPackage->setRequires(array($package1, $package2));
     $result1 = $installer->getInstallPath($package1);
     $result2 = $installer->getInstallPath($package2);
 }
Пример #21
0
 protected function setUp()
 {
     $this->fs = new Filesystem();
     $this->composer = new Composer();
     $this->config = new Config();
     $this->composer->setConfig($this->config);
     $this->vendorDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'composer-test-vendor';
     $this->ensureDirectoryExistsAndClear($this->vendorDir);
     $this->binDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'composer-test-bin';
     $this->ensureDirectoryExistsAndClear($this->binDir);
     $this->config->merge(array('config' => array('vendor-dir' => $this->vendorDir, 'bin-dir' => $this->binDir)));
     $this->dm = $this->getMockBuilder('Composer\\Downloader\\DownloadManager')->disableOriginalConstructor()->getMock();
     $this->composer->setDownloadManager($this->dm);
     $this->repository = $this->getMock('Composer\\Repository\\InstalledRepositoryInterface');
     $this->io = $this->getMock('Composer\\IO\\IOInterface');
     $this->rootDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'composer-test-contao';
     $this->uploadDir = 'upload';
     $this->plugin = $this->getMock('\\ContaoCommunityAlliance\\Composer\\Plugin\\Plugin');
     $this->plugin->expects($this->any())->method('getContaoRoot')->will($this->returnValue($this->rootDir));
     $this->plugin->expects($this->any())->method('getUploadPath')->will($this->returnValue($this->uploadDir));
     $package = new RootPackage('test/package', '1.0.0.0', '1.0.0');
     $this->composer->setPackage($package);
 }
 /**
  * testInstallPath
  *
  * @dataProvider dataForInstallPath
  */
 public function testInstallPath($name, $type, $path, $expected)
 {
     $composer = new Composer();
     $config = new Config();
     $composer->setConfig($config);
     $repository = $this->getMock('Composer\\Repository\\InstalledRepositoryInterface');
     $io = $this->getMock('Composer\\IO\\IOInterface');
     $installer = new CustomInstaller($io, $composer);
     $package = new Package($name, '1.0.0', '1.0.0');
     $package->setType($type);
     $consumerPackage = new RootPackage('foo/bar', '1.0.0', '1.0.0');
     $composer->setPackage($consumerPackage);
     $consumerPackage->setExtra(array('custom-installer' => array($type => $path)));
     $result = $installer->getInstallPath($package);
     $this->assertEquals($expected, $result);
 }
Пример #23
0
 /**
  * Creates a Composer instance
  *
  * @param  IOInterface               $io             IO instance
  * @param  array|string|null         $localConfig    either a configuration array or a filename to read from, if null it will
  *                                                   read from the default filename
  * @param  bool                      $disablePlugins Whether plugins should not be loaded
  * @throws \InvalidArgumentException
  * @throws \UnexpectedValueException
  * @return Composer
  */
 public function createComposer(IOInterface $io, $localConfig = null, $disablePlugins = false)
 {
     // load Composer configuration
     if (null === $localConfig) {
         $localConfig = static::getComposerFile();
     }
     if (is_string($localConfig)) {
         $composerFile = $localConfig;
         $file = new JsonFile($localConfig, new RemoteFilesystem($io));
         if (!$file->exists()) {
             if ($localConfig === './composer.json' || $localConfig === 'composer.json') {
                 $message = 'Composer could not find a composer.json file in ' . getcwd();
             } else {
                 $message = 'Composer could not find the config file: ' . $localConfig;
             }
             $instructions = 'To initialize a project, please create a composer.json file as described in the http://getcomposer.org/ "Getting Started" section';
             throw new \InvalidArgumentException($message . PHP_EOL . $instructions);
         }
         $file->validateSchema(JsonFile::LAX_SCHEMA);
         $localConfig = $file->read();
     }
     // Load config and override with local config/auth config
     $config = static::createConfig($io);
     $config->merge($localConfig);
     if (isset($composerFile)) {
         if ($io && $io->isDebug()) {
             $io->write('Loading config file ' . $composerFile);
         }
         $localAuthFile = new JsonFile(dirname(realpath($composerFile)) . '/auth.json');
         if ($localAuthFile->exists()) {
             if ($io && $io->isDebug()) {
                 $io->write('Loading config file ' . $localAuthFile->getPath());
             }
             $config->merge(array('config' => $localAuthFile->read()));
             $config->setAuthConfigSource(new JsonConfigSource($localAuthFile, true));
         }
     }
     // load auth configs into the IO instance
     $io->loadConfiguration($config);
     $vendorDir = $config->get('vendor-dir');
     $binDir = $config->get('bin-dir');
     // setup process timeout
     ProcessExecutor::setTimeout((int) $config->get('process-timeout'));
     // initialize composer
     $composer = new Composer();
     $composer->setConfig($config);
     // initialize event dispatcher
     $dispatcher = new EventDispatcher($composer, $io);
     // initialize repository manager
     $rm = $this->createRepositoryManager($io, $config, $dispatcher);
     // load local repository
     $this->addLocalRepository($rm, $vendorDir);
     // load package
     $parser = new VersionParser();
     $loader = new Package\Loader\RootPackageLoader($rm, $config, $parser, new ProcessExecutor($io));
     $package = $loader->load($localConfig);
     // initialize installation manager
     $im = $this->createInstallationManager();
     // Composer composition
     $composer->setPackage($package);
     $composer->setRepositoryManager($rm);
     $composer->setInstallationManager($im);
     // initialize download manager
     $dm = $this->createDownloadManager($io, $config, $dispatcher);
     $composer->setDownloadManager($dm);
     $composer->setEventDispatcher($dispatcher);
     // initialize autoload generator
     $generator = new AutoloadGenerator($dispatcher, $io);
     $composer->setAutoloadGenerator($generator);
     // add installers to the manager
     $this->createDefaultInstallers($im, $composer, $io);
     $globalRepository = $this->createGlobalRepository($config, $vendorDir);
     $pm = $this->createPluginManager($composer, $io, $globalRepository);
     $composer->setPluginManager($pm);
     if (!$disablePlugins) {
         $pm->loadInstalledPlugins();
     }
     // purge packages if they have been deleted on the filesystem
     $this->purgePackages($rm, $im);
     // init locker if possible
     if (isset($composerFile)) {
         $lockFile = "json" === pathinfo($composerFile, PATHINFO_EXTENSION) ? substr($composerFile, 0, -4) . 'lock' : $composerFile . '.lock';
         $locker = new Package\Locker($io, new JsonFile($lockFile, new RemoteFilesystem($io, $config)), $rm, $im, md5_file($composerFile));
         $composer->setLocker($locker);
     }
     return $composer;
 }
Пример #24
0
 private function createComposerInstance()
 {
     $composer = new Composer();
     $config = new Config();
     $composer->setConfig($config);
     $package = $this->getMock('Composer\\Package\\RootPackageInterface');
     $composer->setPackage($package);
     return $composer;
 }
Пример #25
0
 /**
  * Creates a Composer instance
  *
  * @param  IOInterface               $io             IO instance
  * @param  array|string|null         $localConfig    either a configuration array or a filename to read from, if null it will
  *                                                   read from the default filename
  * @param  bool                      $disablePlugins Whether plugins should not be loaded
  * @param  bool                      $fullLoad       Whether to initialize everything or only main project stuff (used when loading the global composer)
  * @throws \InvalidArgumentException
  * @throws \UnexpectedValueException
  * @return Composer
  */
 public function createComposer(IOInterface $io, $localConfig = null, $disablePlugins = false, $cwd = null, $fullLoad = true)
 {
     $cwd = $cwd ?: getcwd();
     // load Composer configuration
     if (null === $localConfig) {
         $localConfig = static::getComposerFile();
     }
     if (is_string($localConfig)) {
         $composerFile = $localConfig;
         $file = new JsonFile($localConfig, null, $io);
         if (!$file->exists()) {
             if ($localConfig === './composer.json' || $localConfig === 'composer.json') {
                 $message = 'Composer could not find a composer.json file in ' . $cwd;
             } else {
                 $message = 'Composer could not find the config file: ' . $localConfig;
             }
             $instructions = 'To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section';
             throw new \InvalidArgumentException($message . PHP_EOL . $instructions);
         }
         $file->validateSchema(JsonFile::LAX_SCHEMA);
         $jsonParser = new JsonParser();
         try {
             $jsonParser->parse(file_get_contents($localConfig), JsonParser::DETECT_KEY_CONFLICTS);
         } catch (\Seld\JsonLint\DuplicateKeyException $e) {
             $details = $e->getDetails();
             $io->writeError('<warning>Key ' . $details['key'] . ' is a duplicate in ' . $localConfig . ' at line ' . $details['line'] . '</warning>');
         }
         $localConfig = $file->read();
     }
     // Load config and override with local config/auth config
     $config = static::createConfig($io, $cwd);
     $config->merge($localConfig);
     if (isset($composerFile)) {
         $io->writeError('Loading config file ' . $composerFile, true, IOInterface::DEBUG);
         $localAuthFile = new JsonFile(dirname(realpath($composerFile)) . '/auth.json');
         if ($localAuthFile->exists()) {
             $io->writeError('Loading config file ' . $localAuthFile->getPath(), true, IOInterface::DEBUG);
             $config->merge(array('config' => $localAuthFile->read()));
             $config->setAuthConfigSource(new JsonConfigSource($localAuthFile, true));
         }
     }
     $vendorDir = $config->get('vendor-dir');
     $binDir = $config->get('bin-dir');
     // initialize composer
     $composer = new Composer();
     $composer->setConfig($config);
     if ($fullLoad) {
         // load auth configs into the IO instance
         $io->loadConfiguration($config);
     }
     $rfs = self::createRemoteFilesystem($io, $config);
     // initialize event dispatcher
     $dispatcher = new EventDispatcher($composer, $io);
     $composer->setEventDispatcher($dispatcher);
     // initialize repository manager
     $rm = $this->createRepositoryManager($io, $config, $dispatcher, $rfs);
     $composer->setRepositoryManager($rm);
     // load local repository
     $this->addLocalRepository($io, $rm, $vendorDir);
     // force-set the version of the global package if not defined as
     // guessing it adds no value and only takes time
     if (!$fullLoad && !isset($localConfig['version'])) {
         $localConfig['version'] = '1.0.0';
     }
     // load package
     $parser = new VersionParser();
     $guesser = new VersionGuesser($config, new ProcessExecutor($io), $parser);
     $loader = new Package\Loader\RootPackageLoader($rm, $config, $parser, $guesser);
     $package = $loader->load($localConfig, 'Composer\\Package\\RootPackage', $cwd);
     $composer->setPackage($package);
     // initialize installation manager
     $im = $this->createInstallationManager();
     $composer->setInstallationManager($im);
     if ($fullLoad) {
         // initialize download manager
         $dm = $this->createDownloadManager($io, $config, $dispatcher, $rfs);
         $composer->setDownloadManager($dm);
         // initialize autoload generator
         $generator = new AutoloadGenerator($dispatcher, $io);
         $composer->setAutoloadGenerator($generator);
     }
     // add installers to the manager (must happen after download manager is created since they read it out of $composer)
     $this->createDefaultInstallers($im, $composer, $io);
     if ($fullLoad) {
         $globalComposer = $this->createGlobalComposer($io, $config, $disablePlugins);
         $pm = $this->createPluginManager($io, $composer, $globalComposer, $disablePlugins);
         $composer->setPluginManager($pm);
         $pm->loadInstalledPlugins();
         // once we have plugins and custom installers we can
         // purge packages from local repos if they have been deleted on the filesystem
         if ($rm->getLocalRepository()) {
             $this->purgePackages($rm->getLocalRepository(), $im);
         }
     }
     // init locker if possible
     if ($fullLoad && isset($composerFile)) {
         $lockFile = "json" === pathinfo($composerFile, PATHINFO_EXTENSION) ? substr($composerFile, 0, -4) . 'lock' : $composerFile . '.lock';
         $locker = new Package\Locker($io, new JsonFile($lockFile, null, $io), $rm, $im, file_get_contents($composerFile));
         $composer->setLocker($locker);
     }
     return $composer;
 }
Пример #26
0
 /**
  * Creates a Composer instance
  *
  * @param  IOInterface $io          IO instance
  * @param  mixed       $localConfig either a configuration array or a filename to read from, if null it will read from the default filename
  * @return Composer
  */
 public function createComposer(IOInterface $io, $localConfig = null)
 {
     // load Composer configuration
     if (null === $localConfig) {
         $localConfig = $this->getComposerFile();
     }
     if (is_string($localConfig)) {
         $composerFile = $localConfig;
         $file = new JsonFile($localConfig, new RemoteFilesystem($io));
         if (!$file->exists()) {
             if ($localConfig === 'composer.json') {
                 $message = 'Composer could not find a composer.json file in ' . getcwd();
             } else {
                 $message = 'Composer could not find the config file: ' . $localConfig;
             }
             $instructions = 'To initialize a project, please create a composer.json file as described in the http://getcomposer.org/ "Getting Started" section';
             throw new \InvalidArgumentException($message . PHP_EOL . $instructions);
         }
         $file->validateSchema(JsonFile::LAX_SCHEMA);
         $localConfig = $file->read();
     }
     // Configuration defaults
     $config = static::createConfig();
     $config->merge($localConfig);
     $vendorDir = $config->get('vendor-dir');
     $binDir = $config->get('bin-dir');
     // setup process timeout
     ProcessExecutor::setTimeout((int) $config->get('process-timeout'));
     // initialize repository manager
     $rm = $this->createRepositoryManager($io, $config);
     // load default repository unless it's explicitly disabled
     $localConfig = $this->addPackagistRepository($localConfig);
     // load local repository
     $this->addLocalRepository($rm, $vendorDir);
     // load package
     $loader = new Package\Loader\RootPackageLoader($rm);
     $package = $loader->load($localConfig);
     // initialize download manager
     $dm = $this->createDownloadManager($io);
     // initialize installation manager
     $im = $this->createInstallationManager($rm, $dm, $vendorDir, $binDir, $io);
     // purge packages if they have been deleted on the filesystem
     $this->purgePackages($rm, $im);
     // initialize composer
     $composer = new Composer();
     $composer->setConfig($config);
     $composer->setPackage($package);
     $composer->setRepositoryManager($rm);
     $composer->setDownloadManager($dm);
     $composer->setInstallationManager($im);
     // init locker if possible
     if (isset($composerFile)) {
         $lockFile = "json" === pathinfo($composerFile, PATHINFO_EXTENSION) ? substr($composerFile, 0, -4) . 'lock' : $composerFile . '.lock';
         $locker = new Package\Locker(new JsonFile($lockFile, new RemoteFilesystem($io)), $rm, md5_file($composerFile));
         $composer->setLocker($locker);
     }
     return $composer;
 }
 /**
  * @see   ScriptHandler::generateCSS
  * @test
  */
 public function generateCSS()
 {
     $composer = new Composer();
     /** @var RootPackage|\PHPUnit_Framework_MockObject_MockObject $rootPackage */
     $rootPackage = $this->getMockBuilder(RootPackage::class)->setConstructorArgs(['css-compiler', 'dev-master', 'dev'])->setMethods(['getExtra'])->getMock();
     /** @var IOInterface|\PHPUnit_Framework_MockObject_MockObject $io */
     $io = $this->getMockBuilder(IOInterface::class)->getMock();
     $output = $this->getCacheDirectory() . '/' . __FUNCTION__ . '.css';
     @unlink($output);
     $extra = ['css-compiler' => [['format' => 'compact', 'input' => [$this->getSharedFixturesDirectory() . '/less'], 'output' => $output]]];
     $rootPackage->expects($this->once())->method('getExtra')->willReturn($extra);
     $composer->setPackage($rootPackage);
     $event = new Event('onInstall', $composer, $io);
     ScriptHandler::generateCSS($event);
     $this->assertFileExists($output);
 }
Пример #28
0
 /**
  * Creates a Composer instance
  *
  * @param IOInterface       $io          IO instance
  * @param array|string|null $localConfig either a configuration array or a filename to read from, if null it will
  *                                       read from the default filename
  * @throws \InvalidArgumentException
  * @return Composer
  */
 public function createComposer(IOInterface $io, $localConfig = null)
 {
     // load Composer configuration
     if (null === $localConfig) {
         $localConfig = static::getComposerFile();
     }
     if (is_string($localConfig)) {
         $composerFile = $localConfig;
         $file = new JsonFile($localConfig, new RemoteFilesystem($io));
         if (!$file->exists()) {
             if ($localConfig === 'composer.json') {
                 $message = 'Composer could not find a composer.json file in ' . getcwd();
             } else {
                 $message = 'Composer could not find the config file: ' . $localConfig;
             }
             $instructions = 'To initialize a project, please create a composer.json file as described in the http://getcomposer.org/ "Getting Started" section';
             throw new \InvalidArgumentException($message . PHP_EOL . $instructions);
         }
         $file->validateSchema(JsonFile::LAX_SCHEMA);
         $localConfig = $file->read();
     }
     // Configuration defaults
     $config = static::createConfig();
     $config->merge($localConfig);
     // reload oauth token from config if available
     if ($tokens = $config->get('github-oauth')) {
         foreach ($tokens as $domain => $token) {
             if (!preg_match('{^[a-z0-9]+$}', $token)) {
                 throw new \UnexpectedValueException('Your github oauth token for ' . $domain . ' contains invalid characters: "' . $token . '"');
             }
             $io->setAuthentication($domain, $token, 'x-oauth-basic');
         }
     }
     $vendorDir = $config->get('vendor-dir');
     $binDir = $config->get('bin-dir');
     // setup process timeout
     ProcessExecutor::setTimeout((int) $config->get('process-timeout'));
     // initialize repository manager
     $rm = $this->createRepositoryManager($io, $config);
     // load local repository
     $this->addLocalRepository($rm, $vendorDir);
     // load package
     $loader = new Package\Loader\RootPackageLoader($rm, $config);
     $package = $loader->load($localConfig);
     // initialize download manager
     $dm = $this->createDownloadManager($io, $config);
     // initialize installation manager
     $im = $this->createInstallationManager();
     // initialize composer
     $composer = new Composer();
     $composer->setConfig($config);
     $composer->setPackage($package);
     $composer->setRepositoryManager($rm);
     $composer->setDownloadManager($dm);
     $composer->setInstallationManager($im);
     // initialize event dispatcher
     $dispatcher = new EventDispatcher($composer, $io);
     $composer->setEventDispatcher($dispatcher);
     // initialize autoload generator
     $generator = new AutoloadGenerator($dispatcher);
     $composer->setAutoloadGenerator($generator);
     // add installers to the manager
     $this->createDefaultInstallers($im, $composer, $io);
     // purge packages if they have been deleted on the filesystem
     $this->purgePackages($rm, $im);
     // init locker if possible
     if (isset($composerFile)) {
         $lockFile = "json" === pathinfo($composerFile, PATHINFO_EXTENSION) ? substr($composerFile, 0, -4) . 'lock' : $composerFile . '.lock';
         $locker = new Package\Locker(new JsonFile($lockFile, new RemoteFilesystem($io)), $rm, $im, md5_file($composerFile));
         $composer->setLocker($locker);
     }
     return $composer;
 }
Пример #29
0
 /**
  * Return Event Mock object
  *
  * @param string $root   Root
  * @param string $folder Folder
  * @param string $target Target
  *
  * @return Event
  */
 private function getEventMock($root, $folder, $target)
 {
     $extra = array(MoodleInstaller::MOODLE_MODULES => array($folder => $target));
     $package = $this->getMock("Composer\\Package\\RootPackageInterface");
     $package->expects($this->any())->method("getExtra")->will($this->returnValue($extra));
     $package->expects($this->any())->method("getType")->will($this->returnValue(MoodleInstaller::TYPE_MOODLE_PACKAGE));
     $config = new Config();
     $composer = new Composer();
     $composer->setConfig($config);
     $composer->setPackage($package);
     $config->merge(array("config" => array(MoodleInstaller::MOODLE_DIR => $root)));
     $io = $this->getMock("Composer\\IO\\IOInterface");
     $event = new Event("post-update-cmd", $composer, $io);
     return $event;
 }
Пример #30
0
 /**
  * Creates a Composer instance
  *
  * @return Composer
  */
 public function createComposer(IOInterface $io, $composerFile = null)
 {
     // load Composer configuration
     if (null === $composerFile) {
         $composerFile = getenv('COMPOSER') ?: 'composer.json';
     }
     $file = new JsonFile($composerFile);
     if (!$file->exists()) {
         if ($composerFile === 'composer.json') {
             $message = 'Composer could not find a composer.json file in ' . getcwd();
         } else {
             $message = 'Composer could not find the config file: ' . $composerFile;
         }
         $instructions = 'To initialize a project, please create a composer.json file as described on the http://packagist.org/ "Getting Started" section';
         throw new \InvalidArgumentException($message . PHP_EOL . $instructions);
     }
     // Configuration defaults
     $composerConfig = array('vendor-dir' => 'vendor', 'process-timeout' => 300);
     $packageConfig = $file->read();
     if (isset($packageConfig['config']) && is_array($packageConfig['config'])) {
         $packageConfig['config'] = array_merge($composerConfig, $packageConfig['config']);
     } else {
         $packageConfig['config'] = $composerConfig;
     }
     $vendorDir = getenv('COMPOSER_VENDOR_DIR') ?: $packageConfig['config']['vendor-dir'];
     if (!isset($packageConfig['config']['bin-dir'])) {
         $packageConfig['config']['bin-dir'] = $vendorDir . '/bin';
     }
     $binDir = getenv('COMPOSER_BIN_DIR') ?: $packageConfig['config']['bin-dir'];
     // setup process timeout
     $processTimeout = getenv('COMPOSER_PROCESS_TIMEOUT') ?: $packageConfig['config']['process-timeout'];
     ProcessExecutor::setTimeout((int) $processTimeout);
     // initialize repository manager
     $rm = $this->createRepositoryManager($io);
     // load default repository unless it's explicitly disabled
     $loadPackagist = true;
     if (isset($packageConfig['repositories'])) {
         foreach ($packageConfig['repositories'] as $repo) {
             if (isset($repo['packagist']) && $repo['packagist'] === false) {
                 $loadPackagist = false;
             }
         }
     }
     if ($loadPackagist) {
         $this->addPackagistRepository($rm);
     }
     // load local repository
     $this->addLocalRepository($rm, $vendorDir);
     // load package
     $loader = new Package\Loader\RootPackageLoader($rm);
     $package = $loader->load($packageConfig);
     // initialize download manager
     $dm = $this->createDownloadManager($io);
     // initialize installation manager
     $im = $this->createInstallationManager($rm, $dm, $vendorDir, $binDir, $io);
     // init locker
     $lockFile = substr($composerFile, -5) === '.json' ? substr($composerFile, 0, -4) . 'lock' : $composerFile . '.lock';
     $locker = new Package\Locker(new JsonFile($lockFile), $rm, md5_file($composerFile));
     // initialize composer
     $composer = new Composer();
     $composer->setPackage($package);
     $composer->setLocker($locker);
     $composer->setRepositoryManager($rm);
     $composer->setDownloadManager($dm);
     $composer->setInstallationManager($im);
     return $composer;
 }