mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
Add tests for strict types expectation
Introduced new test cases to ensure strict type declaration handling. Files with and without strict types are tested, including scenarios with comments preceding the declaration. Updated the regex in `Expectation.php` to accommodate comments and whitespaces before the `declare(strict_types=1)` statement.
This commit is contained in:
18
tests/Features/Expect/toUseStrictTypes.php
Normal file
18
tests/Features/Expect/toUseStrictTypes.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Pest\Arch\Exceptions\ArchExpectationFailedException;
|
||||
use Tests\Fixtures\Arch\ToUseStrictTypes\HasNoStrictType;
|
||||
use Tests\Fixtures\Arch\ToUseStrictTypes\HasStrictType;
|
||||
use Tests\Fixtures\Arch\ToUseStrictTypes\HasStrictTypeWithCommentsAbove;
|
||||
|
||||
test('pass', function () {
|
||||
expect(HasStrictType::class)->toUseStrictTypes()
|
||||
->and(HasStrictTypeWithCommentsAbove::class)->toUseStrictTypes();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect(HasNoStrictType::class)->toUseStrictTypes();
|
||||
})->throws(ArchExpectationFailedException::class);
|
||||
|
||||
8
tests/Fixtures/Arch/ToUseStrictTypes/HasNoStrictType.php
Normal file
8
tests/Fixtures/Arch/ToUseStrictTypes/HasNoStrictType.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Fixtures\Arch\ToUseStrictTypes;
|
||||
|
||||
class HasNoStrictType
|
||||
{
|
||||
|
||||
}
|
||||
10
tests/Fixtures/Arch/ToUseStrictTypes/HasStrictType.php
Normal file
10
tests/Fixtures/Arch/ToUseStrictTypes/HasStrictType.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Fixtures\Arch\ToUseStrictTypes;
|
||||
|
||||
class HasStrictType
|
||||
{
|
||||
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
<?php /** @noinspection PhpUnused */
|
||||
|
||||
// some other comment
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Fixtures\Arch\ToUseStrictTypes;
|
||||
|
||||
class HasStrictTypeWithCommentsAbove
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user