-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadonlyClassRuleTest.php
35 lines (30 loc) · 1.14 KB
/
ReadonlyClassRuleTest.php
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
<?php declare(strict_types = 1);
namespace App;
use Phauthentic\PhpstanRules\ReadonlyClassRule;
use PHPStan\Testing\RuleTestCase;
/**
* @extends RuleTestCase<ReadonlyClassRule>
*/
class ReadonlyClassRuleTest extends RuleTestCase
{
protected function getRule(): \PHPStan\Rules\Rule
{
return new ReadonlyClassRule([
'/Controller$/', // all classes that end with "Controller"
]);
}
public function testRule(): void
{
// first argument: path to the example file that contains some errors that should be reported by MyRule
// second argument: an array of expected errors,
// each error consists of the asserted error message, and the asserted error file line
$this->analyse([__DIR__ . '/../data/Controller/MissingReadonlyRuleController.php'], [
[
'Class App\Controller\MissingReadonlyRuleController must be readonly.', // asserted error message
07, // asserted error line
],
]);
// the test fails, if the expected error does not occur,
// or if there are other errors reported beside the expected one
}
}