mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-23 04:11:06 +07:00
Refactor install.test.ts
This commit is contained in:
parent
f8e867a9ff
commit
ad196941ed
@ -1,4 +1,5 @@
|
|||||||
import * as install from '../src/install';
|
import * as install from '../src/install';
|
||||||
|
import * as utils from '../src/utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mock install.ts
|
* Mock install.ts
|
||||||
@ -39,32 +40,18 @@ jest.mock('../src/install', () => ({
|
|||||||
run: jest.fn().mockImplementation(
|
run: jest.fn().mockImplementation(
|
||||||
async (): Promise<string> => {
|
async (): Promise<string> => {
|
||||||
const os_version: string = process.env['RUNNER_OS'] || '';
|
const os_version: string = process.env['RUNNER_OS'] || '';
|
||||||
let version: string = process.env['php-version'] || '';
|
const version: string = await utils.parseVersion(
|
||||||
version = version.length > 1 ? version.slice(0, 3) : version + '.0';
|
await utils.getInput('php-version', true)
|
||||||
let script = '';
|
);
|
||||||
switch (os_version) {
|
const tool = await utils.scriptTool(os_version);
|
||||||
case 'darwin':
|
const filename = os_version + (await utils.scriptExtension(os_version));
|
||||||
case 'linux':
|
return [
|
||||||
script = await install.getScript(
|
await install.getScript(filename, version, os_version),
|
||||||
os_version + '.sh',
|
tool,
|
||||||
version,
|
filename,
|
||||||
os_version
|
version,
|
||||||
);
|
__dirname
|
||||||
script += 'bash script.sh ' + version + ' ' + __dirname;
|
].join(' ');
|
||||||
break;
|
|
||||||
case 'win32':
|
|
||||||
script = await install.getScript(
|
|
||||||
os_version + '.sh',
|
|
||||||
version,
|
|
||||||
os_version
|
|
||||||
);
|
|
||||||
script += 'pwsh script.ps1 ' + version + ' ' + __dirname;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
script += os_version + ' is not supported';
|
|
||||||
}
|
|
||||||
|
|
||||||
return script;
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}));
|
}));
|
||||||
@ -101,13 +88,13 @@ describe('Install', () => {
|
|||||||
|
|
||||||
let script: string = '' + (await install.run());
|
let script: string = '' + (await install.run());
|
||||||
expect(script).toContain('initial script');
|
expect(script).toContain('initial script');
|
||||||
expect(script).toContain('pwsh script.ps1 7.0 ' + __dirname);
|
expect(script).toContain('pwsh win32.ps1 7.0 ' + __dirname);
|
||||||
|
|
||||||
setEnv('7.3', 'win32', '', '', '', '');
|
setEnv('7.3', 'win32', '', '', '', '');
|
||||||
|
|
||||||
script = '' + (await install.run());
|
script = '' + (await install.run());
|
||||||
expect(script).toContain('initial script');
|
expect(script).toContain('initial script');
|
||||||
expect(script).toContain('pwsh script.ps1 7.3 ' + __dirname);
|
expect(script).toContain('pwsh win32.ps1 7.3 ' + __dirname);
|
||||||
|
|
||||||
setEnv('7.3', 'win32', 'a, b', 'a=b', 'x', '');
|
setEnv('7.3', 'win32', 'a, b', 'a=b', 'x', '');
|
||||||
|
|
||||||
@ -116,7 +103,7 @@ describe('Install', () => {
|
|||||||
expect(script).toContain('install extensions');
|
expect(script).toContain('install extensions');
|
||||||
expect(script).toContain('edit php.ini');
|
expect(script).toContain('edit php.ini');
|
||||||
expect(script).toContain('set coverage driver');
|
expect(script).toContain('set coverage driver');
|
||||||
expect(script).toContain('pwsh script.ps1 7.3 ' + __dirname);
|
expect(script).toContain('pwsh win32.ps1 7.3 ' + __dirname);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Test install on linux', async () => {
|
it('Test install on linux', async () => {
|
||||||
@ -124,7 +111,13 @@ describe('Install', () => {
|
|||||||
|
|
||||||
let script: string = '' + (await install.run());
|
let script: string = '' + (await install.run());
|
||||||
expect(script).toContain('initial script');
|
expect(script).toContain('initial script');
|
||||||
expect(script).toContain('bash script.sh 7.3 ');
|
expect(script).toContain('bash linux.sh 7.3 ');
|
||||||
|
|
||||||
|
setEnv('latest', 'linux', '', '', '', '');
|
||||||
|
|
||||||
|
script = '' + (await install.run());
|
||||||
|
expect(script).toContain('initial script');
|
||||||
|
expect(script).toContain('bash linux.sh 7.4 ');
|
||||||
|
|
||||||
setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'phpunit');
|
setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'phpunit');
|
||||||
|
|
||||||
@ -133,7 +126,7 @@ describe('Install', () => {
|
|||||||
expect(script).toContain('install extensions');
|
expect(script).toContain('install extensions');
|
||||||
expect(script).toContain('edit php.ini');
|
expect(script).toContain('edit php.ini');
|
||||||
expect(script).toContain('set coverage driver');
|
expect(script).toContain('set coverage driver');
|
||||||
expect(script).toContain('bash script.sh 7.3');
|
expect(script).toContain('bash linux.sh 7.3');
|
||||||
expect(script).toContain('add_tool');
|
expect(script).toContain('add_tool');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -142,7 +135,7 @@ describe('Install', () => {
|
|||||||
|
|
||||||
let script: string = '' + (await install.run());
|
let script: string = '' + (await install.run());
|
||||||
expect(script).toContain('initial script');
|
expect(script).toContain('initial script');
|
||||||
expect(script).toContain('bash script.sh 7.3 ' + __dirname);
|
expect(script).toContain('bash darwin.sh 7.3 ' + __dirname);
|
||||||
|
|
||||||
setEnv('7.3', 'darwin', 'a, b', 'a=b', 'x', '');
|
setEnv('7.3', 'darwin', 'a, b', 'a=b', 'x', '');
|
||||||
|
|
||||||
@ -151,7 +144,7 @@ describe('Install', () => {
|
|||||||
expect(script).toContain('install extensions');
|
expect(script).toContain('install extensions');
|
||||||
expect(script).toContain('edit php.ini');
|
expect(script).toContain('edit php.ini');
|
||||||
expect(script).toContain('set coverage driver');
|
expect(script).toContain('set coverage driver');
|
||||||
expect(script).toContain('bash script.sh 7.3 ' + __dirname);
|
expect(script).toContain('bash darwin.sh 7.3 ' + __dirname);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Test malformed version inputs', async () => {
|
it('Test malformed version inputs', async () => {
|
||||||
@ -159,18 +152,18 @@ describe('Install', () => {
|
|||||||
|
|
||||||
let script: string = '' + '' + (await install.run());
|
let script: string = '' + '' + (await install.run());
|
||||||
expect(script).toContain('initial script');
|
expect(script).toContain('initial script');
|
||||||
expect(script).toContain('bash script.sh 7.4 ' + __dirname);
|
expect(script).toContain('bash darwin.sh 7.4 ' + __dirname);
|
||||||
|
|
||||||
setEnv(8.0, 'darwin', '', '', '', '');
|
setEnv(8.0, 'darwin', '', '', '', '');
|
||||||
|
|
||||||
script = '' + (await install.run());
|
script = '' + (await install.run());
|
||||||
expect(script).toContain('initial script');
|
expect(script).toContain('initial script');
|
||||||
expect(script).toContain('bash script.sh 8.0 ' + __dirname);
|
expect(script).toContain('bash darwin.sh 8.0 ' + __dirname);
|
||||||
|
|
||||||
setEnv(8, 'darwin', '', '', '', '');
|
setEnv(8, 'darwin', '', '', '', '');
|
||||||
|
|
||||||
script = '' + (await install.run());
|
script = '' + (await install.run());
|
||||||
expect(script).toContain('initial script');
|
expect(script).toContain('initial script');
|
||||||
expect(script).toContain('bash script.sh 8.0 ' + __dirname);
|
expect(script).toContain('bash darwin.sh 8.0 ' + __dirname);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user