Skip to content

Commit e1e30a5

Browse files
committed
Add a test for non-git package skip in update command
1 parent f7821d1 commit e1e30a5

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

tests/Phug/Command/UpdateTest.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,86 @@ public function testSetGitCommitter()
133133
$output
134134
);
135135
}
136+
137+
/**
138+
* @covers ::distributePackage
139+
*/
140+
public function testErrors()
141+
{
142+
$cwd = getcwd();
143+
$cli = new Split();
144+
$cli->setEscapeCharacter('#');
145+
$dist = new Update();
146+
147+
$directory1 = sys_get_temp_dir().'/split-test-'.mt_rand(0, 9999999);
148+
FileSystem::createDir($directory1);
149+
FileSystem::createDir("$directory1/sub-package");
150+
FileSystem::createDir("$directory1/api/vendor");
151+
$directory1 = realpath($directory1);
152+
153+
$directory2 = sys_get_temp_dir().'/split-test-'.mt_rand(0, 9999999);
154+
FileSystem::createDir("$directory2/tests");
155+
$directory2 = realpath($directory2);
156+
157+
chdir($directory1);
158+
file_put_contents('composer.json', json_encode(['name' => 'vendor/package']));
159+
file_put_contents('sub-package/composer.json', json_encode(['name' => 'vendor/sub-package']));
160+
file_put_contents('a.txt', 'A');
161+
file_put_contents('b.txt', 'B');
162+
file_put_contents('c.txt', 'C');
163+
shell_exec('git init 2>&1');
164+
shell_exec('git add --all 2>&1');
165+
shell_exec('git commit --message=Init 2>&1');
166+
preg_match('/^commit (\S+)/', shell_exec('git log -n 1'), $match);
167+
$hash1 = $match[1];
168+
169+
file_put_contents('api/vendor/sub-package.json', json_encode([
170+
'packages' => [
171+
'vendor/sub-package' => [
172+
'dev-master' => [
173+
'source' => [
174+
'type' => 'snv',
175+
'url' => $directory2,
176+
],
177+
],
178+
],
179+
],
180+
]));
181+
182+
chdir($directory2);
183+
file_put_contents('composer.json', json_encode(['name' => 'vendor/sub-package']));
184+
file_put_contents('d.txt', 'D');
185+
file_put_contents('e.txt', 'E');
186+
file_put_contents('f.txt', 'F');
187+
shell_exec('git init 2>&1');
188+
shell_exec('git add --all 2>&1');
189+
file_put_contents('message.txt', "ABC\n\nsplit: $hash1");
190+
shell_exec('git commit --file=message.txt 2>&1');
191+
preg_match('/^commit (\S+)/', shell_exec('git log -n 1'), $match);
192+
193+
chdir($directory1);
194+
195+
ob_start();
196+
$dist->api = 'api/%s.json';
197+
$return = $dist->run($cli);
198+
$output = ob_get_contents();
199+
ob_end_clean();
200+
201+
chdir($cwd);
202+
203+
foreach ([$directory1, $directory2] as $directory) {
204+
@shell_exec('rm -rf ' . escapeshellarg($directory) . ' 2>&1');
205+
file_exists($directory) && @shell_exec('rmdir /S /Q ' . escapeshellarg($directory) . ' 2>&1');
206+
@FileSystem::delete($directory);
207+
}
208+
209+
$outputDirectory = $directory1.DIRECTORY_SEPARATOR.'dist';
210+
211+
$this->assertSame(
212+
"vendor/package\n#[0;31mNo git source found for the package vendor/sub-package\n".
213+
"#[0m#[1;35mBuild distributed in $outputDirectory\n#[0m",
214+
$output
215+
);
216+
$this->assertTrue($return);
217+
}
136218
}

0 commit comments

Comments
 (0)