-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathNegateDecoratorTest.php
56 lines (40 loc) · 2 KB
/
NegateDecoratorTest.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
declare(strict_types=1);
namespace Arkitect\Tests\Expression;
use Arkitect\Analyzer\ClassDescription;
use Arkitect\Expression\ForClasses\IsFinal;
use Arkitect\Expression\ForClasses\IsNotFinal;
use Arkitect\Expression\NegateDecorator;
use Arkitect\Rules\Violations;
use PHPUnit\Framework\TestCase;
class NegateDecoratorTest extends TestCase
{
public function test_positive_decoration(): void
{
$finalClass = ClassDescription::build('Tests\FinalClass')
->setFinal(true)
->get();
$isFinal = new IsFinal();
$isFinal->evaluate($finalClass, $violations = new Violations(), 'of some reason');
self::assertEquals('FinalClass should be final because of some reason', $isFinal->describe($finalClass, 'of some reason')->toString());
self::assertEquals(0, $violations->count());
$isNotFinal = new NegateDecorator($isFinal);
$isNotFinal->evaluate($finalClass, $violations = new Violations(), 'of some reason');
self::assertEquals('FinalClass should not be final because of some reason', $isNotFinal->describe($finalClass, 'of some reason')->toString());
self::assertEquals(1, $violations->count());
}
public function test_negative_decoration(): void
{
$finalClass = ClassDescription::build('Tests\FinalClass')
->setFinal(true)
->get();
$isNotFinal = new IsNotFinal();
$isNotFinal->evaluate($finalClass, $violations = new Violations(), '');
self::assertEquals(1, $violations->count());
self::assertEquals('FinalClass should not be final because of some reason', $isNotFinal->describe($finalClass, 'of some reason')->toString());
$isFinal = new NegateDecorator($isNotFinal);
$isFinal->evaluate($finalClass, $violations = new Violations(), '');
self::assertEquals(0, $violations->count());
self::assertEquals('FinalClass should be final because of some reason', $isFinal->describe($finalClass, 'of some reason')->toString());
}
}