Refactor to use setup-php

This commit is contained in:
Shivam Mathur
2021-09-19 06:06:31 +05:30
parent 3572ca5db9
commit b52930e590
7 changed files with 2811 additions and 2074 deletions

View File

@@ -1,4 +1,5 @@
import path from 'path';
import * as spu from 'setup-php/lib/utils';
import * as cache from '../src/cache';
import * as utils from '../src/utils';
@@ -7,7 +8,7 @@ import * as utils from '../src/utils';
*/
jest.mock('../src/cache', () => ({
run: jest.fn().mockImplementation(async (): Promise<string> => {
const version: string = await utils.parseVersion(
const version: string = await spu.parseVersion(
process.env['php-version'] || ''
);
const extensions = await utils.filterExtensions(

View File

@@ -2,12 +2,6 @@ import * as fs from 'fs';
import * as path from 'path';
import * as utils from '../src/utils';
jest.mock('@actions/core', () => ({
getInput: jest.fn().mockImplementation(key => {
return ['cache-extensions'].indexOf(key) !== -1 ? key : '';
})
}));
async function cleanup(path: string): Promise<void> {
fs.unlink(path, error => {
if (error) {
@@ -17,24 +11,6 @@ async function cleanup(path: string): Promise<void> {
}
describe('Utils tests', () => {
it('checking readEnv', async () => {
process.env['test'] = 'setup-php';
expect(await utils.readEnv('test')).toBe('setup-php');
expect(await utils.readEnv('undefined')).toBe('');
});
it('checking getInput', async () => {
process.env['test'] = 'setup-php';
expect(await utils.getInput('test', false)).toBe('setup-php');
expect(await utils.getInput('cache-extensions', false)).toBe(
'cache-extensions'
);
expect(await utils.getInput('DoesNotExist', false)).toBe('');
await expect(async () => {
await utils.getInput('DoesNotExist', true);
}).rejects.toThrow('Input required and not supplied: DoesNotExist');
});
it('checking getOutput', async () => {
const temp_dir: string = process.env['RUNNER_TEMP'] || '';
const file_path: string = path.join(temp_dir, 'test');
@@ -43,14 +19,15 @@ describe('Utils tests', () => {
await cleanup(file_path);
});
it('checking parseVersion', async () => {
expect(await utils.parseVersion('7')).toBe('7.0');
expect(await utils.parseVersion('7.4')).toBe('7.4');
expect(await utils.parseVersion('latest')).toBe('7.4');
});
it('checking filterExtensions', async () => {
expect(await utils.filterExtensions('a,:b,c')).toBe('"a,c"');
expect(await utils.filterExtensions('a, :b, c')).toBe('"a, c"');
});
it('checking scriptCall', async () => {
const script: string = path.join(__dirname, '../src/scripts/cache.sh');
expect(await utils.scriptCall('test a b')).toBe(
['bash', script, 'test', 'a', 'b'].join(' ')
);
});
});