Skip to content

Commit

Permalink
Add test for class with declare statement
Browse files Browse the repository at this point in the history
Introduced a new test case in ClassNameTest to verify that the ClassName::from function correctly handles PHP files with declare(strict_types=1). This ensures that the class name extraction works accurately in such scenarios.
  • Loading branch information
koriym committed Nov 4, 2024
1 parent b611c1c commit 7d7f597
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/ClassNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,28 @@ class MyClass {}
$result = ClassName::from($filePath);
$this->assertSame('MyNamespace\\MyClass', $result);
}

public function testClassWithDeclare(): void
{
$phpCode = <<<'PHP'
<?php
declare(strict_types=1);
namespace Ray\Aop;
final class FakeFinalClass
{
public function myMethod(): string
{
return 'original';
}
}
PHP;
$filePath = $this->tempDir . '/ClassWithDeclare.php';
file_put_contents($filePath, $phpCode);

$result = ClassName::from($filePath);
$this->assertSame('Ray\\Aop\\FakeFinalClass', $result);
}
}

0 comments on commit 7d7f597

Please sign in to comment.