forked from bmitch/churn-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssessComplexityCommandTest.php
More file actions
64 lines (52 loc) · 1.83 KB
/
AssessComplexityCommandTest.php
File metadata and controls
64 lines (52 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
declare(strict_types=1);
namespace Churn\Tests\Integration\Command;
use Churn\Command\AssessComplexityCommand;
use Churn\Tests\BaseTestCase;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
final class AssessComplexityCommandTest extends BaseTestCase
{
/**
* @var CommandTester
*/
private $commandTester;
/** @return void */
#[\Override]
protected function setUp()
{
parent::setUp();
$application = new Application('churn-php', 'test');
$method = \method_exists($application, 'addCommand')
? 'addCommand'
: 'add';
$application->{$method}(AssessComplexityCommand::newInstance());
$command = $application->find('assess-complexity');
$this->commandTester = new CommandTester($command);
}
/** @return void */
#[\Override]
protected function tearDown()
{
parent::tearDown();
unset($this->commandTester);
}
/** @test */
public function it_returns_the_cyclomatic_complexity_greater_than_zero(): void
{
$exitCode = $this->commandTester->execute(['file' => __FILE__]);
$result = \rtrim($this->commandTester->getDisplay());
self::assertSame(0, $exitCode);
self::assertTrue(\ctype_digit($result), 'The result of the command must be an integer');
self::assertGreaterThan(0, (int) $result);
}
/** @test */
public function it_returns_zero_for_non_existing_file(): void
{
$exitCode = $this->commandTester->execute(['file' => 'nonexisting-file.php']);
$result = \rtrim($this->commandTester->getDisplay());
self::assertSame(0, $exitCode);
self::assertTrue(\ctype_digit($result), 'The result of the command must be an integer');
self::assertSame(0, (int) $result);
}
}