diff --git a/.gitignore b/.gitignore index 04c329d..ba18a1a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ /docs/man /docs/html /docs/*.xml -composer.lock -puli.json -box.json -.puli +/composer.lock +/puli.json +/box.json +/.puli diff --git a/CHANGELOG.md b/CHANGELOG.md index 56cfffc..5361b98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog ========= +* 1.0.0-beta9 (2015-10-06) + + * added integration tests to spot and fix regressions + * 1.0.0-beta8 (2015-10-05) * changed `puli bind` command to generate `ClassBinding` instances when passing diff --git a/composer.json b/composer.json index 14f1868..f52ec97 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "puli/cli", - "description": "A Command Line Interface (CLI) for managing Puli repositories.", + "description": "A Command Line Interface (CLI) for managing Puli projects.", "homepage": "http://puli.io", "license": "MIT", "authors": [ @@ -11,10 +11,10 @@ ], "require": { "php": ">=5.3.9", - "puli/repository": "1.0.*", + "puli/repository": "^1.0-beta8,<1.1", "puli/discovery": "^1.0-beta8", "puli/url-generator": "^1.0", - "puli/manager": "^1.0-beta8", + "puli/manager": "^1.0-beta9", "webmozart/console": "^1.0-beta2", "webmozart/path-util": "^2.2.2", "webmozart/key-value-store": "^1.0.0-beta5", diff --git a/tests/Fixtures/root/public_html/.gitkeep b/tests/Fixtures/root/public_html/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/Fixtures/root/puli.json b/tests/Fixtures/root/puli.json new file mode 100644 index 0000000..c309212 --- /dev/null +++ b/tests/Fixtures/root/puli.json @@ -0,0 +1,8 @@ +{ + "version": "1.0", + "packages": { + "puli/url-generator": { + "install-path": "vendor/puli/url-generator" + } + } +} diff --git a/tests/Fixtures/root/res/messages.en.yml b/tests/Fixtures/root/res/messages.en.yml new file mode 100644 index 0000000..e69de29 diff --git a/tests/Fixtures/root/res/public/style.css b/tests/Fixtures/root/res/public/style.css new file mode 100644 index 0000000..e69de29 diff --git a/tests/PuliBinTest.php b/tests/PuliBinTest.php index 23c4959..f0145eb 100644 --- a/tests/PuliBinTest.php +++ b/tests/PuliBinTest.php @@ -12,8 +12,11 @@ namespace Puli\Cli\Tests; use PHPUnit_Framework_TestCase; +use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Process\PhpExecutableFinder; use Symfony\Component\Process\Process; +use Symfony\Component\Process\ProcessUtils; +use Webmozart\Glob\Test\TestUtil; use Webmozart\PathUtil\Path; /** @@ -23,21 +26,143 @@ */ class PuliBinTest extends PHPUnit_Framework_TestCase { - public function testRunHelp() + private static $php; + + private $rootDir; + + private $puli; + + public static function setUpBeforeClass() { $phpFinder = new PhpExecutableFinder(); - if (!($php = $phpFinder->find())) { + self::$php = $phpFinder->find(); + } + + protected function setUp() + { + if (!self::$php) { $this->markTestSkipped('The "php" command could not be found.'); } - $rootDir = Path::normalize(realpath(__DIR__.'/..')); - $process = new Process($php.' '.$rootDir.'/bin/puli'); + $this->rootDir = TestUtil::makeTempDir('puli-manager', __CLASS__); + $this->puli = Path::canonicalize(__DIR__.'/../bin/puli'); + + $filesystem = new Filesystem(); + $filesystem->mirror(__DIR__.'/Fixtures/root', $this->rootDir); + + // Load the package to import the "puli/public-resource" type + $filesystem->mirror(__DIR__.'/../vendor/puli/url-generator', $this->rootDir.'/vendor/puli/url-generator'); + } + + protected function tearDown() + { + $filesystem = new Filesystem(); + $filesystem->remove($this->rootDir); + } + + public function testHelp() + { + $output = $this->runPuli(''); + + $this->assertTrue(0 === strpos($output, 'Puli version ') || 0 === strpos($output, "Debug Mode\nPuli version ")); + } + + public function testMap() + { + $mappingExistsRegExp = '~\s/app\s+res\s~'; + + $this->assertEmpty($this->runPuli('map /app res')); + $this->assertRegExp($mappingExistsRegExp, $this->runPuli('map')); + $this->assertRegExp('~^app\s~', $this->runPuli('ls')); + $this->assertRegExp('~^messages.en.yml\s~', $this->runPuli('ls app')); + $this->assertRegExp('~\s/app/messages.en.yml\s~', $this->runPuli('find --name *.yml')); + $this->assertEmpty($this->runPuli('map -d /app')); + $this->assertNotRegExp($mappingExistsRegExp, $this->runPuli('map')); + } + + public function testType() + { + $typeExistsRegExp = '~\sthor/catalog\s~'; + + $this->assertEmpty($this->runPuli('type --define thor/catalog')); + $this->assertRegExp($typeExistsRegExp, $this->runPuli('type')); + $this->assertEmpty($this->runPuli('type -d thor/catalog')); + $this->assertNotRegExp($typeExistsRegExp, $this->runPuli('type')); + } + + /** + * @depends testMap + * @depends testType + */ + public function testBind() + { + $bindingExistsRegExp = '~\s/app/\*\.yml\s+thor/catalog\s~'; + + $this->runPuli('map /app res'); + $this->runPuli('type --define thor/catalog'); + + $this->assertEmpty($this->runPuli('bind /app/*.yml thor/catalog')); + + $output = $this->runPuli('bind'); + + $this->assertRegExp($bindingExistsRegExp, $output); + $this->assertSame(1, preg_match('~\s(\S+)\s+/app/\*\.yml~', $output, $matches)); + + $uuid = $matches[1]; + + $this->assertEmpty($this->runPuli('bind -d '.$uuid)); + $this->assertNotRegExp($bindingExistsRegExp, $this->runPuli('bind')); + } + + public function testServer() + { + $serverExistsRegExp = '~\slocalhost\s~'; + + $this->assertEmpty($this->runPuli('server --add localhost public_html')); + $this->assertRegExp($serverExistsRegExp, $this->runPuli('server')); + $this->assertEmpty($this->runPuli('server -d localhost')); + $this->assertNotRegExp($serverExistsRegExp, $this->runPuli('server')); + } + + /** + * @depends testServer + */ + public function testPublish() + { + $assetExistsRegExp = '~\s/app/public\s+/\s~'; + + $this->runPuli('build'); + $this->runPuli('map /app res'); + $this->runPuli('server --add localhost public_html'); + + $this->assertEmpty($this->runPuli('publish /app/public localhost')); + + $output = $this->runPuli('publish'); + $this->assertRegExp($assetExistsRegExp, $output); + $this->assertSame(1, preg_match('~\s(\S+)\s+/app/public~', $output, $matches)); + + $uuid = $matches[1]; + + $this->assertEmpty($this->runPuli('publish -d '.$uuid)); + $this->assertNotRegExp($assetExistsRegExp, $this->runPuli('publish')); + } + + private function runPuli($command) + { + $php = escapeshellcmd(self::$php); + $puli = ProcessUtils::escapeArgument($this->puli); + $process = new Process($php.' '.$puli.' '.$command, $this->rootDir); $status = $process->run(); - $output = $process->getOutput(); + $output = (string) $process->getOutput(); + + if (0 !== $status) { + var_dump($process->getErrorOutput()); + } $this->assertSame(0, $status); - $this->assertTrue(0 === strpos($output, 'Puli version ') || 0 === strpos($output, "Debug Mode\nPuli version ")); + + return $output; } }