Skip to content

Commit 63b33d4

Browse files
authored
Merge pull request #59 from leviy/fix-missing-file-in-phar
Update box.json to not exclude Changelog.php
2 parents fa03849 + 6391733 commit 63b33d4

File tree

5 files changed

+216
-29
lines changed

5 files changed

+216
-29
lines changed

Diff for: Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ integration-tests: vendor
2828
acceptance-tests: vendor
2929
vendor/bin/behat
3030

31-
system-tests: vendor
31+
system-tests: vendor build/release-tool.phar
3232
vendor/bin/phpunit --testsuite system-tests
3333

3434
coding-standards: vendor
@@ -39,5 +39,5 @@ security-tests: vendor
3939
vendor/bin/security-checker security:check
4040

4141
bin/box.phar:
42-
curl -LS https://github.com/humbug/box/releases/download/3.0.0-RC.0/box.phar -o bin/box.phar
42+
curl -LS https://github.com/humbug/box/releases/download/3.4.0/box.phar -o bin/box.phar
4343
chmod a+x bin/box.phar

Diff for: box.json

+4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
2+
"directories": [
3+
"src"
4+
],
25
"directories-bin": [
36
"config"
47
],
8+
"force-autodiscovery": true,
59
"git-version": "package_version",
610
"output": "build/release-tool.phar"
711
}

Diff for: composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"mockery/mockery": "^1.1",
2222
"phpstan/phpstan": "^0.9.2",
2323
"phpunit/phpunit": "^7.1",
24-
"sensiolabs/security-checker": "^5.0"
24+
"sensiolabs/security-checker": "^5.0",
25+
"symfony/process": "^4.2"
2526
},
2627
"config": {
2728
"sort-packages": true

Diff for: composer.lock

+50-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: tests/system/ApplicationTest.php

+158-25
Original file line numberDiff line numberDiff line change
@@ -3,58 +3,191 @@
33

44
namespace Leviy\ReleaseTool\Tests\System;
55

6-
use Leviy\ReleaseTool\Console\Application;
76
use Leviy\ReleaseTool\Vcs\Git;
87
use PHPUnit\Framework\TestCase;
9-
use Symfony\Component\Console\Tester\ApplicationTester;
10-
use Symfony\Component\DependencyInjection\ContainerBuilder;
8+
use Symfony\Component\Process\InputStream;
9+
use Symfony\Component\Process\Process;
1110
use function exec;
11+
use const PHP_EOL;
1212

1313
class ApplicationTest extends TestCase
1414
{
15-
/**
16-
* @var ApplicationTester
17-
*/
18-
private $applicationTester;
19-
2015
protected function setUp(): void
2116
{
2217
Git::execute('init');
2318
Git::execute('remote add origin [email protected]:org/repo.git');
19+
}
2420

25-
$container = new ContainerBuilder();
26-
$application = new Application($container);
21+
protected function tearDown(): void
22+
{
23+
exec('rm -rf $GIT_DIR');
24+
}
2725

28-
$application->setAutoExit(false);
26+
public function testBootsWithoutErrors(): void
27+
{
28+
$process = new Process(['build/release-tool.phar']);
29+
$process->run();
2930

30-
$this->applicationTester = new ApplicationTester($application);
31+
$this->assertTrue($process->isSuccessful(), 'The command returned a non-zero exit code.');
32+
$this->assertContains('Leviy Release Tool', $process->getOutput());
3133
}
3234

33-
protected function tearDown(): void
35+
public function testAsksForConfirmationBeforeReleasingAVersion(): void
3436
{
35-
exec('rm -rf $GIT_DIR');
37+
if (!Process::isPtySupported()) {
38+
$this->markTestSkipped('PTY is not supported on this operating system.');
39+
}
40+
41+
$this->commitFile('README.md', 'Initial commit');
42+
43+
$input = new InputStream();
44+
45+
$process = new Process(['build/release-tool.phar', 'release', '--no-ansi', '1.0.0']);
46+
$process->setInput($input);
47+
$process->setPty(true);
48+
$process->start();
49+
50+
// EOL simulates [Enter]
51+
// Do you want to continue? (yes/no)
52+
$input->write('no' . PHP_EOL);
53+
$input->close();
54+
55+
$process->wait();
56+
57+
$this->assertContains('This will release version 1.0.0', $process->getOutput());
58+
$this->assertContains('Do you want to continue?', $process->getOutput());
59+
$this->assertEmpty($this->getTags());
60+
}
61+
62+
public function testReleasesWithGivenVersionNumber(): void
63+
{
64+
if (!Process::isPtySupported()) {
65+
$this->markTestSkipped('PTY is not supported on this operating system.');
66+
}
67+
68+
$this->commitFile('README.md', 'Initial commit');
69+
70+
$input = new InputStream();
71+
72+
$process = new Process(['build/release-tool.phar', 'release', '1.0.0']);
73+
$process->setInput($input);
74+
$process->setPty(true);
75+
$process->start();
76+
77+
// EOL simulates [Enter]
78+
// Do you want to continue? (yes/no)
79+
$input->write('yes' . PHP_EOL);
80+
81+
// A VCS tag has been created for version 1.0.0. Do you want to push it to the remote repository and perform
82+
// additional release steps? (yes/no)
83+
$input->write('no' . PHP_EOL);
84+
$input->close();
85+
86+
$process->wait();
87+
88+
$this->assertTrue($process->isSuccessful(), 'The command returned a non-zero exit code.');
89+
$this->assertSame(['v1.0.0'], $this->getTags());
3690
}
3791

38-
public function testThatTheApplicationIsBooted(): void
92+
public function testShowsTheChangelogBeforeAskingInteractiveQuestions(): void
3993
{
40-
$this->applicationTester->run([]);
94+
if (!Process::isPtySupported()) {
95+
$this->markTestSkipped('PTY is not supported on this operating system.');
96+
}
4197

42-
$this->assertOutputContains('Leviy Release Tool', $this->applicationTester);
98+
$this->commitFile('README.md', 'Initial commit');
99+
$this->createTag('v1.0.0');
100+
$this->commitFile('phpunit.xml', 'Merge pull request #3 from branchname' . PHP_EOL . PHP_EOL . 'My PR title');
101+
102+
$input = new InputStream();
103+
104+
$process = new Process(['build/release-tool.phar', 'release']);
105+
$process->setInput($input);
106+
$process->setPty(true);
107+
$process->start();
108+
109+
// EOL simulates [Enter]
110+
// Does this release contain backward incompatible changes? (yes/no)
111+
$input->write('no' . PHP_EOL);
112+
113+
// Does this release contain new features? (yes/no)
114+
$input->write('yes' . PHP_EOL);
115+
116+
// Do you want to continue? (yes/no)
117+
$input->write('no' . PHP_EOL);
118+
$input->close();
119+
120+
$process->wait();
121+
122+
$this->assertContains('My PR title (pull request #3)', $process->getOutput());
43123
}
44124

45-
public function testThatTheApplicationReturnsTheCurrentVersion(): void
125+
public function testDeterminesTheVersionNumberBasedOnInteractiveQuestions(): void
46126
{
47-
Git::execute('add README.md');
48-
Git::execute('commit --no-gpg-sign -m "Test commit"');
49-
Git::execute('tag --annotate --message="Test tag" v1.2.5');
127+
if (!Process::isPtySupported()) {
128+
$this->markTestSkipped('PTY is not supported on this operating system.');
129+
}
130+
131+
$this->commitFile('README.md', 'Initial commit');
132+
$this->createTag('v1.0.0');
133+
$this->commitFile('phpunit.xml', 'Merge pull request #3 from branchname' . PHP_EOL . PHP_EOL . 'Foo');
134+
135+
$input = new InputStream();
136+
137+
$process = new Process(['build/release-tool.phar', 'release']);
138+
$process->setInput($input);
139+
$process->setPty(true);
140+
$process->start();
141+
142+
// EOL simulates [Enter]
143+
// Does this release contain backward incompatible changes? (yes/no)
144+
$input->write('no' . PHP_EOL);
145+
146+
// Does this release contain new features? (yes/no)
147+
$input->write('yes' . PHP_EOL);
148+
149+
// Do you want to continue? (yes/no)
150+
$input->write('yes' . PHP_EOL);
151+
152+
// A VCS tag has been created for version 1.0.0. Do you want to push it to the remote repository and perform
153+
// additional release steps? (yes/no)
154+
$input->write('no' . PHP_EOL);
155+
$input->close();
50156

51-
$this->applicationTester->run(['current']);
157+
$process->wait();
52158

53-
$this->assertOutputContains('Current version:', $this->applicationTester);
159+
$this->assertTrue($process->isSuccessful(), 'The command returned a non-zero exit code.');
160+
$this->assertContains('v1.1.0', $this->getTags());
54161
}
55162

56-
private function assertOutputContains(string $text, ApplicationTester $applicationTester): void
163+
public function testReturnsTheCurrentVersion(): void
164+
{
165+
$this->commitFile('README.md', 'Initial commit');
166+
$this->createTag('v1.2.5');
167+
168+
$process = new Process(['build/release-tool.phar', 'current']);
169+
$process->run();
170+
171+
$this->assertTrue($process->isSuccessful(), 'The command returned a non-zero exit code.');
172+
$this->assertContains('Current version: 1.2.5', $process->getOutput());
173+
}
174+
175+
private function commitFile(string $filename, string $commitMessage): void
176+
{
177+
Git::execute('add ' . $filename);
178+
Git::execute('commit --no-gpg-sign -m "' . $commitMessage . '"');
179+
}
180+
181+
private function createTag(string $tag): void
182+
{
183+
Git::execute('tag --annotate --message="Test tag" ' . $tag);
184+
}
185+
186+
/**
187+
* @return string[]
188+
*/
189+
private function getTags(): array
57190
{
58-
$this->assertContains($text, $applicationTester->getDisplay());
191+
return Git::execute('tag');
59192
}
60193
}

0 commit comments

Comments
 (0)