|
| 1 | +import * as install from '../src/install'; |
| 2 | + |
| 3 | +/** |
| 4 | + * Mock install.ts |
| 5 | + */ |
| 6 | +jest.mock('../src/install', () => ({ |
| 7 | + build: jest.fn().mockImplementation( |
| 8 | + async ( |
| 9 | + filename: string, |
| 10 | + version: string, |
| 11 | + os_version: string |
| 12 | + ): Promise<string> => { |
| 13 | + let extension_csv: string = process.env['extension-csv'] || ''; |
| 14 | + let ini_values_csv: string = process.env['ini-values-csv'] || ''; |
| 15 | + let coverage_driver: string = process.env['coverage'] || ''; |
| 16 | + |
| 17 | + let script: string = 'initial script'; |
| 18 | + if (extension_csv) { |
| 19 | + script += 'install extensions'; |
| 20 | + } |
| 21 | + if (ini_values_csv) { |
| 22 | + script += 'edit php.ini'; |
| 23 | + } |
| 24 | + if (coverage_driver) { |
| 25 | + script += 'set coverage driver'; |
| 26 | + } |
| 27 | + |
| 28 | + return script; |
| 29 | + } |
| 30 | + ), |
| 31 | + run: jest.fn().mockImplementation( |
| 32 | + async (): Promise<string> => { |
| 33 | + let os_version: string = process.env['RUNNER_OS'] || ''; |
| 34 | + let version: string = process.env['php-version'] || ''; |
| 35 | + let script: string = ''; |
| 36 | + switch (os_version) { |
| 37 | + case 'darwin': |
| 38 | + case 'linux': |
| 39 | + script = await install.build(os_version + '.sh', version, os_version); |
| 40 | + script += 'sh script.sh ' + version + ' ' + __dirname; |
| 41 | + break; |
| 42 | + case 'win32': |
| 43 | + script = await install.build(os_version + '.sh', version, os_version); |
| 44 | + script += |
| 45 | + 'pwsh script.ps1 -version ' + version + ' -dir ' + __dirname; |
| 46 | + break; |
| 47 | + default: |
| 48 | + script += os_version + ' is not supported'; |
| 49 | + } |
| 50 | + |
| 51 | + return script; |
| 52 | + } |
| 53 | + ) |
| 54 | +})); |
| 55 | + |
| 56 | +/** |
| 57 | + * Function to set the process.env |
| 58 | + * |
| 59 | + * @param version |
| 60 | + * @param os |
| 61 | + * @param extension_csv |
| 62 | + * @param ini_values_csv |
| 63 | + * @param coverage_driver |
| 64 | + */ |
| 65 | +function setEnv( |
| 66 | + version: string, |
| 67 | + os: string, |
| 68 | + extension_csv: string, |
| 69 | + ini_values_csv: string, |
| 70 | + coverage_driver: string |
| 71 | +): void { |
| 72 | + process.env['php-version'] = version; |
| 73 | + process.env['RUNNER_OS'] = os; |
| 74 | + process.env['extension-csv'] = extension_csv; |
| 75 | + process.env['ini-values-csv'] = ini_values_csv; |
| 76 | + process.env['coverage'] = coverage_driver; |
| 77 | +} |
| 78 | + |
| 79 | +describe('Install', () => { |
| 80 | + it('Test install on windows', async () => { |
| 81 | + setEnv('7.3', 'win32', '', '', ''); |
| 82 | + // @ts-ignore |
| 83 | + let script: string = await install.run(); |
| 84 | + expect(script).toContain('initial script'); |
| 85 | + expect(script).toContain('pwsh script.ps1 -version 7.3 -dir ' + __dirname); |
| 86 | + |
| 87 | + setEnv('7.3', 'win32', 'a, b', 'a=b', 'x'); |
| 88 | + // @ts-ignore |
| 89 | + script = await install.run(); |
| 90 | + expect(script).toContain('initial script'); |
| 91 | + expect(script).toContain('install extensions'); |
| 92 | + expect(script).toContain('edit php.ini'); |
| 93 | + expect(script).toContain('set coverage driver'); |
| 94 | + expect(script).toContain('pwsh script.ps1 -version 7.3 -dir ' + __dirname); |
| 95 | + }); |
| 96 | + |
| 97 | + it('Test install on linux', async () => { |
| 98 | + setEnv('7.3', 'linux', '', '', ''); |
| 99 | + // @ts-ignore |
| 100 | + let script: string = await install.run(); |
| 101 | + expect(script).toContain('initial script'); |
| 102 | + expect(script).toContain('sh script.sh 7.3 ' + __dirname); |
| 103 | + |
| 104 | + setEnv('7.3', 'linux', 'a, b', 'a=b', 'x'); |
| 105 | + // @ts-ignore |
| 106 | + script = await install.run(); |
| 107 | + expect(script).toContain('initial script'); |
| 108 | + expect(script).toContain('install extensions'); |
| 109 | + expect(script).toContain('edit php.ini'); |
| 110 | + expect(script).toContain('set coverage driver'); |
| 111 | + expect(script).toContain('sh script.sh 7.3 ' + __dirname); |
| 112 | + }); |
| 113 | + |
| 114 | + it('Test install on darwin', async () => { |
| 115 | + setEnv('7.3', 'darwin', '', '', ''); |
| 116 | + // @ts-ignore |
| 117 | + let script: string = await install.run(); |
| 118 | + expect(script).toContain('initial script'); |
| 119 | + expect(script).toContain('sh script.sh 7.3 ' + __dirname); |
| 120 | + |
| 121 | + setEnv('7.3', 'darwin', 'a, b', 'a=b', 'x'); |
| 122 | + // @ts-ignore |
| 123 | + script = await install.run(); |
| 124 | + expect(script).toContain('initial script'); |
| 125 | + expect(script).toContain('install extensions'); |
| 126 | + expect(script).toContain('edit php.ini'); |
| 127 | + expect(script).toContain('set coverage driver'); |
| 128 | + expect(script).toContain('sh script.sh 7.3 ' + __dirname); |
| 129 | + }); |
| 130 | +}); |
0 commit comments