diff --git a/tests/expectations/source.txt b/tests/expectations/source.txt new file mode 100644 index 0000000..2272678 --- /dev/null +++ b/tests/expectations/source.txt @@ -0,0 +1,7 @@ + 1 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace SebastianBergmann\FOAL; + +use function file; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Small; +use PHPUnit\Framework\Attributes\UsesClass; +use PHPUnit\Framework\TestCase; + +#[CoversClass(FileRenderer::class)] +#[UsesClass(File::class)] +#[Small] +final class FileRendererTest extends TestCase +{ + public function testRendersFileAsString(): void + { + $this->assertStringEqualsFile( + __DIR__ . '/../expectations/source.txt', + (new FileRenderer)->render($this->file()), + ); + } + + private function file(): File + { + return new File( + file(__DIR__ . '/../fixture/source.php'), + [4, 7], + ); + } +} diff --git a/tests/unit/FileTest.php b/tests/unit/FileTest.php new file mode 100644 index 0000000..d6b28d4 --- /dev/null +++ b/tests/unit/FileTest.php @@ -0,0 +1,44 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace SebastianBergmann\FOAL; + +use function file; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Small; +use PHPUnit\Framework\TestCase; + +#[CoversClass(File::class)] +#[Small] +final class FileTest extends TestCase +{ + public function testHasSourceLines(): void + { + $this->assertSame( + file(__DIR__ . '/../fixture/source.php'), + $this->file()->sourceLines(), + ); + } + + public function testLinesEliminatedByOptimizer(): void + { + $this->assertSame( + [4, 7], + $this->file()->linesEliminatedByOptimizer(), + ); + } + + private function file(): File + { + return new File( + file(__DIR__ . '/../fixture/source.php'), + [4, 7], + ); + } +}