|
12 | 12 | use Arkitect\CLI\TargetPhpVersion;
|
13 | 13 | use Arkitect\Expression\ForClasses\DependsOnlyOnTheseNamespaces;
|
14 | 14 | use Arkitect\Expression\ForClasses\Implement;
|
| 15 | +use Arkitect\Expression\ForClasses\IsAbstract; |
| 16 | +use Arkitect\Expression\ForClasses\IsFinal; |
| 17 | +use Arkitect\Expression\ForClasses\IsReadonly; |
15 | 18 | use Arkitect\Expression\ForClasses\NotContainDocBlockLike;
|
16 | 19 | use Arkitect\Expression\ForClasses\NotHaveDependencyOutsideNamespace;
|
17 | 20 | use Arkitect\Rules\ParsingError;
|
@@ -1506,4 +1509,81 @@ public function __construct(string $firstName, string $lastName) {
|
1506 | 1509 |
|
1507 | 1510 | self::assertInstanceOf(ClassDescription::class, $cd[0]);
|
1508 | 1511 | }
|
| 1512 | + |
| 1513 | + public function test_is_final_when_there_is_anonymous_final(): void |
| 1514 | + { |
| 1515 | + $code = <<< 'EOF' |
| 1516 | + <?php |
| 1517 | + namespace App\Foo; |
| 1518 | +
|
| 1519 | + final class User { |
| 1520 | + public function __construct() { |
| 1521 | + $class = new class() extends Bundle {} |
| 1522 | + } |
| 1523 | + } |
| 1524 | + EOF; |
| 1525 | + |
| 1526 | + /** @var FileParser $fp */ |
| 1527 | + $fp = FileParserFactory::createFileParser(TargetPhpVersion::create('8.4')); |
| 1528 | + $fp->parse($code, 'relativePathName'); |
| 1529 | + |
| 1530 | + $cd = $fp->getClassDescriptions(); |
| 1531 | + $violations = new Violations(); |
| 1532 | + $isFinal = new IsFinal(); |
| 1533 | + $isFinal->evaluate($cd[0], $violations, 'we want to add this rule for our software'); |
| 1534 | + |
| 1535 | + self::assertCount(0, $violations); |
| 1536 | + } |
| 1537 | + |
| 1538 | + public function test_is_abstract_when_there_is_anonymous_final(): void |
| 1539 | + { |
| 1540 | + $code = <<< 'EOF' |
| 1541 | + <?php |
| 1542 | + namespace App\Foo; |
| 1543 | +
|
| 1544 | + abstract class User { |
| 1545 | + public function bar() { |
| 1546 | + $class = new class() extends Bundle {} |
| 1547 | + } |
| 1548 | +
|
| 1549 | + abstract public function foo() {} |
| 1550 | + } |
| 1551 | + EOF; |
| 1552 | + |
| 1553 | + /** @var FileParser $fp */ |
| 1554 | + $fp = FileParserFactory::createFileParser(TargetPhpVersion::create('8.4')); |
| 1555 | + $fp->parse($code, 'relativePathName'); |
| 1556 | + |
| 1557 | + $cd = $fp->getClassDescriptions(); |
| 1558 | + $violations = new Violations(); |
| 1559 | + $isAbstract = new IsAbstract(); |
| 1560 | + $isAbstract->evaluate($cd[0], $violations, 'we want to add this rule for our software'); |
| 1561 | + |
| 1562 | + self::assertCount(0, $violations); |
| 1563 | + } |
| 1564 | + |
| 1565 | + public function test_is_readonly_when_there_is_anonymous_final(): void |
| 1566 | + { |
| 1567 | + $code = <<< 'EOF' |
| 1568 | + <?php |
| 1569 | + namespace App\Foo; |
| 1570 | +
|
| 1571 | + readonly class User { |
| 1572 | + public function __construct() { |
| 1573 | + $class = new class() extends Bundle {} |
| 1574 | + } |
| 1575 | + } |
| 1576 | + EOF; |
| 1577 | + |
| 1578 | + /** @var FileParser $fp */ |
| 1579 | + $fp = FileParserFactory::createFileParser(TargetPhpVersion::create('8.4')); |
| 1580 | + $fp->parse($code, 'relativePathName'); |
| 1581 | + |
| 1582 | + $cd = $fp->getClassDescriptions(); |
| 1583 | + $violations = new Violations(); |
| 1584 | + $isReadOnly = new IsReadonly(); |
| 1585 | + $isReadOnly->evaluate($cd[0], $violations, 'we want to add this rule for our software'); |
| 1586 | + |
| 1587 | + self::assertCount(0, $violations); |
| 1588 | + } |
1509 | 1589 | }
|
0 commit comments