@@ -12,6 +12,42 @@ class PatchbotCommandsTest extends TestCase
1212 /** @var string[] */
1313 protected $ commandClass ;
1414
15+ protected static $ bareRepository = '' ;
16+
17+ /**
18+ * Set up a bare local Git repository
19+ *
20+ * Additional method since data providers get executed before
21+ * setupBeforeClass, see
22+ * https://github.com/sebastianbergmann/phpunit/issues/836
23+ */
24+ public static function loadFixtures (): void
25+ {
26+ if (empty (self ::$ bareRepository )) {
27+ self ::$ bareRepository = sys_get_temp_dir () . '/ ' . 'patchbot-source-repository- ' . uniqid ('' , true ) . '.git ' ;
28+ $ tmpDirectory = sys_get_temp_dir () . '/ ' . 'patchbot-source-repository-clone- ' . uniqid ('' , true ) . '/ ' ;
29+ exec ('git init --bare ' . self ::$ bareRepository );
30+ exec ('git clone ' . self ::$ bareRepository . ' ' . $ tmpDirectory . ' 2> /dev/null ' );
31+ chdir ($ tmpDirectory );
32+ exec (
'git config --global user.email "[email protected] " && git config --global user.name "Patchbot" ' );
33+ exec ('git checkout --orphan master 2> /dev/null ' );
34+ file_put_contents ($ tmpDirectory . 'README.md ' , '# ACME Project ' . PHP_EOL . 'Hello World ' . PHP_EOL . PHP_EOL );
35+ exec ('git add -A ' );
36+ exec ('git commit -a -m "Add README" ' );
37+ exec ('git push origin master 2> /dev/null ' );
38+ }
39+ }
40+
41+ public static function setUpBeforeClass (): void
42+ {
43+ self ::loadFixtures ();
44+ }
45+
46+ public static function tearDownAfterClass (): void
47+ {
48+ //rmdir(self::$bareRepository);
49+ }
50+
1551 /**
1652 * Prepare CLI setup
1753 */
@@ -24,10 +60,9 @@ protected function setUp(): void
2460 /**
2561 * Data provider for testExampleCommands.
2662 */
27- public function generalCommandsProvider ()
63+ public function generalCommandsProvider (): array
2864 {
2965 return [
30-
3166 [
3267 'patch ' ,
3368 0 ,
@@ -59,7 +94,7 @@ public function generalCommandsProvider()
5994 /**
6095 * @dataProvider generalCommandsProvider
6196 */
62- public function testGeneralCommands ($ expectedOutput , $ expectedStatus , $ CliArguments )
97+ public function testGeneralCommands ($ expectedOutput , $ expectedStatus , $ CliArguments ): void
6398 {
6499 // Create Robo arguments and execute a runner instance
65100 $ argv = $ this ->argv (func_get_args ());
@@ -69,4 +104,43 @@ public function testGeneralCommands($expectedOutput, $expectedStatus, $CliArgume
69104 $ this ->assertStringContainsString ($ expectedOutput , $ actualOutput );
70105 $ this ->assertEquals ($ expectedStatus , $ statusCode );
71106 }
107+
108+ /**
109+ * Data provider for testPatchCommandWarning.
110+ */
111+ public function patchCommandWarningProvider (): array
112+ {
113+ self ::loadFixtures ();
114+
115+ return [
116+ [
117+ 'Cloning failed ' ,
118+ 1 ,
119+ 'patch ' , '--repository-url=file:///not-existing-repository- ' . microtime ()
120+ ],
121+ [
122+ 'Branch creation failed ' ,
123+ 1 ,
124+ 'patch ' , '--source-branch=branch-does-not-exist ' , '--repository-url=file:// ' . self ::$ bareRepository
125+ ],
126+ [
127+ 'nothing to change ' ,
128+ 0 ,
129+ 'patch ' , '--repository-url=file:// ' . self ::$ bareRepository
130+ ]
131+ ];
132+ }
133+
134+ /**
135+ * @dataProvider patchCommandWarningProvider
136+ */
137+ public function testPatchCommandWarning ($ expectedOutput , $ expectedStatus , $ CliArguments ): void
138+ {
139+ // Create Robo arguments and execute a runner instance
140+ $ argv = $ this ->argv (func_get_args ());
141+ list ($ actualOutput , $ statusCode ) = $ this ->execute ($ argv , $ this ->commandClass );
142+
143+ $ this ->assertStringContainsString ($ expectedOutput , $ actualOutput );
144+ $ this ->assertEquals ($ expectedStatus , $ statusCode );
145+ }
72146}
0 commit comments