Add support for reading PHP version from composer.lock or composer.json

This commit is contained in:
Jason Gill
2023-07-29 19:46:06 -04:00
parent 72ae4ccbe5
commit a5fb328c6a
3 changed files with 78 additions and 0 deletions

View File

@ -282,6 +282,31 @@ describe('Utils tests', () => {
process.env['php-version'] = '8.2';
expect(await utils.readPHPVersion()).toBe('8.2');
delete process.env['php-version-file'];
delete process.env['php-version'];
existsSync.mockReturnValueOnce(false).mockReturnValueOnce(true);
readFileSync.mockReturnValue(
'{ "platform-overrides": { "php": "7.3.25" } }'
);
expect(await utils.readPHPVersion()).toBe('7.3.25');
existsSync
.mockReturnValueOnce(false)
.mockReturnValueOnce(false)
.mockReturnValueOnce(true);
readFileSync.mockReturnValue(
'{ "config": { "platform": { "php": "7.4.33" } } }'
);
expect(await utils.readPHPVersion()).toBe('7.4.33');
existsSync
.mockReturnValueOnce(false)
.mockReturnValueOnce(false)
.mockReturnValueOnce(true);
readFileSync.mockReturnValue('{ "require": { "php": "^8.2" } }');
expect(await utils.readPHPVersion()).toBe('^8.2');
existsSync.mockClear();
readFileSync.mockClear();
});