setup-php/__tests__/install.test.ts

102 lines
4.4 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 += tools_csv ? ' add_tool' : '';
script += extension_csv ? ' install extensions' : '';
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)
);
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,
__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,
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;
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`
2021-10-09 20:14:47 +07:00
version | os | extension_csv | ini_values_csv | coverage_driver | tools | output
2021-10-09 20:29:50 +07:00
${'7.3'} | ${'darwin'} | ${''} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 7.3 ' + __dirname}
${'7.3'} | ${'darwin'} | ${'a, b'} | ${'a=b'} | ${'x'} | ${''} | ${'initial script install extensions set coverage driver edit php.ini bash darwin.sh 7.3 ' + __dirname}
${'7.4.1'} | ${'darwin'} | ${''} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 7.4 ' + __dirname}
${'8'} | ${'darwin'} | ${''} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 8.0 ' + __dirname}
${'8.0'} | ${'darwin'} | ${''} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 8.0 ' + __dirname}
${'8.1'} | ${'darwin'} | ${''} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 8.1 ' + __dirname}
${'7.3'} | ${'linux'} | ${''} | ${''} | ${''} | ${''} | ${'initial script bash linux.sh 7.3 ' + __dirname}
${'7.3'} | ${'linux'} | ${'a, b'} | ${'a=b'} | ${'x'} | ${'phpunit'} | ${'initial script add_tool install extensions set coverage driver edit php.ini bash linux.sh 7.3 ' + __dirname}
${'latest'} | ${'linux'} | ${''} | ${''} | ${''} | ${''} | ${'initial script bash linux.sh 8.1 ' + __dirname}
2021-10-09 20:29:50 +07:00
${'7.0'} | ${'win32'} | ${''} | ${''} | ${''} | ${''} | ${'initial script pwsh win32.ps1 7.0 ' + __dirname}
${'7.3'} | ${'win32'} | ${''} | ${''} | ${''} | ${''} | ${'initial script pwsh win32.ps1 7.3 ' + __dirname}
${'7.3'} | ${'win32'} | ${'a, b'} | ${'a=b'} | ${'x'} | ${''} | ${'initial script install extensions set coverage driver edit php.ini pwsh win32.ps1 7.3 ' + __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,
ini_values_csv,
coverage_driver,
tools,
output
}) => {
setEnv(
version,
2021-10-09 20:14:47 +07:00
os,
extension_csv,
ini_values_csv,
coverage_driver,
tools
);
expect(await install.run()).toBe(output);
}
);
});