Refactor to use setup-php
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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(' ')
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user