Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scan tests/ with PHPStan #372

Merged
merged 1 commit into from
Nov 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ jobs:
- name: "Run PHP Copy/Paste Detector"
run: "vendor/bin/phpcpd src"

- name: "Install PHPUnit"
run: "vendor/bin/simple-phpunit --version"

- name: "Run Psalm"
run: "vendor/bin/psalm --show-info=true"

Expand Down
7 changes: 6 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ parameters:
level: 8
paths:
- %currentWorkingDirectory%/src/
- %currentWorkingDirectory%/tests/

bootstrapFiles:
- vendor/bin/.phpunit/phpunit/vendor/autoload.php
- tests/Integration/Command/Assets/hooks

checkGenericClassInNonGenericObjectType: false
reportUnmatchedIgnoredErrors: true
ignoreErrors:
- '/Casting to .+ something that''s already/'
- '/^Casting to .+ something that''s already/'

checkTooWideReturnTypesInProtectedAndPublicMethods: true
checkUninitializedProperties: true
Expand Down
2 changes: 2 additions & 0 deletions tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ abstract class BaseTestCase extends TestCase
{
/**
* @see https://github.com/phpspec/prophecy/issues/366#issuecomment-359587114
*
* @return void
*/
protected function tearDown()
{
Expand Down
14 changes: 10 additions & 4 deletions tests/EndToEnd/FossilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,27 @@ class FossilTest extends BaseTestCase
/** @var CommandTester */
private $commandTester;

/** @return void */
protected function setUp()
{
parent::setUp();

$application = new Application('churn-php', 'test');
$application->add(RunCommand::newInstance());
$command = $application->find('run');
$this->commandTester = new CommandTester($command);
}

/** @return void */
protected function tearDown()
{
$this->commandTester = null;
parent::tearDown();

unset($this->commandTester);
}

/** @test */
public function it_works_with_fossil()
public function it_works_with_fossil(): void
{
$exitCode = $this->commandTester->execute([
'paths' => [],
Expand All @@ -51,7 +57,7 @@ public function it_works_with_fossil()
+---------+---------------+------------+-------+
";

$this->assertSame(0, $exitCode);
$this->assertSame($expected, $display);
self::assertSame(0, $exitCode);
self::assertSame($expected, $display);
}
}
14 changes: 10 additions & 4 deletions tests/EndToEnd/MercurialTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,27 @@ class MercurialTest extends BaseTestCase
/** @var CommandTester */
private $commandTester;

/** @return void */
protected function setUp()
{
parent::setUp();

$application = new Application('churn-php', 'test');
$application->add(RunCommand::newInstance());
$command = $application->find('run');
$this->commandTester = new CommandTester($command);
}

/** @return void */
protected function tearDown()
{
$this->commandTester = null;
parent::tearDown();

unset($this->commandTester);
}

/** @test */
public function it_works_with_mercurial()
public function it_works_with_mercurial(): void
{
$exitCode = $this->commandTester->execute([
'paths' => [],
Expand All @@ -51,7 +57,7 @@ public function it_works_with_mercurial()
+---------+---------------+------------+-------+
";

$this->assertSame(0, $exitCode);
$this->assertSame($expected, $display);
self::assertSame(0, $exitCode);
self::assertSame($expected, $display);
}
}
14 changes: 10 additions & 4 deletions tests/EndToEnd/SubversionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,27 @@ class SubversionTest extends BaseTestCase
/** @var CommandTester */
private $commandTester;

/** @return void */
protected function setUp()
{
parent::setUp();

$application = new Application('churn-php', 'test');
$application->add(RunCommand::newInstance());
$command = $application->find('run');
$this->commandTester = new CommandTester($command);
}

/** @return void */
protected function tearDown()
{
$this->commandTester = null;
parent::tearDown();

unset($this->commandTester);
}

/** @test */
public function it_works_with_subversion()
public function it_works_with_subversion(): void
{
$exitCode = $this->commandTester->execute([
'paths' => [],
Expand All @@ -51,7 +57,7 @@ public function it_works_with_subversion()
+---------+---------------+------------+-------+
";

$this->assertSame(0, $exitCode);
$this->assertSame($expected, $display);
self::assertSame(0, $exitCode);
self::assertSame($expected, $display);
}
}
24 changes: 15 additions & 9 deletions tests/Integration/Command/AssessComplexityCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,44 @@ class AssessComplexityCommandTest extends BaseTestCase
/** @var CommandTester */
private $commandTester;

/** @return void */
protected function setUp()
{
parent::setUp();

$application = new Application('churn-php', 'test');
$application->add(AssessComplexityCommand::newInstance());
$command = $application->find('assess-complexity');
$this->commandTester = new CommandTester($command);
}

/** @return void */
protected function tearDown()
{
$this->commandTester = null;
parent::tearDown();

unset($this->commandTester);
}

/** @test */
public function it_returns_the_cyclomatic_complexity_greater_than_zero()
public function it_returns_the_cyclomatic_complexity_greater_than_zero(): void
{
$exitCode = $this->commandTester->execute(['file' => __FILE__]);
$result = \rtrim($this->commandTester->getDisplay());

$this->assertSame(0, $exitCode);
$this->assertTrue(\ctype_digit($result), 'The result of the command must be an integer');
$this->assertGreaterThan(0, (int) $result);
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()
public function it_returns_zero_for_non_existing_file(): void
{
$exitCode = $this->commandTester->execute(['file' => 'nonexisting-file.php']);
$result = \rtrim($this->commandTester->getDisplay());

$this->assertSame(0, $exitCode);
$this->assertTrue(\ctype_digit($result), 'The result of the command must be an integer');
$this->assertSame(0, (int) $result);
self::assertSame(0, $exitCode);
self::assertTrue(\ctype_digit($result), 'The result of the command must be an integer');
self::assertSame(0, (int) $result);
}
}
3 changes: 3 additions & 0 deletions tests/Integration/Command/Assets/TestHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
class TestHook implements AfterAnalysisHook, AfterFileAnalysisHook, BeforeAnalysisHook
{

/** @var int */
public static $nbAfterAnalysisEvent = 0;
/** @var int */
public static $nbAfterFileAnalysisEvent = 0;
/** @var int */
public static $nbBeforeAnalysisEvent = 0;

public static function reset(): void
Expand Down
3 changes: 3 additions & 0 deletions tests/Integration/Command/Assets/hooks
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use Churn\Event\Hook\BeforeAnalysisHook;

class TestAfterAnalysisHook implements AfterAnalysisHook
{
/** @var int */
public static $nbAfterAnalysisEvent = 0;

/**
Expand All @@ -26,6 +27,7 @@ class TestAfterAnalysisHook implements AfterAnalysisHook

class TestAfterFileAnalysisHook implements AfterFileAnalysisHook
{
/** @var int */
public static $nbAfterFileAnalysisEvent = 0;

/**
Expand All @@ -39,6 +41,7 @@ class TestAfterFileAnalysisHook implements AfterFileAnalysisHook

class TestBeforeAnalysisHook implements BeforeAnalysisHook
{
/** @var int */
public static $nbBeforeAnalysisEvent = 0;

/**
Expand Down
Loading