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-10-30 10:46:37 +07:00
|
|
|
|
2019-11-24 03:34:12 +07:00
|
|
|
let script = 'initial script ' + filename + version + os_version;
|
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'] || '';
|
|
|
|
const version: string = process.env['php-version'] || '';
|
|
|
|
let script = '';
|
2019-10-30 10:46:37 +07:00
|
|
|
switch (os_version) {
|
|
|
|
case 'darwin':
|
|
|
|
script = await install.build(os_version + '.sh', version, os_version);
|
|
|
|
script += 'sh script.sh ' + version + ' ' + __dirname;
|
|
|
|
break;
|
2019-11-24 03:34:12 +07:00
|
|
|
case 'linux': {
|
|
|
|
const pecl: string = process.env['pecl'] || '';
|
2019-11-07 12:41:35 +07:00
|
|
|
script = await install.build(os_version + '.sh', version, os_version);
|
|
|
|
script += 'sh script.sh ' + version + ' ' + pecl + ' ' + __dirname;
|
|
|
|
break;
|
2019-11-24 03:34:12 +07:00
|
|
|
}
|
2019-10-30 10:46:37 +07:00
|
|
|
case 'win32':
|
|
|
|
script = await install.build(os_version + '.sh', version, os_version);
|
|
|
|
script +=
|
|
|
|
'pwsh script.ps1 -version ' + version + ' -dir ' + __dirname;
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
function setEnv(
|
|
|
|
version: string,
|
|
|
|
os: string,
|
|
|
|
extension_csv: string,
|
|
|
|
ini_values_csv: string,
|
2019-11-07 12:41:35 +07:00
|
|
|
coverage_driver: string,
|
2019-11-24 03:34:12 +07:00
|
|
|
pecl: string
|
2019-10-30 10:46:37 +07:00
|
|
|
): void {
|
|
|
|
process.env['php-version'] = version;
|
|
|
|
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-11-07 12:41:35 +07:00
|
|
|
process.env['pecl'] = pecl;
|
2019-10-30 10:46:37 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('Install', () => {
|
|
|
|
it('Test install on windows', async () => {
|
2019-11-07 12:41:35 +07:00
|
|
|
setEnv('7.3', 'win32', '', '', '', '');
|
2019-10-30 10:46:37 +07:00
|
|
|
// @ts-ignore
|
|
|
|
let script: string = await install.run();
|
|
|
|
expect(script).toContain('initial script');
|
|
|
|
expect(script).toContain('pwsh script.ps1 -version 7.3 -dir ' + __dirname);
|
|
|
|
|
2019-11-07 12:41:35 +07:00
|
|
|
setEnv('7.3', 'win32', 'a, b', 'a=b', 'x', '');
|
2019-10-30 10:46:37 +07:00
|
|
|
// @ts-ignore
|
|
|
|
script = await install.run();
|
|
|
|
expect(script).toContain('initial script');
|
|
|
|
expect(script).toContain('install extensions');
|
|
|
|
expect(script).toContain('edit php.ini');
|
|
|
|
expect(script).toContain('set coverage driver');
|
|
|
|
expect(script).toContain('pwsh script.ps1 -version 7.3 -dir ' + __dirname);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Test install on linux', async () => {
|
2019-11-07 12:41:35 +07:00
|
|
|
setEnv('7.3', 'linux', '', '', '', '');
|
2019-10-30 10:46:37 +07:00
|
|
|
// @ts-ignore
|
|
|
|
let script: string = await install.run();
|
|
|
|
expect(script).toContain('initial script');
|
2019-11-07 12:41:35 +07:00
|
|
|
expect(script).toContain('sh script.sh 7.3 ');
|
2019-10-30 10:46:37 +07:00
|
|
|
|
2019-11-07 12:41:35 +07:00
|
|
|
setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'true');
|
2019-10-30 10:46:37 +07:00
|
|
|
// @ts-ignore
|
|
|
|
script = await install.run();
|
|
|
|
expect(script).toContain('initial script');
|
|
|
|
expect(script).toContain('install extensions');
|
|
|
|
expect(script).toContain('edit php.ini');
|
|
|
|
expect(script).toContain('set coverage driver');
|
2019-11-07 12:41:35 +07:00
|
|
|
expect(script).toContain('sh script.sh 7.3 true');
|
|
|
|
|
2019-11-24 03:34:12 +07:00
|
|
|
setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'true');
|
2019-11-07 12:41:35 +07:00
|
|
|
// @ts-ignore
|
|
|
|
script = await install.run();
|
|
|
|
expect(script).toContain('initial script');
|
|
|
|
expect(script).toContain('install extensions');
|
|
|
|
expect(script).toContain('edit php.ini');
|
|
|
|
expect(script).toContain('set coverage driver');
|
|
|
|
expect(script).toContain('sh script.sh 7.3 true');
|
2019-10-30 10:46:37 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Test install on darwin', async () => {
|
2019-11-07 12:41:35 +07:00
|
|
|
setEnv('7.3', 'darwin', '', '', '', '');
|
2019-10-30 10:46:37 +07:00
|
|
|
// @ts-ignore
|
|
|
|
let script: string = await install.run();
|
|
|
|
expect(script).toContain('initial script');
|
|
|
|
expect(script).toContain('sh script.sh 7.3 ' + __dirname);
|
|
|
|
|
2019-11-07 12:41:35 +07:00
|
|
|
setEnv('7.3', 'darwin', 'a, b', 'a=b', 'x', '');
|
2019-10-30 10:46:37 +07:00
|
|
|
// @ts-ignore
|
|
|
|
script = await install.run();
|
|
|
|
expect(script).toContain('initial script');
|
|
|
|
expect(script).toContain('install extensions');
|
|
|
|
expect(script).toContain('edit php.ini');
|
|
|
|
expect(script).toContain('set coverage driver');
|
|
|
|
expect(script).toContain('sh script.sh 7.3 ' + __dirname);
|
|
|
|
});
|
|
|
|
});
|