Created
July 25, 2014 09:30
-
-
Save tomjn/1b642cfdf9e93a73efd1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "tomjn/composer-webtest", | |
"description": "tests for web based composer uis", | |
"license": "GPL-V2.0", | |
"authors": [ | |
{ | |
"name": "Tom J Nowell", | |
"email": "contact@tomjn.com" | |
} | |
], | |
"minimum-stability": "dev", | |
"require": { | |
"composer/composer": "*" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Composer\IO\NullIO; | |
use Composer\Installer; | |
use Composer\Plugin\CommandEvent; | |
use Composer\Plugin\PluginEvents; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Input\InputOption; | |
use Symfony\Component\Console\Input\InputArgument; | |
use Symfony\Component\Console\Input\StringInput; | |
use Symfony\Component\Console\Output\NullOutput; | |
use Symfony\Component\Console\Output\OutputInterface; | |
if ( file_exists( 'vendor/autoload.php' ) ) { | |
require 'vendor/autoload.php'; | |
} else { | |
echo '<p>You must run composer install on this folder for the needed dependencies</p>'; | |
} | |
echo '<p>hello there, there should be a test folder with a composer.json in it. This script will change into that directory and attempt a composer install</p>'; | |
chdir( 'test' ); | |
// a lot of this was taken from the install command | |
$factory = new Composer\Factory(); | |
$io = new NullIO(); | |
$composer = $factory->createComposer( $io ); | |
$composer->getDownloadManager()->setOutputProgress( false ); | |
$output = new NullOutput(); | |
$input = new StringInput( '' ); | |
$commandEvent = new CommandEvent( PluginEvents::COMMAND, 'install', $input, $output ); | |
$composer->getEventDispatcher()->dispatch( $commandEvent->getName(), $commandEvent ); | |
$install = Installer::create( $io, $composer ); | |
$preferSource = false; | |
$preferDist = false; | |
$config = $composer->getConfig(); | |
switch ($config->get('preferred-install')) { | |
case 'source': | |
$preferSource = true; | |
break; | |
case 'dist': | |
$preferDist = true; | |
break; | |
case 'auto': | |
default: | |
// noop | |
break; | |
} | |
$optimize = $config->get('optimize-autoloader'); | |
$install | |
->setDryRun( false) | |
->setVerbose( false ) | |
->setPreferSource( false ) | |
->setPreferDist( true ) | |
->setDevMode( false) | |
->setRunScripts( false ) | |
->setOptimizeAutoloader( $optimize ) | |
; | |
echo '<p>Created and configured composer objects, running install</p>'; | |
$result = $install->run(); | |
echo '<p>Installer ran, and returned with value: <code>'.print_r( $result, true ).'</code></p>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment