Skip to content

Commit f88b802

Browse files
committed
Merge pull request #14 from puli/integration-tests
Added integration tests to spot and fix regressions
2 parents c085d87 + 39353ac commit f88b802

8 files changed

Lines changed: 150 additions & 13 deletions

File tree

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/docs/man
44
/docs/html
55
/docs/*.xml
6-
composer.lock
7-
puli.json
8-
box.json
9-
.puli
6+
/composer.lock
7+
/puli.json
8+
/box.json
9+
/.puli

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changelog
22
=========
33

4+
* 1.0.0-beta9 (2015-10-06)
5+
6+
* added integration tests to spot and fix regressions
7+
48
* 1.0.0-beta8 (2015-10-05)
59

610
* changed `puli bind` command to generate `ClassBinding` instances when passing

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "puli/cli",
3-
"description": "A Command Line Interface (CLI) for managing Puli repositories.",
3+
"description": "A Command Line Interface (CLI) for managing Puli projects.",
44
"homepage": "http://puli.io",
55
"license": "MIT",
66
"authors": [
@@ -11,10 +11,10 @@
1111
],
1212
"require": {
1313
"php": ">=5.3.9",
14-
"puli/repository": "1.0.*",
14+
"puli/repository": "^1.0-beta8,<1.1",
1515
"puli/discovery": "^1.0-beta8",
1616
"puli/url-generator": "^1.0",
17-
"puli/manager": "^1.0-beta8",
17+
"puli/manager": "^1.0-beta9",
1818
"webmozart/console": "^1.0-beta2",
1919
"webmozart/path-util": "^2.2.2",
2020
"webmozart/key-value-store": "^1.0.0-beta5",

tests/Fixtures/root/public_html/.gitkeep

Whitespace-only changes.

tests/Fixtures/root/puli.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"version": "1.0",
3+
"packages": {
4+
"puli/url-generator": {
5+
"install-path": "vendor/puli/url-generator"
6+
}
7+
}
8+
}

tests/Fixtures/root/res/messages.en.yml

Whitespace-only changes.

tests/Fixtures/root/res/public/style.css

Whitespace-only changes.

tests/PuliBinTest.php

Lines changed: 131 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
namespace Puli\Cli\Tests;
1313

1414
use PHPUnit_Framework_TestCase;
15+
use Symfony\Component\Filesystem\Filesystem;
1516
use Symfony\Component\Process\PhpExecutableFinder;
1617
use Symfony\Component\Process\Process;
18+
use Symfony\Component\Process\ProcessUtils;
19+
use Webmozart\Glob\Test\TestUtil;
1720
use Webmozart\PathUtil\Path;
1821

1922
/**
@@ -23,21 +26,143 @@
2326
*/
2427
class PuliBinTest extends PHPUnit_Framework_TestCase
2528
{
26-
public function testRunHelp()
29+
private static $php;
30+
31+
private $rootDir;
32+
33+
private $puli;
34+
35+
public static function setUpBeforeClass()
2736
{
2837
$phpFinder = new PhpExecutableFinder();
2938

30-
if (!($php = $phpFinder->find())) {
39+
self::$php = $phpFinder->find();
40+
}
41+
42+
protected function setUp()
43+
{
44+
if (!self::$php) {
3145
$this->markTestSkipped('The "php" command could not be found.');
3246
}
3347

34-
$rootDir = Path::normalize(realpath(__DIR__.'/..'));
35-
$process = new Process($php.' '.$rootDir.'/bin/puli');
48+
$this->rootDir = TestUtil::makeTempDir('puli-manager', __CLASS__);
49+
$this->puli = Path::canonicalize(__DIR__.'/../bin/puli');
50+
51+
$filesystem = new Filesystem();
52+
$filesystem->mirror(__DIR__.'/Fixtures/root', $this->rootDir);
53+
54+
// Load the package to import the "puli/public-resource" type
55+
$filesystem->mirror(__DIR__.'/../vendor/puli/url-generator', $this->rootDir.'/vendor/puli/url-generator');
56+
}
57+
58+
protected function tearDown()
59+
{
60+
$filesystem = new Filesystem();
61+
$filesystem->remove($this->rootDir);
62+
}
63+
64+
public function testHelp()
65+
{
66+
$output = $this->runPuli('');
67+
68+
$this->assertTrue(0 === strpos($output, 'Puli version ') || 0 === strpos($output, "Debug Mode\nPuli version "));
69+
}
70+
71+
public function testMap()
72+
{
73+
$mappingExistsRegExp = '~\s/app\s+res\s~';
74+
75+
$this->assertEmpty($this->runPuli('map /app res'));
76+
$this->assertRegExp($mappingExistsRegExp, $this->runPuli('map'));
77+
$this->assertRegExp('~^app\s~', $this->runPuli('ls'));
78+
$this->assertRegExp('~^messages.en.yml\s~', $this->runPuli('ls app'));
79+
$this->assertRegExp('~\s/app/messages.en.yml\s~', $this->runPuli('find --name *.yml'));
80+
$this->assertEmpty($this->runPuli('map -d /app'));
81+
$this->assertNotRegExp($mappingExistsRegExp, $this->runPuli('map'));
82+
}
83+
84+
public function testType()
85+
{
86+
$typeExistsRegExp = '~\sthor/catalog\s~';
87+
88+
$this->assertEmpty($this->runPuli('type --define thor/catalog'));
89+
$this->assertRegExp($typeExistsRegExp, $this->runPuli('type'));
90+
$this->assertEmpty($this->runPuli('type -d thor/catalog'));
91+
$this->assertNotRegExp($typeExistsRegExp, $this->runPuli('type'));
92+
}
93+
94+
/**
95+
* @depends testMap
96+
* @depends testType
97+
*/
98+
public function testBind()
99+
{
100+
$bindingExistsRegExp = '~\s/app/\*\.yml\s+thor/catalog\s~';
101+
102+
$this->runPuli('map /app res');
103+
$this->runPuli('type --define thor/catalog');
104+
105+
$this->assertEmpty($this->runPuli('bind /app/*.yml thor/catalog'));
106+
107+
$output = $this->runPuli('bind');
108+
109+
$this->assertRegExp($bindingExistsRegExp, $output);
110+
$this->assertSame(1, preg_match('~\s(\S+)\s+/app/\*\.yml~', $output, $matches));
111+
112+
$uuid = $matches[1];
113+
114+
$this->assertEmpty($this->runPuli('bind -d '.$uuid));
115+
$this->assertNotRegExp($bindingExistsRegExp, $this->runPuli('bind'));
116+
}
117+
118+
public function testServer()
119+
{
120+
$serverExistsRegExp = '~\slocalhost\s~';
121+
122+
$this->assertEmpty($this->runPuli('server --add localhost public_html'));
123+
$this->assertRegExp($serverExistsRegExp, $this->runPuli('server'));
124+
$this->assertEmpty($this->runPuli('server -d localhost'));
125+
$this->assertNotRegExp($serverExistsRegExp, $this->runPuli('server'));
126+
}
127+
128+
/**
129+
* @depends testServer
130+
*/
131+
public function testPublish()
132+
{
133+
$assetExistsRegExp = '~\s/app/public\s+/\s~';
134+
135+
$this->runPuli('build');
136+
$this->runPuli('map /app res');
137+
$this->runPuli('server --add localhost public_html');
138+
139+
$this->assertEmpty($this->runPuli('publish /app/public localhost'));
140+
141+
$output = $this->runPuli('publish');
36142

143+
$this->assertRegExp($assetExistsRegExp, $output);
144+
$this->assertSame(1, preg_match('~\s(\S+)\s+/app/public~', $output, $matches));
145+
146+
$uuid = $matches[1];
147+
148+
$this->assertEmpty($this->runPuli('publish -d '.$uuid));
149+
$this->assertNotRegExp($assetExistsRegExp, $this->runPuli('publish'));
150+
}
151+
152+
private function runPuli($command)
153+
{
154+
$php = escapeshellcmd(self::$php);
155+
$puli = ProcessUtils::escapeArgument($this->puli);
156+
$process = new Process($php.' '.$puli.' '.$command, $this->rootDir);
37157
$status = $process->run();
38-
$output = $process->getOutput();
158+
$output = (string) $process->getOutput();
159+
160+
if (0 !== $status) {
161+
var_dump($process->getErrorOutput());
162+
}
39163

40164
$this->assertSame(0, $status);
41-
$this->assertTrue(0 === strpos($output, 'Puli version ') || 0 === strpos($output, "Debug Mode\nPuli version "));
165+
166+
return $output;
42167
}
43168
}

0 commit comments

Comments
 (0)