Skip to content

Commit 5cdfc33

Browse files
committed
Improves tests
1 parent fb474a6 commit 5cdfc33

File tree

4 files changed

+32
-65
lines changed

4 files changed

+32
-65
lines changed

tests/Commands/InitCommandTest.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,11 @@
1414
use Stolt\LeanPackage\Presets\PhpPreset;
1515
use Stolt\LeanPackage\Tests\CommandTester;
1616
use Stolt\LeanPackage\Tests\TestCase;
17-
use Symfony\Component\Console\Application;
1817
use Symfony\Component\Console\Command\Command;
1918
use Symfony\Component\Console\Output\OutputInterface;
2019

2120
class InitCommandTest extends TestCase
2221
{
23-
/**
24-
* @var Application
25-
*/
26-
private $application;
27-
2822
/**
2923
* Set up test environment.
3024
*/
@@ -34,7 +28,7 @@ protected function setUp(): void
3428
if (!\defined('WORKING_DIRECTORY')) {
3529
\define('WORKING_DIRECTORY', $this->temporaryDirectory);
3630
}
37-
$this->application = $this->getApplication();
31+
$this->application = $this->getApplication(new InitCommand(new Analyser(new Finder(new PhpPreset()))));
3832
}
3933

4034
/**
@@ -237,15 +231,4 @@ public function existingDefaultLpvFileIsOverwrittenWhenDesired(): void
237231
$commandTester->assertCommandIsSuccessful();
238232
$this->assertFileExists($expectedDefaultLpvFile);
239233
}
240-
241-
/**
242-
* @return Application
243-
*/
244-
protected function getApplication(): Application
245-
{
246-
$application = new Application();
247-
$application->add(new InitCommand(new Analyser(new Finder(new PhpPreset()))));
248-
249-
return $application;
250-
}
251234
}

tests/Commands/TreeCommandTest.php

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,20 @@
1111
use Stolt\LeanPackage\Tests\CommandTester;
1212
use Stolt\LeanPackage\Tests\TestCase;
1313
use Stolt\LeanPackage\Tree;
14-
use Symfony\Component\Console\Application;
1514

1615
class TreeCommandTest extends TestCase
1716
{
18-
/**
19-
* @var Application
20-
*/
21-
private Application $application;
22-
2317
/**
2418
* Set up test environment.
19+
* @throws GitNotAvailable
2520
*/
2621
protected function setUp(): void
2722
{
2823
$this->setUpTemporaryDirectory();
2924
if (!\defined('WORKING_DIRECTORY')) {
3025
\define('WORKING_DIRECTORY', $this->temporaryDirectory);
3126
}
32-
$this->application = $this->getApplication();
27+
$this->application = $this->getApplication(new TreeCommand(new Tree(new Archive(WORKING_DIRECTORY))));
3328
}
3429

3530
/**
@@ -43,7 +38,6 @@ protected function tearDown(): void
4338
$this->removeDirectory($this->temporaryDirectory);
4439
}
4540
}
46-
4741
#[Test]
4842
public function displaysExpectedSrcTree(): void
4943
{
@@ -71,16 +65,4 @@ public function displaysExpectedSrcTree(): void
7165
$this->assertStringContainsString('5 directories, 2 files', $commandTester->getDisplay());
7266
$commandTester->assertCommandIsSuccessful();
7367
}
74-
75-
/**
76-
* @throws GitNotAvailable
77-
* @return Application
78-
*/
79-
protected function getApplication(): Application
80-
{
81-
$application = new Application();
82-
$application->add(new TreeCommand(new Tree(new Archive(WORKING_DIRECTORY))));
83-
84-
return $application;
85-
}
8668
}

tests/Commands/ValidateCommandTest.php

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use PHPUnit\Framework\Attributes\Group;
1313
use PHPUnit\Framework\Attributes\Test;
1414
use PHPUnit\Framework\Attributes\Ticket;
15-
use SebastianBergmann\CodeCoverage\Driver\WriteOperationFailedException;
1615
use Stolt\LeanPackage\Analyser;
1716
use Stolt\LeanPackage\Archive;
1817
use Stolt\LeanPackage\Archive\Validator;
@@ -32,11 +31,6 @@ class ValidateCommandTest extends TestCase
3231
{
3332
use InteractsWithConsole;
3433

35-
/**
36-
* @var Application
37-
*/
38-
private Application $application;
39-
4034
/**
4135
* Set up test environment.
4236
*/
@@ -46,7 +40,13 @@ protected function setUp(): void
4640
if (!\defined('WORKING_DIRECTORY')) {
4741
\define('WORKING_DIRECTORY', $this->temporaryDirectory);
4842
}
49-
$this->application = $this->getApplication();
43+
44+
$analyserCommand = new ValidateCommand(
45+
new Analyser(new Finder(new PhpPreset())),
46+
new Validator(new Archive($this->temporaryDirectory))
47+
);
48+
49+
$this->application = $this->getApplication($analyserCommand);
5050
}
5151

5252
/**
@@ -2246,24 +2246,4 @@ protected function getApplicationWithMockedArchiveValidator(MockInterface $mocke
22462246

22472247
return $application;
22482248
}
2249-
2250-
/**
2251-
* @return Application
2252-
*/
2253-
protected function getApplication(): Application
2254-
{
2255-
$application = new Application();
2256-
$archive = new Archive(
2257-
$this->temporaryDirectory
2258-
);
2259-
2260-
$analyserCommand = new ValidateCommand(
2261-
new Analyser(new Finder(new PhpPreset())),
2262-
new Validator($archive)
2263-
);
2264-
2265-
$application->add($analyserCommand);
2266-
2267-
return $application;
2268-
}
22692249
}

tests/TestCase.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,20 @@
55
namespace Stolt\LeanPackage\Tests;
66

77
use PHPUnit\Framework\TestCase as PHPUnit;
8+
use Stolt\LeanPackage\Analyser;
9+
use Stolt\LeanPackage\Commands\InitCommand;
810
use Stolt\LeanPackage\Helpers\Str as OsHelper;
11+
use Stolt\LeanPackage\Presets\Finder;
12+
use Stolt\LeanPackage\Presets\PhpPreset;
13+
use Symfony\Component\Console\Application;
14+
use Symfony\Component\Console\Command\Command;
915

1016
class TestCase extends PHPUnit
1117
{
18+
/**
19+
* @var Application
20+
*/
21+
protected Application $application;
1222
protected string $temporaryDirectory;
1323

1424
/**
@@ -134,4 +144,16 @@ protected function createTemporaryGlobPatternFile($content)
134144

135145
return file_put_contents($temporaryLpvFile, $content) > 0;
136146
}
147+
148+
/**
149+
* @param Command $command
150+
* @return Application
151+
*/
152+
protected function getApplication(Command $command): Application
153+
{
154+
$application = new Application();
155+
$application->add($command);
156+
157+
return $application;
158+
}
137159
}

0 commit comments

Comments
 (0)