/**
  * @test
  */
 public function update()
 {
     $initial = $this->createPackageMock();
     $target = $this->createPackageMock();
     $this->installer->expects($this->once())->method('update')->with($this->repository, $initial, $target);
     $this->repository->expects($this->once())->method('hasPackage')->with($initial)->willReturn(true);
     $this->createSolver()->update($this->repository, $initial, $target);
 }
 public function testExcludeFromClassmap()
 {
     $package = new Package('a', '1.0', '1.0');
     $package->setAutoload(array('psr-0' => array('Main' => 'src/', 'Lala' => array('src/', 'lib/')), 'psr-4' => array('Acme\\Fruit\\' => 'src-fruit/', 'Acme\\Cake\\' => array('src-cake/', 'lib-cake/')), 'classmap' => array('composersrc/'), 'exclude-from-classmap' => array('/composersrc/excludedTests/', '/composersrc/ClassToExclude.php', '/composersrc/*/excluded/excsubpath', '**/excsubpath')));
     $this->repository->expects($this->once())->method('getCanonicalPackages')->will($this->returnValue(array()));
     $this->fs->ensureDirectoryExists($this->workingDir . '/composer');
     $this->fs->ensureDirectoryExists($this->workingDir . '/src/Lala/Test');
     $this->fs->ensureDirectoryExists($this->workingDir . '/lib');
     file_put_contents($this->workingDir . '/src/Lala/ClassMapMain.php', '<?php namespace Lala; class ClassMapMain {}');
     file_put_contents($this->workingDir . '/src/Lala/Test/ClassMapMainTest.php', '<?php namespace Lala\\Test; class ClassMapMainTest {}');
     $this->fs->ensureDirectoryExists($this->workingDir . '/src-fruit');
     $this->fs->ensureDirectoryExists($this->workingDir . '/src-cake');
     $this->fs->ensureDirectoryExists($this->workingDir . '/lib-cake');
     file_put_contents($this->workingDir . '/src-cake/ClassMapBar.php', '<?php namespace Acme\\Cake; class ClassMapBar {}');
     $this->fs->ensureDirectoryExists($this->workingDir . '/composersrc');
     $this->fs->ensureDirectoryExists($this->workingDir . '/composersrc/tests');
     file_put_contents($this->workingDir . '/composersrc/foo.php', '<?php class ClassMapFoo {}');
     // this classes should not be found in the classmap
     $this->fs->ensureDirectoryExists($this->workingDir . '/composersrc/excludedTests');
     file_put_contents($this->workingDir . '/composersrc/excludedTests/bar.php', '<?php class ClassExcludeMapFoo {}');
     file_put_contents($this->workingDir . '/composersrc/ClassToExclude.php', '<?php class ClassClassToExclude {}');
     $this->fs->ensureDirectoryExists($this->workingDir . '/composersrc/long/excluded/excsubpath');
     file_put_contents($this->workingDir . '/composersrc/long/excluded/excsubpath/foo.php', '<?php class ClassExcludeMapFoo2 {}');
     file_put_contents($this->workingDir . '/composersrc/long/excluded/excsubpath/bar.php', '<?php class ClassExcludeMapBar {}');
     $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_1');
     // Assert that autoload_classmap.php was correctly generated.
     $this->assertAutoloadFiles('classmap', $this->vendorDir . '/composer', 'classmap');
 }
 /**
  * @test
  */
 public function uninstallKeepSources()
 {
     $this->io->expects($this->once())->method('askConfirmation')->willReturn(false);
     /** @var SymlinkFilesystem|\PHPUnit_Framework_MockObject_MockObject $filesystem */
     $filesystem = $this->getMock('\\LEtudiant\\Composer\\Util\\SymlinkFilesystem');
     $filesystem->expects($this->once())->method('removeSymlink')->willReturn(true);
     $installer = $this->createInstaller($this->config, $filesystem);
     $package = $this->createPackageMock();
     $this->repository->expects($this->once())->method('removePackage')->with($package);
     $this->dm->expects($this->never())->method('remove');
     $this->dataManager->expects($this->once())->method('removePackageUsage')->with($package);
     $installer->uninstall($this->repository, $package);
 }
 /**
  * @test
  */
 public function uninstallDevelopment()
 {
     $this->io->expects($this->once())->method('askConfirmation')->willReturn(true);
     /** @var SymlinkFilesystem|\PHPUnit_Framework_MockObject_MockObject $filesystem */
     $filesystem = $this->getMock('\\LEtudiant\\Composer\\Util\\SymlinkFilesystem');
     $filesystem->expects($this->once())->method('removeSymlink')->willReturn(true);
     $library = new SharedPackageInstaller($this->io, $this->composer, $filesystem, $this->dataManager);
     $package = $this->createDevelopmentPackageMock();
     $this->repository->expects($this->exactly(1))->method('hasPackage')->with($package)->will($this->onConsecutiveCalls(true, true));
     $this->repository->expects($this->once())->method('removePackage')->with($package);
     $this->dm->expects($this->once())->method('remove')->with($package, $this->dependenciesDir . '/letudiant/foo-bar/dev-develop');
     $this->dataManager->expects($this->once())->method('removePackageUsage')->with($package);
     $library->uninstall($this->repository, $package);
 }
 public function testIgnoredBundles()
 {
     $packages = array($this->createPackage('foo/foo-bundle', 'symfony-bundle', array('psr-0' => array('Acme\\FooBundle' => ''))), $this->createPackage('acme/library-bundle', 'symfony-bundle', array('psr-0' => array('Acme\\LibraryBundle' => ''))));
     $rootPackage = new RootPackage('DemoPackage', 'dev-master', '1.x-dev');
     $rootPackage->setExtra(array('checkbundles-ignore' => array('Acme\\LibraryBundle\\AcmeLibraryBundle')));
     $this->composerMock->expects($this->any())->method('getPackage')->will($this->returnValue($rootPackage));
     $this->localRepository->expects($this->any())->method('getPackages')->will($this->returnValue($packages));
     $kernelHelper = $this->getMockBuilder('WillemJan\\Util\\KernelHelper')->disableOriginalConstructor()->setMethods(array('getBundlesForKernels'))->getMock();
     $kernelHelper->expects($this->any())->method('getBundlesForKernels')->will($this->returnValue(array('Acme\\FooBundle\\AcmeFooBundle')));
     $composerHelper = $this->getMockBuilder('WillemJan\\CheckBundles\\Util\\ComposerHelper')->setConstructorArgs(array($this->composerMock))->setMethods(array('getInstalledRepository', 'findBundleFiles'))->getMock();
     $composerHelper->expects($this->any())->method('findBundleFiles')->will($this->returnCallback(function ($package) use($packages) {
         switch ($package->getName()) {
             case 'foo/foo-bundle':
                 return array('AcmeFooBundle.php');
                 break;
             case 'acme/library-bundle':
                 return array('AcmeLibraryBundle.php');
                 break;
         }
         return array('ShouldNotHappenBundle.php');
     }));
     $composerHelper->expects($this->any())->method('getInstalledRepository')->will($this->returnValue($this->localRepository));
     $this->assertEquals(array(), $composerHelper->getNonActiveSymfonyBundles($kernelHelper->getBundlesForKernels()));
 }
    public function testVendorSubstringPath()
    {
        $package = new Package('a', '1.0', '1.0');
        $package->setAutoload(array('psr-0' => array('Foo' => 'composer-test-autoload-src/src'), 'psr-4' => array('Acme\\Foo\\' => 'composer-test-autoload-src/src-psr4')));
        $this->repository->expects($this->once())->method('getCanonicalPackages')->will($this->returnValue(array()));
        $this->fs->ensureDirectoryExists($this->vendorDir . '/a');
        $expectedNamespace = <<<'EOF'
<?php

// autoload_namespaces.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
    'Foo' => array($baseDir . '/composer-test-autoload-src/src'),
);

EOF;
        $expectedPsr4 = <<<'EOF'
<?php

// autoload_psr4.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
    'Acme\\Foo\\' => array($baseDir . '/composer-test-autoload-src/src-psr4'),
);

EOF;
        $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'VendorSubstring');
        $this->assertEquals($expectedNamespace, file_get_contents($this->vendorDir . '/composer/autoload_namespaces.php'));
        $this->assertEquals($expectedPsr4, file_get_contents($this->vendorDir . '/composer/autoload_psr4.php'));
    }