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
2 changes: 2 additions & 0 deletions extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ parameters:
- PHPUnit\Framework\TestCase
scanDirectories:
- src
stubFiles:
- stubs/DescribeCall.stub

services:
-
Expand Down
1 change: 1 addition & 0 deletions src/Type/Pest/PestInternalClassAccessIgnoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ final class PestInternalClassAccessIgnoreExtension implements IgnoreErrorExtensi
'property.internalClass',
'method.internalClass',
'method.internalTrait',
'method.internalInterface',
];

public function shouldIgnore(Error $error, Node $node, Scope $scope): bool
Expand Down
12 changes: 12 additions & 0 deletions stubs/DescribeCall.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Pest\PendingCalls;

/**
* @mixin \Pest\PendingCalls\BeforeEachCall
*/
final class DescribeCall
{
}
21 changes: 21 additions & 0 deletions tests/Rules/DescribeCallMethodTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Tests\Rules;

use PHPStan\Rules\Methods\CallMethodsRule;
use Tests\RuleTestCase;

beforeAll(function (): void {
RuleTestCase::$additionalConfigFiles = [
__DIR__.'/../extension.neon',
];
RuleTestCase::$rule = RuleTestCase::resolveRule(CallMethodsRule::class);
});

test('describe call chain methods are allowed', function (): void {
$this->analyse([
__DIR__.'/data/describe-call-methods.php',
], []);
});
21 changes: 21 additions & 0 deletions tests/Rules/PestInternalClassAccessIgnoreExtensionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Tests\Rules;

use PHPStan\Rules\RestrictedUsage\RestrictedMethodUsageRule;
use Tests\RuleTestCase;

beforeAll(function (): void {
RuleTestCase::$additionalConfigFiles = [
__DIR__.'/internal-tag.neon',
];
RuleTestCase::$rule = RuleTestCase::resolveRule(RestrictedMethodUsageRule::class);
});

test('methods of internal pest interfaces are not reported on arch expectations', function (): void {
$this->analyse([
__DIR__.'/data/arch-expectation-internal-methods.php',
], []);
});
17 changes: 17 additions & 0 deletions tests/Rules/data/arch-expectation-internal-methods.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

test('arch expectation methods of an internal interface are allowed', function (): void {
arch()->expect('App\Models')
->toBeClasses()
->toExtend('Illuminate\Database\Eloquent\Model')
->toOnlyBeUsedIn('App\Repositories')
->ignoring('App\Models\User');
});

test('arch expectation ignoring global functions is allowed', function (): void {
arch()->expect('App\Services')
->toUseNothing()
->ignoringGlobalFunctions();
});
29 changes: 29 additions & 0 deletions tests/Rules/data/describe-call-methods.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

describe('migrations', function (): void {
test('can rollback migrations', function (): void {
expect(true)->toBeTrue();
});
})->skip();

describe('user settings', function (): void {
test('receives the dataset value', function (int $value): void {
expect($value)->toBeGreaterThan(0);
});
})->with([10, 20]);

describe('auth', function (): void {
beforeEach(fn () => null);

test('can logout', function (): void {
expect(true)->toBeTrue();
});
})->skip(fn (): bool => true, 'only runs on sqlite')->with([10, 20])->group('slow');

describe('teardown', function (): void {
test('example', function (): void {
expect(true)->toBeTrue();
});
})->after(function (): void {});
5 changes: 5 additions & 0 deletions tests/Rules/internal-tag.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
includes:
- ../extension.neon
parameters:
featureToggles:
internalTag: true