mirror of
https://github.com/shivammathur/setup-php.git
synced 2025-07-25 08:09:08 +07:00
Support .php-version file; closes #629
This commit is contained in:
@ -10,7 +10,7 @@ jest.mock('../src/install', () => ({
|
||||
.mockImplementation(async (os: string): Promise<string> => {
|
||||
const filename = os + (await utils.scriptExtension(os));
|
||||
const version: string = await utils.parseVersion(
|
||||
await utils.getInput('php-version', true)
|
||||
await utils.resolveVersion()
|
||||
);
|
||||
const ini_file: string = await utils.parseIniFile(
|
||||
await utils.getInput('ini-file', false)
|
||||
|
@ -1,3 +1,4 @@
|
||||
import fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as utils from '../src/utils';
|
||||
|
||||
@ -7,7 +8,8 @@ import * as utils from '../src/utils';
|
||||
jest.mock('@actions/core', () => ({
|
||||
getInput: jest.fn().mockImplementation(key => {
|
||||
return ['setup-php'].indexOf(key) !== -1 ? key : '';
|
||||
})
|
||||
}),
|
||||
info: jest.fn()
|
||||
}));
|
||||
|
||||
/**
|
||||
@ -261,6 +263,31 @@ describe('Utils tests', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('checking resolveVersion', async () => {
|
||||
await expect(utils.resolveVersion()).rejects.toThrow(
|
||||
"Neither 'php-version' nor 'php-version-file' inputs were supplied, and could not find '.php-version' file."
|
||||
);
|
||||
|
||||
process.env['php-version-file'] = '.phpenv-version';
|
||||
await expect(utils.resolveVersion()).rejects.toThrow(
|
||||
"Could not find '.phpenv-version' file."
|
||||
);
|
||||
|
||||
const existsSync = jest.spyOn(fs, 'existsSync').mockImplementation();
|
||||
const readFileSync = jest.spyOn(fs, 'readFileSync').mockImplementation();
|
||||
|
||||
existsSync.mockReturnValue(true);
|
||||
readFileSync.mockReturnValue('8.1');
|
||||
|
||||
expect(await utils.resolveVersion()).toBe('8.1');
|
||||
|
||||
process.env['php-version'] = '8.2';
|
||||
expect(await utils.resolveVersion()).toBe('8.2');
|
||||
|
||||
existsSync.mockClear();
|
||||
readFileSync.mockClear();
|
||||
});
|
||||
|
||||
it('checking setVariable', async () => {
|
||||
let script: string = await utils.setVariable('var', 'command', 'linux');
|
||||
expect(script).toEqual('\nvar="$(command)"\n');
|
||||
|
Reference in New Issue
Block a user