Skip to content

Commit

Permalink
Merge pull request #14 from puli/integration-tests
Browse files Browse the repository at this point in the history
Added integration tests to spot and fix regressions
  • Loading branch information
webmozart committed Oct 6, 2015
2 parents c085d87 + 39353ac commit f88b802
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 13 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/docs/man
/docs/html
/docs/*.xml
composer.lock
puli.json
box.json
.puli
/composer.lock
/puli.json
/box.json
/.puli
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand All @@ -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",
Expand Down
Empty file.
8 changes: 8 additions & 0 deletions tests/Fixtures/root/puli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"version": "1.0",
"packages": {
"puli/url-generator": {
"install-path": "vendor/puli/url-generator"
}
}
}
Empty file.
Empty file.
137 changes: 131 additions & 6 deletions tests/PuliBinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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;
}
}

0 comments on commit f88b802

Please sign in to comment.