Skip to content

Commit 972fc94

Browse files
committed
Add more test cases
1 parent ec63131 commit 972fc94

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

tests/CodeConverterTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,37 @@
1111
namespace AdrianSuter\Autoload\Override\Tests;
1212

1313
use AdrianSuter\Autoload\Override\CodeConverter;
14+
use PhpParser\Parser;
1415
use PHPUnit\Framework\TestCase;
16+
use Prophecy\Argument;
17+
use Prophecy\Prophecy\MethodProphecy;
18+
use RuntimeException;
1519

1620
class CodeConverterTest extends TestCase
1721
{
18-
public function testA()
22+
public function testConvert(): void
1923
{
2024
$converter = new CodeConverter();
2125
$this->assertEquals(
2226
'<?php echo \foo\rand(0, 9);',
2327
$converter->convert('<?php echo \rand(0, 9);', ['\rand' => 'foo\rand'])
2428
);
2529
}
30+
31+
public function testExceptionIfParserReturnsNull(): void
32+
{
33+
$this->expectException(RuntimeException::class);
34+
$this->expectExceptionMessage('Code could not be parsed.');
35+
36+
$parserProphecy = $this->prophesize(Parser::class);
37+
38+
$parseProphecy = new MethodProphecy($parserProphecy, 'parse', [Argument::any()]);
39+
$parseProphecy->willReturn(null);
40+
41+
/** @var Parser $parser */
42+
$parser = $parserProphecy->reveal();
43+
44+
$converter = new CodeConverter(null, $parser);
45+
$converter->convert('<?php echo "1";', []);
46+
}
2647
}

0 commit comments

Comments
 (0)