2019-10-30 10:46:37 +07:00
|
|
|
import * as install from '../src/install';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mock install.ts
|
|
|
|
*/
|
|
|
|
jest.mock('../src/install', () => ({
|
|
|
|
build: jest.fn().mockImplementation(
|
|
|
|
async (
|
|
|
|
filename: string,
|
|
|
|
version: string,
|
|
|
|
os_version: string
|
|
|
|
): Promise<string> => {
|
2019-12-09 12:22:43 +07:00
|
|
|
const extension_csv: string = process.env['extensions'] || '';
|
|
|
|
const ini_values_csv: string = process.env['ini-values'] || '';
|
2019-11-24 03:34:12 +07:00
|
|
|
const coverage_driver: string = process.env['coverage'] || '';
|
2019-12-27 08:26:49 +07:00
|
|
|
let tools_csv: string = process.env['tools'] || '';
|
|
|
|
const pecl: string = process.env['pecl'] || '';
|
|
|
|
if (pecl == 'true') {
|
|
|
|
tools_csv = 'pecl, ' + tools_csv;
|
|
|
|
}
|
2019-10-30 10:46:37 +07:00
|
|
|
|
2019-11-24 03:34:12 +07:00
|
|
|
let script = 'initial script ' + filename + version + os_version;
|
2020-01-01 17:35:01 +07:00
|
|
|
if (tools_csv) {
|
|
|
|
script += 'add_tool';
|
|
|
|
}
|
2019-10-30 10:46:37 +07:00
|
|
|
if (extension_csv) {
|
|
|
|
script += 'install extensions';
|
|
|
|
}
|
|
|
|
if (ini_values_csv) {
|
|
|
|
script += 'edit php.ini';
|
|
|
|
}
|
|
|
|
if (coverage_driver) {
|
|
|
|
script += 'set coverage driver';
|
|
|
|
}
|
|
|
|
|
|
|
|
return script;
|
|
|
|
}
|
|
|
|
),
|
|
|
|
run: jest.fn().mockImplementation(
|
|
|
|
async (): Promise<string> => {
|
2019-11-24 03:34:12 +07:00
|
|
|
const os_version: string = process.env['RUNNER_OS'] || '';
|
2019-12-14 11:43:01 +07:00
|
|
|
let version: string = process.env['php-version'] || '';
|
2019-12-20 19:59:05 +07:00
|
|
|
version = version.length > 1 ? version.slice(0, 3) : version + '.0';
|
2019-11-24 03:34:12 +07:00
|
|
|
let script = '';
|
2019-10-30 10:46:37 +07:00
|
|
|
switch (os_version) {
|
|
|
|
case 'darwin':
|
2019-12-27 08:26:49 +07:00
|
|
|
case 'linux':
|
2019-10-30 10:46:37 +07:00
|
|
|
script = await install.build(os_version + '.sh', version, os_version);
|
2020-02-09 05:38:48 +07:00
|
|
|
script += 'bash script.sh ' + version + ' ' + __dirname;
|
2019-10-30 10:46:37 +07:00
|
|
|
break;
|
|
|
|
case 'win32':
|
|
|
|
script = await install.build(os_version + '.sh', version, os_version);
|
2019-12-26 20:01:18 +07:00
|
|
|
script += 'pwsh script.ps1 ' + version + ' ' + __dirname;
|
2019-10-30 10:46:37 +07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
script += os_version + ' is not supported';
|
|
|
|
}
|
|
|
|
|
|
|
|
return script;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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', () => {
|
|
|
|
it('Test install on windows', async () => {
|
2020-05-22 03:24:13 +07:00
|
|
|
setEnv('7.0', 'win32', '', '', '', '');
|
|
|
|
|
|
|
|
let script: string = '' + (await install.run());
|
2019-10-30 10:46:37 +07:00
|
|
|
expect(script).toContain('initial script');
|
2019-12-26 20:01:18 +07:00
|
|
|
expect(script).toContain('pwsh script.ps1 7.0 ' + __dirname);
|
2019-12-14 11:43:01 +07:00
|
|
|
|
2020-05-22 03:24:13 +07:00
|
|
|
setEnv('7.3', 'win32', '', '', '', '');
|
|
|
|
|
|
|
|
script = '' + (await install.run());
|
2019-12-14 11:43:01 +07:00
|
|
|
expect(script).toContain('initial script');
|
2019-12-26 20:01:18 +07:00
|
|
|
expect(script).toContain('pwsh script.ps1 7.3 ' + __dirname);
|
2019-10-30 10:46:37 +07:00
|
|
|
|
2020-05-22 03:24:13 +07:00
|
|
|
setEnv('7.3', 'win32', 'a, b', 'a=b', 'x', '');
|
|
|
|
|
|
|
|
script = '' + (await install.run());
|
2019-10-30 10:46:37 +07:00
|
|
|
expect(script).toContain('initial script');
|
|
|
|
expect(script).toContain('install extensions');
|
|
|
|
expect(script).toContain('edit php.ini');
|
|
|
|
expect(script).toContain('set coverage driver');
|
2019-12-26 20:01:18 +07:00
|
|
|
expect(script).toContain('pwsh script.ps1 7.3 ' + __dirname);
|
2019-10-30 10:46:37 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Test install on linux', async () => {
|
2020-05-22 03:24:13 +07:00
|
|
|
setEnv('7.3', 'linux', '', '', '', '');
|
|
|
|
|
|
|
|
let script: string = '' + (await install.run());
|
2019-10-30 10:46:37 +07:00
|
|
|
expect(script).toContain('initial script');
|
2020-02-09 05:38:48 +07:00
|
|
|
expect(script).toContain('bash script.sh 7.3 ');
|
2019-10-30 10:46:37 +07:00
|
|
|
|
2020-05-22 03:24:13 +07:00
|
|
|
setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'phpunit');
|
2019-11-07 12:41:35 +07:00
|
|
|
|
2020-05-22 03:24:13 +07:00
|
|
|
script = '' + (await install.run());
|
2019-11-07 12:41:35 +07:00
|
|
|
expect(script).toContain('initial script');
|
|
|
|
expect(script).toContain('install extensions');
|
|
|
|
expect(script).toContain('edit php.ini');
|
|
|
|
expect(script).toContain('set coverage driver');
|
2020-02-09 05:38:48 +07:00
|
|
|
expect(script).toContain('bash script.sh 7.3');
|
2019-12-27 08:26:49 +07:00
|
|
|
expect(script).toContain('add_tool');
|
2019-10-30 10:46:37 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Test install on darwin', async () => {
|
2020-05-22 03:24:13 +07:00
|
|
|
setEnv('7.3', 'darwin', '', '', '', '');
|
|
|
|
|
|
|
|
let script: string = '' + (await install.run());
|
2019-10-30 10:46:37 +07:00
|
|
|
expect(script).toContain('initial script');
|
2020-02-09 05:38:48 +07:00
|
|
|
expect(script).toContain('bash script.sh 7.3 ' + __dirname);
|
2019-10-30 10:46:37 +07:00
|
|
|
|
2020-05-22 03:24:13 +07:00
|
|
|
setEnv('7.3', 'darwin', 'a, b', 'a=b', 'x', '');
|
|
|
|
|
|
|
|
script = '' + (await install.run());
|
2019-10-30 10:46:37 +07:00
|
|
|
expect(script).toContain('initial script');
|
|
|
|
expect(script).toContain('install extensions');
|
|
|
|
expect(script).toContain('edit php.ini');
|
|
|
|
expect(script).toContain('set coverage driver');
|
2020-02-09 05:38:48 +07:00
|
|
|
expect(script).toContain('bash script.sh 7.3 ' + __dirname);
|
2019-10-30 10:46:37 +07:00
|
|
|
});
|
2019-12-20 19:59:05 +07:00
|
|
|
|
|
|
|
it('Test malformed version inputs', async () => {
|
2020-05-22 03:24:13 +07:00
|
|
|
setEnv('7.4.1', 'darwin', '', '', '', '');
|
|
|
|
|
|
|
|
let script: string = '' + '' + (await install.run());
|
2019-12-20 19:59:05 +07:00
|
|
|
expect(script).toContain('initial script');
|
2020-02-09 05:38:48 +07:00
|
|
|
expect(script).toContain('bash script.sh 7.4 ' + __dirname);
|
2019-12-20 19:59:05 +07:00
|
|
|
|
2020-05-22 03:24:13 +07:00
|
|
|
setEnv(8.0, 'darwin', '', '', '', '');
|
|
|
|
|
|
|
|
script = '' + (await install.run());
|
2019-12-20 19:59:05 +07:00
|
|
|
expect(script).toContain('initial script');
|
2020-02-09 05:38:48 +07:00
|
|
|
expect(script).toContain('bash script.sh 8.0 ' + __dirname);
|
2019-12-20 19:59:05 +07:00
|
|
|
|
2020-05-22 03:24:13 +07:00
|
|
|
setEnv(8, 'darwin', '', '', '', '');
|
|
|
|
|
|
|
|
script = '' + (await install.run());
|
2019-12-20 19:59:05 +07:00
|
|
|
expect(script).toContain('initial script');
|
2020-02-09 05:38:48 +07:00
|
|
|
expect(script).toContain('bash script.sh 8.0 ' + __dirname);
|
2019-12-20 19:59:05 +07:00
|
|
|
});
|
2019-10-30 10:46:37 +07:00
|
|
|
});
|