1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-05 00:20:08 +01:00

Update normalizePhpVersion regex

Handle "php@8.1"
Simplify the entire method into one block

Co-Authored-By: Nathan Morgan <nathan@fuelingtheweb.com>
This commit is contained in:
Matt Stauffer
2022-03-13 22:17:50 -04:00
parent 7226da5bb7
commit 530e4c30dd
2 changed files with 10 additions and 5 deletions

View File

@@ -311,11 +311,7 @@ public function symlinkPrimaryValetSock($phpVersion)
*/
public function normalizePhpVersion($version)
{
if (strpos($version, 'php') === false) {
$version = 'php'.$version;
}
return preg_replace('/(php)([0-9+])(?:.)?([0-9+])/i', '$1@$2.$3', $version);
return preg_replace('/(?:php@?)?([0-9+])(?:.)?([0-9+])/i', 'php@$1.$2', $version);
}
/**

View File

@@ -51,6 +51,15 @@ public function test_it_can_generate_sock_file_name_from_php_version()
$this->assertEquals('valet72.sock', resolve(PhpFpm::class)->fpmSockName('72'));
}
public function test_it_normalizes_php_versions()
{
$this->assertEquals('php@8.1', resolve(PhpFpm::class)->normalizePhpVersion('php@8.1'));
$this->assertEquals('php@8.1', resolve(PhpFpm::class)->normalizePhpVersion('php8.1'));
$this->assertEquals('php@8.1', resolve(PhpFpm::class)->normalizePhpVersion('php81'));
$this->assertEquals('php@8.1', resolve(PhpFpm::class)->normalizePhpVersion('8.1'));
$this->assertEquals('php@8.1', resolve(PhpFpm::class)->normalizePhpVersion('81'));
}
public function test_utilized_php_versions()
{
$fileSystemMock = Mockery::mock(Filesystem::class);