Skip to content

Commit

Permalink
Refactor to use setup-php
Browse files Browse the repository at this point in the history
  • Loading branch information
shivammathur committed Sep 19, 2021
1 parent 3572ca5 commit b52930e
Show file tree
Hide file tree
Showing 7 changed files with 2,811 additions and 2,074 deletions.
3 changes: 2 additions & 1 deletion __tests__/cache.test.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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(
Expand Down
37 changes: 7 additions & 30 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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');
Expand All @@ -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(' ')
);
});
});
Loading

0 comments on commit b52930e

Please sign in to comment.