Skip to content
This repository was archived by the owner on Sep 1, 2024. It is now read-only.

Commit d5f580d

Browse files
committed
Refactor tests
1 parent 3a03aaa commit d5f580d

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

tests/MainTest.php

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,23 @@ class MainTest extends TestCase
1010
{
1111
public function testHappyPath(): void
1212
{
13-
$expectedTotalErrors = 4;
13+
$expectedTotalErrors = 12;
1414
$expectedErrorsPerFile = [
15+
'file_exists_but_path_is_relative.php' => [
16+
'errors' => 4,
17+
'lines' => [5, 6, 7, 8]
18+
],
1519
'included_file_does_not_exist.php' => [
1620
'errors' => 4,
17-
'messages' => [
18-
[
19-
'message' => 'Included or required file "a_file_that_does_not_exist.php" does not exist.',
20-
'line' => 5,
21-
'ignorable' => true
22-
],
23-
[
24-
'message' => 'Included or required file "a_file_that_does_not_exist_once.php" does not exist.',
25-
'line' => 6,
26-
'ignorable' => true
27-
],
28-
[
29-
'message' => 'Included or required file "a_file_that_does_not_exist.php" does not exist.',
30-
'line' => 7,
31-
'ignorable' => true
32-
],
33-
[
34-
'message' => 'Included or required file "a_file_that_does_not_exist_once.php" does not exist.',
35-
'line' => 8,
36-
'ignorable' => true
37-
],
38-
]
21+
'lines' => [5, 6, 7, 8]
22+
],
23+
'included_file_does_not_exist_using_class_const.php' => [
24+
'errors' => 4,
25+
'lines' => [7, 8, 9, 10]
3926
],
4027
];
28+
$errorStartsWith = 'Included or required file "';
29+
$errorEndsWith = '" does not exist.';
4130

4231
$output = [];
4332
exec('php vendor/bin/phpstan analyse -c tests/phpstan-testing.neon --error-format=json', $output);
@@ -51,8 +40,16 @@ public function testHappyPath(): void
5140
$basename = basename($filename);
5241

5342
$this->assertArrayHasKey($basename, $expectedErrorsPerFile);
54-
$this->assertSame($expectedErrorsPerFile[$basename]['errors'], $errors['errors']);
55-
$this->assertSame($expectedErrorsPerFile[$basename]['messages'], $errors['messages']);
43+
44+
$expectedError = $expectedErrorsPerFile[$basename];
45+
$this->assertSame($expectedError['errors'], $errors['errors']);
46+
47+
foreach ($errors['messages'] as $index => $error) {
48+
$this->assertStringStartsWith($errorStartsWith, $error['message']);
49+
$this->assertStringEndsWith($errorEndsWith, $error['message']);
50+
51+
$this->assertSame($expectedError['lines'][$index], $error['line']);
52+
}
5653
}
5754
}
5855
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
include 'include_me_to_prove_you_work.txt';
6+
include_once 'include_me_to_prove_you_work.txt';
7+
require 'include_me_to_prove_you_work.txt';
8+
require_once 'include_me_to_prove_you_work.txt';

0 commit comments

Comments
 (0)