diff --git a/src/Expectation.php b/src/Expectation.php index 57843616..ebfd6302 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -509,7 +509,7 @@ public function toUseStrictTypes(): ArchExpectation { return Targeted::make( $this, - fn (ObjectDescription $object): bool => (bool) preg_match('/^<\?php\s+declare\(.*?strict_types\s?=\s?1.*?\);/', (string) file_get_contents($object->path)), + fn (ObjectDescription $object): bool => (bool) preg_match('/^<\?php\s*(\/\*[\s\S]*?\*\/|\/\/[^\r\n]*(?:\r?\n|$)|\s)*declare\s*\(\s*strict_types\s*=\s*1\s*\)\s*;/m', (string) file_get_contents($object->path)), 'to use strict types', FileLineFinder::where(fn (string $line): bool => str_contains($line, 'toUseStrictTypes() + ->and(HasStrictTypeWithCommentsAbove::class)->toUseStrictTypes(); +}); + +test('failures', function () { + expect(HasNoStrictType::class)->toUseStrictTypes(); +})->throws(ArchExpectationFailedException::class); + diff --git a/tests/Fixtures/Arch/ToUseStrictTypes/HasNoStrictType.php b/tests/Fixtures/Arch/ToUseStrictTypes/HasNoStrictType.php new file mode 100644 index 00000000..ce87bf9a --- /dev/null +++ b/tests/Fixtures/Arch/ToUseStrictTypes/HasNoStrictType.php @@ -0,0 +1,8 @@ +