1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-11 16:59:45 +01:00
psalm/tests/LanguageServer/PathMapperTest.php

76 lines
2.7 KiB
PHP
Raw Normal View History

2023-07-23 00:04:25 +02:00
<?php
namespace Psalm\Tests\LanguageServer;
use PHPUnit\Framework\TestCase;
use Psalm\Internal\LanguageServer\PathMapper;
final class PathMapperTest extends TestCase
{
public function testUsesUpdatedClientRoot(): void
{
$mapper = new PathMapper('/var/www');
$mapper->configureClientRoot('/home/user/src/project');
$this->assertSame(
'/home/user/src/project/filename.php',
2023-07-23 02:16:44 +02:00
$mapper->mapServerToClient('/var/www/filename.php'),
2023-07-23 00:04:25 +02:00
);
}
public function testIgnoresClientRootIfItWasPreconfigures(): void
{
$mapper = new PathMapper('/var/www', '/home/user/src/project');
// this will be ignored
$mapper->configureClientRoot('/home/anotheruser/Projects/project');
$this->assertSame(
'/home/user/src/project/filename.php',
2023-07-23 02:16:44 +02:00
$mapper->mapServerToClient('/var/www/filename.php'),
2023-07-23 00:04:25 +02:00
);
}
/**
* @dataProvider mappingProvider
*/
public function testMapsClientToServer(
2023-07-23 01:19:39 +02:00
string $server_root,
?string $client_root_reconfigured,
string $client_root_provided_later,
string $client_path,
string $server_ath
2023-07-23 00:04:25 +02:00
): void {
2023-07-23 01:19:39 +02:00
$mapper = new PathMapper($server_root, $client_root_reconfigured);
$mapper->configureClientRoot($client_root_provided_later);
2023-07-23 00:04:25 +02:00
$this->assertSame(
2023-07-23 01:19:39 +02:00
$server_ath,
2023-07-23 02:16:44 +02:00
$mapper->mapClientToServer($client_path),
2023-07-23 00:04:25 +02:00
);
}
/** @dataProvider mappingProvider */
public function testMapsServerToClient(
2023-07-23 01:19:39 +02:00
string $server_root,
?string $client_root_preconfigured,
string $client_root_provided_later,
string $client_path,
string $server_path
2023-07-23 00:04:25 +02:00
): void {
2023-07-23 01:19:39 +02:00
$mapper = new PathMapper($server_root, $client_root_preconfigured);
$mapper->configureClientRoot($client_root_provided_later);
2023-07-23 00:04:25 +02:00
$this->assertSame(
2023-07-23 01:19:39 +02:00
$client_path,
2023-07-23 02:16:44 +02:00
$mapper->mapServerToClient($server_path),
2023-07-23 00:04:25 +02:00
);
}
/** @return iterable<int, array{string, string|null, string, string, string}> */
public static function mappingProvider(): iterable
{
yield ["/var/a", null, "/user/project", "/user/project/filename.php", "/var/a/filename.php"];
yield ["/var/a", "/user/project", "/whatever", "/user/project/filename.php", "/var/a/filename.php"];
yield ["/var/a/", "/user/project", "/whatever", "/user/project/filename.php", "/var/a/filename.php"];
yield ["/var/a", "/user/project/", "/whatever", "/user/project/filename.php", "/var/a/filename.php"];
yield ["/var/a/", "/user/project/", "/whatever", "/user/project/filename.php", "/var/a/filename.php"];
}
}