2019-10-30 10:46:37 +07:00
|
|
|
import * as install from '../src/install';
|
2020-10-04 20:08:22 +07:00
|
|
|
import * as utils from '../src/utils';
|
2019-10-30 10:46:37 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}),
|
2021-05-31 06:51:18 +07:00
|
|
|
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(' ');
|
|
|
|
})
|
2019-10-30 10:46:37 +07:00
|
|
|
}));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2019-10-30 10:46:37 +07:00
|
|
|
*/
|
|
|
|
function setEnv(
|
2019-12-20 19:59:05 +07:00
|
|
|
version: string | number,
|
2019-10-30 10:46:37 +07:00
|
|
|
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
|
2019-10-30 10:46:37 +07:00
|
|
|
): void {
|
2019-12-20 19:59:05 +07:00
|
|
|
process.env['php-version'] = version.toString();
|
2019-10-30 10:46:37 +07:00
|
|
|
process.env['RUNNER_OS'] = os;
|
2019-12-09 12:22:43 +07:00
|
|
|
process.env['extensions'] = extension_csv;
|
|
|
|
process.env['ini-values'] = ini_values_csv;
|
2019-10-30 10:46:37 +07:00
|
|
|
process.env['coverage'] = coverage_driver;
|
2019-12-27 08:26:49 +07:00
|
|
|
process.env['tools'] = tools;
|
2019-10-30 10:46:37 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('Install', () => {
|
2021-10-09 19:00:06 +07:00
|
|
|
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}
|
2021-10-09 20:31:59 +07:00
|
|
|
${'7.3'} | ${'linux'} | ${''} | ${''} | ${''} | ${''} | ${'initial script bash linux.sh 7.3 ' + __dirname}
|
2022-01-13 05:59:05 +07:00
|
|
|
${'7.3'} | ${'linux'} | ${'a, b'} | ${'a=b'} | ${'x'} | ${'phpunit'} | ${'initial script install extensions add_tool set coverage driver edit php.ini bash linux.sh 7.3 ' + __dirname}
|
2021-11-25 19:04:13 +07:00
|
|
|
${'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 19:00:06 +07:00
|
|
|
`(
|
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',
|
2021-10-09 19:00:06 +07:00
|
|
|
async ({
|
|
|
|
version,
|
2021-10-09 20:14:47 +07:00
|
|
|
os,
|
2021-10-09 19:00:06 +07:00
|
|
|
extension_csv,
|
|
|
|
ini_values_csv,
|
|
|
|
coverage_driver,
|
|
|
|
tools,
|
|
|
|
output
|
|
|
|
}) => {
|
|
|
|
setEnv(
|
|
|
|
version,
|
2021-10-09 20:14:47 +07:00
|
|
|
os,
|
2021-10-09 19:00:06 +07:00
|
|
|
extension_csv,
|
|
|
|
ini_values_csv,
|
|
|
|
coverage_driver,
|
|
|
|
tools
|
|
|
|
);
|
|
|
|
|
2021-10-09 20:31:59 +07:00
|
|
|
expect(await install.run()).toBe(output);
|
2021-10-09 19:00:06 +07:00
|
|
|
}
|
|
|
|
);
|
2019-10-30 10:46:37 +07:00
|
|
|
});
|