예제 #1
0
 /**
  * @dataProvider getIntegrationTests
  */
 public function testIntegration($file, $message, $condition, $composerConfig, $lock, $installed, $run, $expectLock, $expectOutput, $expect, $expectResult)
 {
     if ($condition) {
         eval('$res = ' . $condition . ';');
         if (!$res) {
             $this->markTestSkipped($condition);
         }
     }
     $io = new BufferIO('', OutputInterface::VERBOSITY_NORMAL, new OutputFormatter(false));
     // Prepare for exceptions
     if (!is_int($expectResult)) {
         $normalizedOutput = rtrim(str_replace("\n", PHP_EOL, $expect));
         $this->setExpectedException($expectResult, $normalizedOutput);
     }
     // Create Composer mock object according to configuration
     $composer = FactoryMock::create($io, $composerConfig);
     $this->tempComposerHome = $composer->getConfig()->get('home');
     $jsonMock = $this->getMockBuilder('Composer\\Json\\JsonFile')->disableOriginalConstructor()->getMock();
     $jsonMock->expects($this->any())->method('read')->will($this->returnValue($installed));
     $jsonMock->expects($this->any())->method('exists')->will($this->returnValue(true));
     $repositoryManager = $composer->getRepositoryManager();
     $repositoryManager->setLocalRepository(new InstalledFilesystemRepositoryMock($jsonMock));
     $lockJsonMock = $this->getMockBuilder('Composer\\Json\\JsonFile')->disableOriginalConstructor()->getMock();
     $lockJsonMock->expects($this->any())->method('read')->will($this->returnValue($lock));
     $lockJsonMock->expects($this->any())->method('exists')->will($this->returnValue(true));
     if ($expectLock) {
         $actualLock = array();
         $lockJsonMock->expects($this->atLeastOnce())->method('write')->will($this->returnCallback(function ($hash, $options) use(&$actualLock) {
             // need to do assertion outside of mock for nice phpunit output
             // so store value temporarily in reference for later assetion
             $actualLock = $hash;
         }));
     }
     $contents = json_encode($composerConfig);
     $locker = new Locker($io, $lockJsonMock, $repositoryManager, $composer->getInstallationManager(), $contents);
     $composer->setLocker($locker);
     $eventDispatcher = $this->getMockBuilder('Composer\\EventDispatcher\\EventDispatcher')->disableOriginalConstructor()->getMock();
     $autoloadGenerator = $this->getMock('Composer\\Autoload\\AutoloadGenerator', array(), array($eventDispatcher));
     $composer->setAutoloadGenerator($autoloadGenerator);
     $composer->setEventDispatcher($eventDispatcher);
     $installer = Installer::create($io, $composer);
     $application = new Application();
     $application->get('install')->setCode(function ($input, $output) use($installer) {
         $installer->setDevMode(!$input->getOption('no-dev'))->setDryRun($input->getOption('dry-run'))->setIgnorePlatformRequirements($input->getOption('ignore-platform-reqs'));
         return $installer->run();
     });
     $application->get('update')->setCode(function ($input, $output) use($installer) {
         $installer->setDevMode(!$input->getOption('no-dev'))->setUpdate(true)->setDryRun($input->getOption('dry-run'))->setUpdateWhitelist($input->getArgument('packages'))->setWhitelistDependencies($input->getOption('with-dependencies'))->setPreferStable($input->getOption('prefer-stable'))->setPreferLowest($input->getOption('prefer-lowest'))->setIgnorePlatformRequirements($input->getOption('ignore-platform-reqs'));
         return $installer->run();
     });
     if (!preg_match('{^(install|update)\\b}', $run)) {
         throw new \UnexpectedValueException('The run command only supports install and update');
     }
     $application->setAutoExit(false);
     $appOutput = fopen('php://memory', 'w+');
     $result = $application->run(new StringInput($run), new StreamOutput($appOutput));
     fseek($appOutput, 0);
     // Shouldn't check output and results if an exception was expected by this point
     if (!is_int($expectResult)) {
         return;
     }
     $output = str_replace("\r", '', $io->getOutput());
     $this->assertEquals($expectResult, $result, $output . stream_get_contents($appOutput));
     if ($expectLock) {
         unset($actualLock['hash']);
         unset($actualLock['content-hash']);
         unset($actualLock['_readme']);
         $this->assertEquals($expectLock, $actualLock);
     }
     $installationManager = $composer->getInstallationManager();
     $this->assertSame(rtrim($expect), implode("\n", $installationManager->getTrace()));
     if ($expectOutput) {
         $this->assertStringMatchesFormat(rtrim($expectOutput), rtrim($output));
     }
 }
예제 #2
0
    /**
     * @dataProvider getIntegrationTests
     */
    public function testIntegration($file, $message, $condition, $composerConfig, $lock, $installed, $run, $expectLock, $expectOutput, $expect)
    {
        if ($condition) {
            eval('$res = '.$condition.';');
            if (!$res) {
                $this->markTestSkipped($condition);
            }
        }

        $output = null;
        $io = $this->getMock('Composer\IO\IOInterface');
        $io->expects($this->any())
            ->method('write')
            ->will($this->returnCallback(function ($text, $newline) use (&$output) {
                $output .= $text . ($newline ? "\n":"");
            }));

        $composer = FactoryMock::create($io, $composerConfig);

        $jsonMock = $this->getMockBuilder('Composer\Json\JsonFile')->disableOriginalConstructor()->getMock();
        $jsonMock->expects($this->any())
            ->method('read')
            ->will($this->returnValue($installed));
        $jsonMock->expects($this->any())
            ->method('exists')
            ->will($this->returnValue(true));

        $repositoryManager = $composer->getRepositoryManager();
        $repositoryManager->setLocalRepository(new InstalledFilesystemRepositoryMock($jsonMock));

        $lockJsonMock = $this->getMockBuilder('Composer\Json\JsonFile')->disableOriginalConstructor()->getMock();
        $lockJsonMock->expects($this->any())
            ->method('read')
            ->will($this->returnValue($lock));
        $lockJsonMock->expects($this->any())
            ->method('exists')
            ->will($this->returnValue(true));

        if ($expectLock) {
            $actualLock = array();
            $lockJsonMock->expects($this->atLeastOnce())
                ->method('write')
                ->will($this->returnCallback(function ($hash, $options) use (&$actualLock) {
                    // need to do assertion outside of mock for nice phpunit output
                    // so store value temporarily in reference for later assetion
                    $actualLock = $hash;
                }));
        }

        $locker = new Locker($lockJsonMock, $repositoryManager, $composer->getInstallationManager(), md5(json_encode($composerConfig)));
        $composer->setLocker($locker);

        $eventDispatcher = $this->getMockBuilder('Composer\Script\EventDispatcher')->disableOriginalConstructor()->getMock();
        $autoloadGenerator = $this->getMock('Composer\Autoload\AutoloadGenerator', array(), array($eventDispatcher));
        $composer->setAutoloadGenerator($autoloadGenerator);
        $composer->setEventDispatcher($eventDispatcher);

        $installer = Installer::create(
            $io,
            $composer
        );

        $application = new Application;
        $application->get('install')->setCode(function ($input, $output) use ($installer) {
            $installer->setDevMode($input->getOption('dev'));

            return $installer->run() ? 0 : 1;
        });

        $application->get('update')->setCode(function ($input, $output) use ($installer) {
            $installer
                ->setDevMode($input->getOption('dev'))
                ->setUpdate(true)
                ->setUpdateWhitelist($input->getArgument('packages'));

            return $installer->run() ? 0 : 1;
        });

        if (!preg_match('{^(install|update)\b}', $run)) {
            throw new \UnexpectedValueException('The run command only supports install and update');
        }

        $application->setAutoExit(false);
        $appOutput = fopen('php://memory', 'w+');
        $result = $application->run(new StringInput($run), new StreamOutput($appOutput));
        fseek($appOutput, 0);
        $this->assertEquals(0, $result, $output . stream_get_contents($appOutput));

        if ($expectLock) {
            unset($actualLock['hash']);
            unset($actualLock['_readme']);
            $this->assertEquals($expectLock, $actualLock);
        }

        $installationManager = $composer->getInstallationManager();
        $this->assertSame($expect, implode("\n", $installationManager->getTrace()));

        if ($expectOutput) {
            $this->assertEquals($expectOutput, $output);
        }
    }
예제 #3
0
 /**
  * @dataProvider getIntegrationTests
  */
 public function testIntegration($file, $message, $condition, $composerConfig, $lock, $installed, $installedDev, $run, $expect)
 {
     if ($condition) {
         eval('$res = ' . $condition . ';');
         if (!$res) {
             $this->markTestSkipped($condition);
         }
     }
     $output = null;
     $io = $this->getMock('Composer\\IO\\IOInterface');
     $io->expects($this->any())->method('write')->will($this->returnCallback(function ($text, $newline) use(&$output) {
         $output .= $text . ($newline ? "\n" : "");
     }));
     $composer = FactoryMock::create($io, $composerConfig);
     $jsonMock = $this->getMockBuilder('Composer\\Json\\JsonFile')->disableOriginalConstructor()->getMock();
     $jsonMock->expects($this->any())->method('read')->will($this->returnValue($installed));
     $jsonMock->expects($this->any())->method('exists')->will($this->returnValue(true));
     $devJsonMock = $this->getMockBuilder('Composer\\Json\\JsonFile')->disableOriginalConstructor()->getMock();
     $devJsonMock->expects($this->any())->method('read')->will($this->returnValue($installedDev));
     $devJsonMock->expects($this->any())->method('exists')->will($this->returnValue(true));
     $repositoryManager = $composer->getRepositoryManager();
     $repositoryManager->setLocalRepository(new InstalledFilesystemRepositoryMock($jsonMock));
     $repositoryManager->setLocalDevRepository(new InstalledFilesystemRepositoryMock($devJsonMock));
     $lockJsonMock = $this->getMockBuilder('Composer\\Json\\JsonFile')->disableOriginalConstructor()->getMock();
     $lockJsonMock->expects($this->any())->method('read')->will($this->returnValue($lock));
     $lockJsonMock->expects($this->any())->method('exists')->will($this->returnValue(true));
     $locker = new Locker($lockJsonMock, $repositoryManager, $composer->getInstallationManager(), md5(json_encode($composerConfig)));
     $composer->setLocker($locker);
     $autoloadGenerator = $this->getMock('Composer\\Autoload\\AutoloadGenerator');
     $installer = Installer::create($io, $composer, null, $autoloadGenerator);
     $application = new Application();
     $application->get('install')->setCode(function ($input, $output) use($installer) {
         $installer->setDevMode($input->getOption('dev'));
         return $installer->run();
     });
     $application->get('update')->setCode(function ($input, $output) use($installer) {
         $installer->setDevMode($input->getOption('dev'))->setUpdate(true)->setUpdateWhitelist($input->getArgument('packages'));
         return $installer->run();
     });
     if (!preg_match('{^(install|update)\\b}', $run)) {
         throw new \UnexpectedValueException('The run command only supports install and update');
     }
     $application->setAutoExit(false);
     $appOutput = fopen('php://memory', 'w+');
     $result = $application->run(new StringInput($run), new StreamOutput($appOutput));
     fseek($appOutput, 0);
     $this->assertEquals(0, $result, $output . stream_get_contents($appOutput));
     $installationManager = $composer->getInstallationManager();
     $this->assertSame($expect, implode("\n", $installationManager->getTrace()));
 }