Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 11 additions & 55 deletions tests/Unit/Expressions/ForClasses/ContainDocBlockLikeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

namespace Arkitect\Tests\Unit\Expressions\ForClasses;

use Arkitect\Analyzer\ClassDescription;
use Arkitect\Analyzer\FullyQualifiedClassName;
use Arkitect\Analyzer\ClassDescriptionBuilder;
use Arkitect\Expression\ForClasses\ContainDocBlockLike;
use Arkitect\Rules\Violations;
use PHPUnit\Framework\TestCase;
Expand All @@ -16,19 +15,11 @@ public function test_it_should_return_true_if_contains_doc_block(): void
{
$expression = new ContainDocBlockLike('myDocBlock');

$classDescription = new ClassDescription(
FullyQualifiedClassName::fromString('HappyIsland\Myclass'),
[],
[],
null,
false,
false,
false,
false,
false,
false,
['/** */myDocBlock with other information']
);
$classDescription = (new ClassDescriptionBuilder())
->setClassName('HappyIsland\Myclass')
->addDocBlock('/** */myDocBlock with other information')
->build();

$because = 'we want to add this rule for our software';
$violations = new Violations();
$expression->evaluate($classDescription, $violations, $because);
Expand All @@ -40,50 +31,15 @@ public function test_it_should_return_true_if_contains_doc_block(): void
);
}

public function test_it_should_return_true_if_contains_doc_block_without_because(): void
{
$expression = new ContainDocBlockLike('myDocBlock');

$classDescription = new ClassDescription(
FullyQualifiedClassName::fromString('HappyIsland\Myclass'),
[],
[],
null,
false,
false,
false,
false,
false,
false,
['/** */myDocBlock with other information']
);
$violations = new Violations();
$expression->evaluate($classDescription, $violations, '');

self::assertEquals(0, $violations->count());
self::assertEquals(
'should have a doc block that contains myDocBlock',
$expression->describe($classDescription, '')->toString()
);
}

public function test_it_should_return_false_if_not_contains_doc_block(): void
{
$expression = new ContainDocBlockLike('anotherDocBlock');

$classDescription = new ClassDescription(
FullyQualifiedClassName::fromString('HappyIsland\Myclass'),
[],
[],
null,
false,
false,
false,
false,
false,
false,
['/** */myDocBlock with other information']
);
$classDescription = (new ClassDescriptionBuilder())
->setClassName('HappyIsland\Myclass')
->addDocBlock('/** */myDocBlock with other information')
->build();

$because = 'we want to add this rule for our software';
$violations = new Violations();
$expression->evaluate($classDescription, $violations, $because);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function test_it_should_return_true_if_it_has_no_dependencies(): void
$dependOnClasses = new DependsOnlyOnTheseNamespaces('myNamespace');

$classDescription = ClassDescription::getBuilder('HappyIsland\Myclass')->build();

$because = 'we want to add this rule for our software';
$violations = new Violations();
$dependOnClasses->evaluate($classDescription, $violations, $because);
Expand Down
17 changes: 3 additions & 14 deletions tests/Unit/Expressions/ForClasses/ExtendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

namespace Arkitect\Tests\Unit\Expressions\ForClasses;

use Arkitect\Analyzer\ClassDescription;
use Arkitect\Analyzer\ClassDescriptionBuilder;
use Arkitect\Analyzer\FullyQualifiedClassName;
use Arkitect\Expression\ForClasses\Extend;
use Arkitect\Rules\Violations;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -77,18 +75,9 @@ public function test_it_should_return_violation_error_if_extend_is_null(): void
{
$extend = new Extend('My\BaseClass');

$classDescription = new ClassDescription(
FullyQualifiedClassName::fromString('HappyIsland'),
[],
[],
null,
false,
false,
false,
false,
false,
false
);
$classDescription = (new ClassDescriptionBuilder())
->setClassName('HappyIsland')
->build();

$because = 'we want to add this rule for our software';
$violationError = $extend->describe($classDescription, $because)->toString();
Expand Down
60 changes: 16 additions & 44 deletions tests/Unit/Expressions/ForClasses/HaveAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

namespace Arkitect\Tests\Unit\Expressions\ForClasses;

use Arkitect\Analyzer\ClassDescription;
use Arkitect\Analyzer\FullyQualifiedClassName;
use Arkitect\Analyzer\ClassDescriptionBuilder;
use Arkitect\Expression\ForClasses\HaveAttribute;
use Arkitect\Rules\Violations;
use PHPUnit\Framework\TestCase;
Expand All @@ -16,20 +15,11 @@ public function test_it_should_return_true_if_contains_doc_block(): void
{
$expression = new HaveAttribute('myAttribute');

$classDescription = new ClassDescription(
FullyQualifiedClassName::fromString('HappyIsland\Myclass'),
[],
[],
null,
false,
false,
false,
false,
false,
false,
[],
[FullyQualifiedClassName::fromString('myAttribute')]
);
$classDescription = (new ClassDescriptionBuilder())
->setClassName('HappyIsland\Myclass')
->addAttribute('myAttribute', 1)
->build();

$because = 'we want to add this rule for our software';
$violations = new Violations();
$expression->evaluate($classDescription, $violations, $because);
Expand All @@ -45,20 +35,11 @@ public function test_it_should_return_true_if_contains_doc_block_without_because
{
$expression = new HaveAttribute('myAttribute');

$classDescription = new ClassDescription(
FullyQualifiedClassName::fromString('HappyIsland\Myclass'),
[],
[],
null,
false,
false,
false,
false,
false,
false,
[],
[FullyQualifiedClassName::fromString('myAttribute')]
);
$classDescription = (new ClassDescriptionBuilder())
->setClassName('HappyIsland\Myclass')
->addAttribute('myAttribute', 1)
->build();

$violations = new Violations();
$expression->evaluate($classDescription, $violations, '');

Expand All @@ -73,20 +54,11 @@ public function test_it_should_return_false_if_not_contains_doc_block(): void
{
$expression = new HaveAttribute('anotherAttribute');

$classDescription = new ClassDescription(
FullyQualifiedClassName::fromString('HappyIsland\Myclass'),
[],
[],
null,
false,
false,
false,
false,
false,
false,
[],
[FullyQualifiedClassName::fromString('myAttribute')]
);
$classDescription = (new ClassDescriptionBuilder())
->setClassName('HappyIsland\Myclass')
->addAttribute('myAttribute', 1)
->build();

$because = 'we want to add this rule for our software';
$violations = new Violations();
$expression->evaluate($classDescription, $violations, $because);
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Expressions/ForClasses/HaveNameMatchingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function test_check_class_name_match(): void
$expression = new HaveNameMatching('*Class');

$goodClass = ClassDescription::getBuilder('\App\MyClass')->build();

$because = 'we want to add this rule for our software';
$violations = new Violations();
$expression->evaluate($goodClass, $violations, $because);
Expand All @@ -26,6 +27,7 @@ public function test_show_violation_when_class_name_does_not_match(): void
$expression = new HaveNameMatching('*GoodName*');

$badClass = ClassDescription::getBuilder('\App\BadNameClass')->build();

$because = 'we want to add this rule for our software';
$violations = new Violations();
$expression->evaluate($badClass, $violations, $because);
Expand Down
Loading