Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Mar 24, 2024
1 parent dd83dcd commit a201947
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/expectations/source.txt
@@ -0,0 +1,7 @@
1 <?php declare(strict_types=1);
2 function f()
3 {
- 4 $result = 'result';
5
6 return $result;
- 7 }
38 changes: 38 additions & 0 deletions tests/unit/FileRendererTest.php
@@ -0,0 +1,38 @@
<?php declare(strict_types=1);
/*
* This file is part of FOAL.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* 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],
);
}
}
44 changes: 44 additions & 0 deletions tests/unit/FileTest.php
@@ -0,0 +1,44 @@
<?php declare(strict_types=1);
/*
* This file is part of FOAL.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* 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],
);
}
}

0 comments on commit a201947

Please sign in to comment.