setup-php/__tests__/install.test.ts

110 lines
4.9 KiB
TypeScript
Raw Normal View History

import * as install from '../src/install';
2020-10-04 20:08:22 +07:00
import * as utils from '../src/utils';
/**
* Mock install.ts
*/
jest.mock('../src/install', () => ({
2021-10-09 20:29:50 +07:00
getScript: jest.fn().mockImplementation(async (): Promise<string> => {
const extension_csv: string = process.env['extensions'] || '';
const ini_values_csv: string = process.env['ini-values'] || '';
const coverage_driver: string = process.env['coverage'] || '';
const tools_csv: string = process.env['tools'] || '';
let script = 'initial script';
script += extension_csv ? ' install extensions' : '';
2022-01-13 05:59:05 +07:00
script += tools_csv ? ' add_tool' : '';
2021-10-09 20:29:50 +07:00
script += coverage_driver ? ' set coverage driver' : '';
script += ini_values_csv ? ' edit php.ini' : '';
return script;
}),
run: jest.fn().mockImplementation(async (): Promise<string> => {
const os_version: string = process.env['RUNNER_OS'] || '';
const version: string = await utils.parseVersion(
await utils.getInput('php-version', true)
);
2022-01-25 15:13:49 +07:00
const ini_file: string = await utils.parseIniFile(
await utils.getInput('ini-file', false)
);
const tool = await utils.scriptTool(os_version);
const filename = os_version + (await utils.scriptExtension(os_version));
return [
await install.getScript(filename, version, os_version),
tool,
filename,
version,
2022-01-25 15:13:49 +07:00
ini_file,
__dirname
].join(' ');
})
}));
/**
* Function to set the process.env
*
* @param version
* @param os
* @param extension_csv
* @param ini_values_csv
* @param coverage_driver
2020-05-22 03:24:13 +07:00
* @param tools
*/
function setEnv(
version: string | number,
os: string,
extension_csv: string,
2022-01-25 15:13:49 +07:00
ini_file: string,
ini_values_csv: string,
2019-11-07 12:41:35 +07:00
coverage_driver: string,
2020-05-22 03:24:13 +07:00
tools: string
): void {
process.env['php-version'] = version.toString();
process.env['RUNNER_OS'] = os;
process.env['extensions'] = extension_csv;
2022-01-25 15:13:49 +07:00
process.env['ini-file'] = ini_file;
process.env['ini-values'] = ini_values_csv;
process.env['coverage'] = coverage_driver;
2019-12-27 08:26:49 +07:00
process.env['tools'] = tools;
}
describe('Install', () => {
it.each`
2022-01-25 15:13:49 +07:00
version | os | extension_csv | ini_file | ini_values_csv | coverage_driver | tools | output
${'7.3'} | ${'darwin'} | ${''} | ${'production'} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 7.3 production ' + __dirname}
${'7.3'} | ${'darwin'} | ${'a, b'} | ${'development'} | ${'a=b'} | ${'x'} | ${''} | ${'initial script install extensions set coverage driver edit php.ini bash darwin.sh 7.3 development ' + __dirname}
${'7.4.1'} | ${'darwin'} | ${''} | ${'none'} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 7.4 none ' + __dirname}
${'8'} | ${'darwin'} | ${''} | ${''} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 8.0 production ' + __dirname}
${'8.0'} | ${'darwin'} | ${''} | ${'development'} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 8.0 development ' + __dirname}
${'8.1'} | ${'darwin'} | ${''} | ${'none'} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 8.1 none ' + __dirname}
${'7.3'} | ${'linux'} | ${''} | ${'invalid'} | ${''} | ${''} | ${''} | ${'initial script bash linux.sh 7.3 production ' + __dirname}
${'7.3'} | ${'linux'} | ${'a, b'} | ${'development'} | ${'a=b'} | ${'x'} | ${'phpunit'} | ${'initial script install extensions add_tool set coverage driver edit php.ini bash linux.sh 7.3 development ' + __dirname}
${'latest'} | ${'linux'} | ${''} | ${'none'} | ${''} | ${''} | ${''} | ${'initial script bash linux.sh 8.1 none ' + __dirname}
${'7.0'} | ${'win32'} | ${''} | ${'production'} | ${''} | ${''} | ${''} | ${'initial script pwsh win32.ps1 7.0 production ' + __dirname}
${'7.3'} | ${'win32'} | ${''} | ${'development'} | ${''} | ${''} | ${''} | ${'initial script pwsh win32.ps1 7.3 development ' + __dirname}
${'7.3'} | ${'win32'} | ${'a, b'} | ${'none'} | ${'a=b'} | ${'x'} | ${''} | ${'initial script install extensions set coverage driver edit php.ini pwsh win32.ps1 7.3 none ' + __dirname}
`(
2021-10-09 20:14:47 +07:00
'Test install on $os for $version with extensions=$extension_csv, ini_values=$ini_values_csv, coverage_driver=$coverage_driver, tools=$tools',
async ({
version,
2021-10-09 20:14:47 +07:00
os,
extension_csv,
2022-01-25 15:13:49 +07:00
ini_file,
ini_values_csv,
coverage_driver,
tools,
output
}) => {
setEnv(
version,
2021-10-09 20:14:47 +07:00
os,
extension_csv,
2022-01-25 15:13:49 +07:00
ini_file,
ini_values_csv,
coverage_driver,
tools
);
expect(await install.run()).toBe(output);
}
);
});