-
-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathNoClassRulesTest.php
More file actions
64 lines (52 loc) · 1.99 KB
/
NoClassRulesTest.php
File metadata and controls
64 lines (52 loc) · 1.99 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 Arkitect\Tests\Unit\Rules;
use Arkitect\Analyzer\FileParserFactory;
use Arkitect\ClassSet;
use Arkitect\ClassSetRules;
use Arkitect\CLI\Progress\VoidProgress;
use Arkitect\CLI\Runner;
use Arkitect\CLI\TargetPhpVersion;
use Arkitect\Expression\ForClasses\HaveNameMatching;
use Arkitect\Expression\ForClasses\NotResideInTheseNamespaces;
use Arkitect\Expression\ForClasses\ResideInOneOfTheseNamespaces;
use Arkitect\Rules\ParsingErrors;
use Arkitect\Rules\Rule;
use Arkitect\Rules\Violations;
use PHPUnit\Framework\TestCase;
class NoClassRulesTest extends TestCase
{
public function test_no_class_without_that_clause_dsl_works(): void
{
$rule = Rule::noClass()
->should(new NotResideInTheseNamespaces('App\Services'))
->because('this namespace has been deprecated in favor of the modular architecture');
$classSet = ClassSet::fromDir(__DIR__.'/../../E2E/_fixtures/mvc');
$runner = new Runner();
$runner->check(
ClassSetRules::create($classSet, $rule),
new VoidProgress(),
FileParserFactory::createFileParser(TargetPhpVersion::create()),
$violations = new Violations(),
new ParsingErrors()
);
self::assertNotEmpty($violations->toArray());
}
public function test_no_class_dsl_works(): void
{
$rule = Rule::noClass()
->that(new ResideInOneOfTheseNamespaces('App\Entity'))
->should(new HaveNameMatching('*Service'))
->because('of our naming convention');
$classSet = ClassSet::fromDir(__DIR__.'/../../E2E/_fixtures/mvc');
$runner = new Runner();
$runner->check(
ClassSetRules::create($classSet, $rule),
new VoidProgress(),
FileParserFactory::createFileParser(TargetPhpVersion::create()),
$violations = new Violations(),
new ParsingErrors()
);
self::assertEmpty($violations->toArray());
}
}