65 lines
1.8 KiB
PHP
65 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace JumPHP\Ide\Tests;
|
|
|
|
use JumPHP\Ide\Cryo\HotPatchSource;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/** The method under the cursor made the closure of a hot patch (the Cryo window's Hot patch tab). */
|
|
final class HotPatchSourceTest extends TestCase
|
|
{
|
|
private const CODE = <<<'PHP'
|
|
<?php
|
|
|
|
namespace App\Scene;
|
|
|
|
final class PlayScene extends AbstractScene
|
|
{
|
|
private array $list = [];
|
|
|
|
/** moves things */
|
|
public function update(float $dt): void
|
|
{
|
|
$f = function () { return 1; };
|
|
foreach ($this->list as $x) {
|
|
$x->go("{$dt}");
|
|
}
|
|
}
|
|
|
|
public static function make(int $n = 2): static
|
|
{
|
|
return new static();
|
|
}
|
|
}
|
|
|
|
function helper(): int
|
|
{
|
|
return 3;
|
|
}
|
|
PHP;
|
|
|
|
public function testTheMethodUnderTheCursorIsFoundWithItsClass(): void
|
|
{
|
|
$patch = HotPatchSource::at(self::CODE, 13);
|
|
self::assertSame('method', $patch['action']);
|
|
self::assertSame('App\Scene\PlayScene', $patch['class']);
|
|
self::assertSame('update', $patch['method']);
|
|
self::assertStringStartsWith('function (float $dt): void', $patch['code']);
|
|
self::assertStringEndsWith('}', $patch['code']);
|
|
self::assertStringContainsString('$x->go("{$dt}");', $patch['code']);
|
|
self::assertSame([10, 16], [$patch['from'], $patch['to']]);
|
|
}
|
|
|
|
public function testAStaticMethodAndAFunction(): void
|
|
{
|
|
self::assertSame('make', HotPatchSource::at(self::CODE, 20)['method']);
|
|
$f = HotPatchSource::at(self::CODE, 26);
|
|
self::assertSame(['function', 'App\Scene\helper'], [$f['action'], $f['function']]);
|
|
}
|
|
|
|
public function testOutsideAFunctionItSaysWhatToDo(): void
|
|
{
|
|
$this->expectExceptionMessage('Put the cursor in a method');
|
|
HotPatchSource::at(self::CODE, 7);
|
|
}
|
|
}
|