| 
									
										
										
										
											2024-11-04 08:55:26 +05:30
										 |  |  | import fs from 'fs'; | 
					
						
							| 
									
										
										
										
											2019-09-20 08:11:20 +05:30
										 |  |  | import * as path from 'path'; | 
					
						
							|  |  |  | import * as utils from '../src/utils'; | 
					
						
							| 
									
										
										
										
											2025-05-19 08:09:13 +05:30
										 |  |  | import * as fetchModule from '../src/fetch'; | 
					
						
							| 
									
										
										
										
											2019-09-20 08:11:20 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-05 11:41:01 +05:30
										 |  |  | /** | 
					
						
							|  |  |  |  * Mock @actions/core | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-09-26 02:33:39 +05:30
										 |  |  | jest.mock('@actions/core', () => ({ | 
					
						
							|  |  |  |   getInput: jest.fn().mockImplementation(key => { | 
					
						
							|  |  |  |     return ['setup-php'].indexOf(key) !== -1 ? key : ''; | 
					
						
							| 
									
										
										
										
											2023-01-29 13:26:49 +08:00
										 |  |  |   }), | 
					
						
							|  |  |  |   info: jest.fn() | 
					
						
							| 
									
										
										
										
											2019-09-26 02:33:39 +05:30
										 |  |  | })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-20 08:11:20 +05:30
										 |  |  | describe('Utils tests', () => { | 
					
						
							| 
									
										
										
										
											2020-10-03 01:39:43 +05:30
										 |  |  |   it('checking readEnv', async () => { | 
					
						
							|  |  |  |     process.env['test'] = 'setup-php'; | 
					
						
							| 
									
										
										
										
											2021-07-23 16:19:00 +05:30
										 |  |  |     process.env['test-hyphen'] = 'setup-php'; | 
					
						
							| 
									
										
										
										
											2020-10-03 01:39:43 +05:30
										 |  |  |     expect(await utils.readEnv('test')).toBe('setup-php'); | 
					
						
							| 
									
										
										
										
											2021-07-23 16:19:00 +05:30
										 |  |  |     expect(await utils.readEnv('TEST')).toBe('setup-php'); | 
					
						
							|  |  |  |     expect(await utils.readEnv('test_hyphen')).toBe('setup-php'); | 
					
						
							|  |  |  |     expect(await utils.readEnv('TEST_HYPHEN')).toBe('setup-php'); | 
					
						
							| 
									
										
										
										
											2020-10-03 01:39:43 +05:30
										 |  |  |     expect(await utils.readEnv('undefined')).toBe(''); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-20 08:11:20 +05:30
										 |  |  |   it('checking getInput', async () => { | 
					
						
							|  |  |  |     process.env['test'] = 'setup-php'; | 
					
						
							|  |  |  |     expect(await utils.getInput('test', false)).toBe('setup-php'); | 
					
						
							| 
									
										
										
										
											2019-09-26 02:33:39 +05:30
										 |  |  |     expect(await utils.getInput('setup-php', false)).toBe('setup-php'); | 
					
						
							| 
									
										
										
										
											2019-09-20 08:11:20 +05:30
										 |  |  |     expect(await utils.getInput('DoesNotExist', false)).toBe(''); | 
					
						
							| 
									
										
										
										
											2021-07-05 16:03:10 +05:30
										 |  |  |     await expect(async () => { | 
					
						
							| 
									
										
										
										
											2020-10-03 01:39:43 +05:30
										 |  |  |       await utils.getInput('DoesNotExist', true); | 
					
						
							|  |  |  |     }).rejects.toThrow('Input required and not supplied: DoesNotExist'); | 
					
						
							| 
									
										
										
										
											2019-09-20 08:11:20 +05:30
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-09 11:26:38 +05:30
										 |  |  |   it('checking getManifestURL', async () => { | 
					
						
							| 
									
										
										
										
											2025-05-19 08:09:13 +05:30
										 |  |  |     for (const url of await utils.getManifestURLS()) { | 
					
						
							|  |  |  |       expect(url).toContain('php-versions.json'); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-01-16 11:16:13 +05:30
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-02 14:51:40 +05:30
										 |  |  |   it('checking parseVersion', async () => { | 
					
						
							| 
									
										
										
										
											2025-05-19 08:09:13 +05:30
										 |  |  |     const fetchSpy = jest | 
					
						
							|  |  |  |       .spyOn(fetchModule, 'fetch') | 
					
						
							|  |  |  |       .mockResolvedValue({data: '{ "latest": "8.1", "5.x": "5.6" }'}); | 
					
						
							| 
									
										
										
										
											2021-11-25 17:34:13 +05:30
										 |  |  |     expect(await utils.parseVersion('latest')).toBe('8.1'); | 
					
						
							| 
									
										
										
										
											2020-10-02 14:51:40 +05:30
										 |  |  |     expect(await utils.parseVersion('7')).toBe('7.0'); | 
					
						
							|  |  |  |     expect(await utils.parseVersion('7.4')).toBe('7.4'); | 
					
						
							| 
									
										
										
										
											2021-01-16 11:16:13 +05:30
										 |  |  |     expect(await utils.parseVersion('5.x')).toBe('5.6'); | 
					
						
							|  |  |  |     expect(await utils.parseVersion('4.x')).toBe(undefined); | 
					
						
							| 
									
										
										
										
											2025-05-19 08:09:13 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |     fetchSpy.mockReset(); | 
					
						
							|  |  |  |     fetchSpy.mockResolvedValueOnce({}).mockResolvedValueOnce({}); | 
					
						
							|  |  |  |     await expect(utils.parseVersion('latest')).rejects.toThrow( | 
					
						
							|  |  |  |       'Could not fetch the PHP version manifest.' | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     expect(fetchSpy).toHaveBeenCalledTimes(2); | 
					
						
							| 
									
										
										
										
											2020-10-02 14:51:40 +05:30
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-25 13:43:49 +05:30
										 |  |  |   it('checking parseIniFile', async () => { | 
					
						
							|  |  |  |     expect(await utils.parseIniFile('production')).toBe('production'); | 
					
						
							|  |  |  |     expect(await utils.parseIniFile('development')).toBe('development'); | 
					
						
							|  |  |  |     expect(await utils.parseIniFile('none')).toBe('none'); | 
					
						
							|  |  |  |     expect(await utils.parseIniFile('php.ini-production')).toBe('production'); | 
					
						
							|  |  |  |     expect(await utils.parseIniFile('php.ini-development')).toBe('development'); | 
					
						
							|  |  |  |     expect(await utils.parseIniFile('invalid')).toBe('production'); | 
					
						
							| 
									
										
										
										
											2022-01-29 05:29:58 +05:30
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2022-01-25 13:43:49 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-20 08:11:20 +05:30
										 |  |  |   it('checking asyncForEach', async () => { | 
					
						
							| 
									
										
										
										
											2019-11-24 02:04:12 +05:30
										 |  |  |     const array: Array<string> = ['a', 'b', 'c']; | 
					
						
							|  |  |  |     let concat = ''; | 
					
						
							| 
									
										
										
										
											2020-11-27 00:06:27 +05:30
										 |  |  |     await utils.asyncForEach( | 
					
						
							|  |  |  |       array, | 
					
						
							|  |  |  |       async function (str: string): Promise<void> { | 
					
						
							|  |  |  |         concat += str; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2019-11-24 02:04:12 +05:30
										 |  |  |     expect(concat).toBe('abc'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('checking asyncForEach', async () => { | 
					
						
							|  |  |  |     expect(await utils.color('error')).toBe('31'); | 
					
						
							|  |  |  |     expect(await utils.color('success')).toBe('32'); | 
					
						
							|  |  |  |     expect(await utils.color('any')).toBe('32'); | 
					
						
							|  |  |  |     expect(await utils.color('warning')).toBe('33'); | 
					
						
							| 
									
										
										
										
											2019-09-20 08:11:20 +05:30
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('checking extensionArray', async () => { | 
					
						
							| 
									
										
										
										
											2021-08-25 20:09:50 +05:30
										 |  |  |     expect( | 
					
						
							| 
									
										
										
										
											2021-08-26 21:29:38 +05:30
										 |  |  |       await utils.extensionArray('a, :b, php_c, none, php-d, Zend e, :Zend f') | 
					
						
							|  |  |  |     ).toEqual(['none', 'a', ':b', 'c', 'd', 'e', ':f']); | 
					
						
							| 
									
										
										
										
											2019-10-08 18:12:54 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-28 20:09:05 +05:30
										 |  |  |     expect(await utils.extensionArray('')).toEqual([]); | 
					
						
							|  |  |  |     expect(await utils.extensionArray(' ')).toEqual([]); | 
					
						
							| 
									
										
										
										
											2019-09-20 08:11:20 +05:30
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('checking INIArray', async () => { | 
					
						
							| 
									
										
										
										
											2019-12-27 06:56:49 +05:30
										 |  |  |     expect(await utils.CSVArray('a=1, b=2, c=3')).toEqual([ | 
					
						
							| 
									
										
										
										
											2019-09-20 08:11:20 +05:30
										 |  |  |       'a=1', | 
					
						
							|  |  |  |       'b=2', | 
					
						
							|  |  |  |       'c=3' | 
					
						
							|  |  |  |     ]); | 
					
						
							| 
									
										
										
										
											2021-01-15 13:52:18 +05:30
										 |  |  |     expect(await utils.CSVArray('\'a=1,2\', "b=3, 4", c=5, d=~e~')).toEqual([ | 
					
						
							|  |  |  |       'a=1,2', | 
					
						
							|  |  |  |       'b=3, 4', | 
					
						
							|  |  |  |       'c=5', | 
					
						
							|  |  |  |       "d='~e~'" | 
					
						
							|  |  |  |     ]); | 
					
						
							|  |  |  |     expect(await utils.CSVArray('a=\'1,2\', b="3, 4", c=5')).toEqual([ | 
					
						
							|  |  |  |       'a=1,2', | 
					
						
							|  |  |  |       'b=3, 4', | 
					
						
							|  |  |  |       'c=5' | 
					
						
							|  |  |  |     ]); | 
					
						
							| 
									
										
										
										
											2021-02-04 13:01:05 +05:30
										 |  |  |     expect( | 
					
						
							|  |  |  |       await utils.CSVArray('a=E_ALL, b=E_ALL & ~ E_ALL, c="E_ALL", d=\'E_ALL\'') | 
					
						
							|  |  |  |     ).toEqual(['a=E_ALL', 'b=E_ALL & ~ E_ALL', 'c=E_ALL', 'd=E_ALL']); | 
					
						
							| 
									
										
										
										
											2022-12-15 05:27:13 +05:30
										 |  |  |     expect( | 
					
						
							|  |  |  |       await utils.CSVArray('a="b=c;d=e", b=\'c=d,e\', c="g=h,i=j", d=g=h, a===') | 
					
						
							|  |  |  |     ).toEqual(["a='b=c;d=e'", "b='c=d,e'", "c='g=h,i=j'", "d='g=h'", "a='=='"]); | 
					
						
							| 
									
										
										
										
											2019-12-27 06:56:49 +05:30
										 |  |  |     expect(await utils.CSVArray('')).toEqual([]); | 
					
						
							|  |  |  |     expect(await utils.CSVArray(' ')).toEqual([]); | 
					
						
							| 
									
										
										
										
											2019-09-20 08:11:20 +05:30
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-26 02:33:39 +05:30
										 |  |  |   it('checking log', async () => { | 
					
						
							| 
									
										
										
										
											2019-11-24 02:04:12 +05:30
										 |  |  |     const message = 'Test message'; | 
					
						
							| 
									
										
										
										
											2019-09-26 02:33:39 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |     let warning_log: string = await utils.log(message, 'win32', 'warning'); | 
					
						
							| 
									
										
										
										
											2019-10-17 01:41:13 +05:30
										 |  |  |     expect(warning_log).toEqual('printf "\\033[33;1m' + message + ' \\033[0m"'); | 
					
						
							| 
									
										
										
										
											2019-09-26 02:33:39 +05:30
										 |  |  |     warning_log = await utils.log(message, 'linux', 'warning'); | 
					
						
							| 
									
										
										
										
											2019-09-28 03:06:41 +05:30
										 |  |  |     expect(warning_log).toEqual('echo "\\033[33;1m' + message + '\\033[0m"'); | 
					
						
							| 
									
										
										
										
											2019-09-26 02:33:39 +05:30
										 |  |  |     warning_log = await utils.log(message, 'darwin', 'warning'); | 
					
						
							| 
									
										
										
										
											2019-09-28 20:09:05 +05:30
										 |  |  |     expect(warning_log).toEqual('echo "\\033[33;1m' + message + '\\033[0m"'); | 
					
						
							| 
									
										
										
										
											2019-09-26 02:33:39 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |     let error_log: string = await utils.log(message, 'win32', 'error'); | 
					
						
							| 
									
										
										
										
											2019-10-17 01:41:13 +05:30
										 |  |  |     expect(error_log).toEqual('printf "\\033[31;1m' + message + ' \\033[0m"'); | 
					
						
							| 
									
										
										
										
											2019-09-26 02:33:39 +05:30
										 |  |  |     error_log = await utils.log(message, 'linux', 'error'); | 
					
						
							| 
									
										
										
										
											2019-09-28 03:06:41 +05:30
										 |  |  |     expect(error_log).toEqual('echo "\\033[31;1m' + message + '\\033[0m"'); | 
					
						
							| 
									
										
										
										
											2019-09-26 02:33:39 +05:30
										 |  |  |     error_log = await utils.log(message, 'darwin', 'error'); | 
					
						
							| 
									
										
										
										
											2019-09-28 20:09:05 +05:30
										 |  |  |     expect(error_log).toEqual('echo "\\033[31;1m' + message + '\\033[0m"'); | 
					
						
							| 
									
										
										
										
											2019-09-26 02:33:39 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |     let success_log: string = await utils.log(message, 'win32', 'success'); | 
					
						
							| 
									
										
										
										
											2019-10-17 01:41:13 +05:30
										 |  |  |     expect(success_log).toEqual('printf "\\033[32;1m' + message + ' \\033[0m"'); | 
					
						
							| 
									
										
										
										
											2019-09-26 02:33:39 +05:30
										 |  |  |     success_log = await utils.log(message, 'linux', 'success'); | 
					
						
							| 
									
										
										
										
											2019-09-28 03:06:41 +05:30
										 |  |  |     expect(success_log).toEqual('echo "\\033[32;1m' + message + '\\033[0m"'); | 
					
						
							| 
									
										
										
										
											2019-09-26 02:33:39 +05:30
										 |  |  |     success_log = await utils.log(message, 'darwin', 'success'); | 
					
						
							| 
									
										
										
										
											2019-09-28 20:09:05 +05:30
										 |  |  |     expect(success_log).toEqual('echo "\\033[32;1m' + message + '\\033[0m"'); | 
					
						
							| 
									
										
										
										
											2019-10-04 19:34:05 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-17 01:41:13 +05:30
										 |  |  |     let step_log: string = await utils.stepLog(message, 'win32'); | 
					
						
							|  |  |  |     expect(step_log).toEqual('Step-Log "Test message"'); | 
					
						
							|  |  |  |     step_log = await utils.stepLog(message, 'linux'); | 
					
						
							|  |  |  |     expect(step_log).toEqual('step_log "Test message"'); | 
					
						
							|  |  |  |     step_log = await utils.stepLog(message, 'darwin'); | 
					
						
							|  |  |  |     expect(step_log).toEqual('step_log "Test message"'); | 
					
						
							| 
									
										
										
										
											2020-08-19 08:00:36 +05:30
										 |  |  |     step_log = await utils.stepLog(message, 'openbsd'); | 
					
						
							|  |  |  |     expect(step_log).toContain('Platform openbsd is not supported'); | 
					
						
							| 
									
										
										
										
											2019-10-17 01:41:13 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |     let add_log: string = await utils.addLog( | 
					
						
							|  |  |  |       'tick', | 
					
						
							|  |  |  |       'xdebug', | 
					
						
							|  |  |  |       'enabled', | 
					
						
							|  |  |  |       'win32' | 
					
						
							| 
									
										
										
										
											2019-10-04 19:34:05 +05:30
										 |  |  |     ); | 
					
						
							| 
									
										
										
										
											2019-10-17 01:41:13 +05:30
										 |  |  |     expect(add_log).toEqual('Add-Log "tick" "xdebug" "enabled"'); | 
					
						
							|  |  |  |     add_log = await utils.addLog('tick', 'xdebug', 'enabled', 'linux'); | 
					
						
							|  |  |  |     expect(add_log).toEqual('add_log "tick" "xdebug" "enabled"'); | 
					
						
							|  |  |  |     add_log = await utils.addLog('tick', 'xdebug', 'enabled', 'darwin'); | 
					
						
							|  |  |  |     expect(add_log).toEqual('add_log "tick" "xdebug" "enabled"'); | 
					
						
							| 
									
										
										
										
											2020-08-19 08:00:36 +05:30
										 |  |  |     add_log = await utils.addLog('tick', 'xdebug', 'enabled', 'openbsd'); | 
					
						
							|  |  |  |     expect(add_log).toContain('Platform openbsd is not supported'); | 
					
						
							| 
									
										
										
										
											2019-09-26 02:33:39 +05:30
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-28 08:49:11 +05:30
										 |  |  |   it('checking getExtensionPrefix', async () => { | 
					
						
							|  |  |  |     expect(await utils.getExtensionPrefix('extensionDoesNotExist')).toEqual( | 
					
						
							|  |  |  |       'extension' | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     expect(await utils.getExtensionPrefix('xsl')).toEqual('extension'); | 
					
						
							|  |  |  |     expect(await utils.getExtensionPrefix('xdebug')).toEqual('zend_extension'); | 
					
						
							| 
									
										
										
										
											2020-06-20 06:25:19 +05:30
										 |  |  |     expect(await utils.getExtensionPrefix('xdebug3')).toEqual('zend_extension'); | 
					
						
							| 
									
										
										
										
											2019-09-28 08:49:11 +05:30
										 |  |  |     expect(await utils.getExtensionPrefix('opcache')).toEqual('zend_extension'); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2019-10-17 01:41:13 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |   it('checking suppressOutput', async () => { | 
					
						
							|  |  |  |     expect(await utils.suppressOutput('win32')).toEqual(' >$null 2>&1'); | 
					
						
							|  |  |  |     expect(await utils.suppressOutput('linux')).toEqual(' >/dev/null 2>&1'); | 
					
						
							|  |  |  |     expect(await utils.suppressOutput('darwin')).toEqual(' >/dev/null 2>&1'); | 
					
						
							| 
									
										
										
										
											2020-08-19 08:00:36 +05:30
										 |  |  |     expect(await utils.suppressOutput('openbsd')).toContain( | 
					
						
							|  |  |  |       'Platform openbsd is not supported' | 
					
						
							| 
									
										
										
										
											2019-10-17 01:41:13 +05:30
										 |  |  |     ); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-07-24 10:28:48 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |   it('checking getUnsupportedLog', async () => { | 
					
						
							|  |  |  |     expect(await utils.getUnsupportedLog('ext', '5.6', 'linux')).toContain( | 
					
						
							|  |  |  |       'add_log "$cross" "ext" "ext is not supported on PHP 5.6"' | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-06 15:33:58 +05:30
										 |  |  |   it('checking getCommand', async () => { | 
					
						
							|  |  |  |     expect(await utils.getCommand('linux', 'tool')).toBe('add_tool '); | 
					
						
							|  |  |  |     expect(await utils.getCommand('darwin', 'tool')).toBe('add_tool '); | 
					
						
							|  |  |  |     expect(await utils.getCommand('win32', 'tool')).toBe('Add-Tool '); | 
					
						
							| 
									
										
										
										
											2023-01-18 09:00:28 +05:30
										 |  |  |     expect(await utils.getCommand('win32', 'tool_name')).toBe('Add-ToolName '); | 
					
						
							| 
									
										
										
										
											2020-08-19 08:00:36 +05:30
										 |  |  |     expect(await utils.getCommand('openbsd', 'tool')).toContain( | 
					
						
							|  |  |  |       'Platform openbsd is not supported' | 
					
						
							| 
									
										
										
										
											2020-08-06 15:33:58 +05:30
										 |  |  |     ); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-24 10:28:48 +05:30
										 |  |  |   it('checking joins', async () => { | 
					
						
							|  |  |  |     expect(await utils.joins('a', 'b', 'c')).toBe('a b c'); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-07-31 20:43:06 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |   it('checking scriptExtension', async () => { | 
					
						
							|  |  |  |     expect(await utils.scriptExtension('linux')).toBe('.sh'); | 
					
						
							|  |  |  |     expect(await utils.scriptExtension('darwin')).toBe('.sh'); | 
					
						
							|  |  |  |     expect(await utils.scriptExtension('win32')).toBe('.ps1'); | 
					
						
							| 
									
										
										
										
											2020-08-19 08:00:36 +05:30
										 |  |  |     expect(await utils.scriptExtension('openbsd')).toContain( | 
					
						
							|  |  |  |       'Platform openbsd is not supported' | 
					
						
							| 
									
										
										
										
											2020-07-31 20:43:06 +05:30
										 |  |  |     ); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-08-06 15:33:58 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-04 17:03:02 +05:30
										 |  |  |   it('checking scriptTool', async () => { | 
					
						
							| 
									
										
										
										
											2022-01-30 08:45:11 +05:30
										 |  |  |     expect(await utils.scriptTool('linux')).toBe('bash '); | 
					
						
							|  |  |  |     expect(await utils.scriptTool('darwin')).toBe('bash '); | 
					
						
							|  |  |  |     expect(await utils.scriptTool('win32')).toBe('pwsh '); | 
					
						
							| 
									
										
										
										
											2020-10-04 17:03:02 +05:30
										 |  |  |     expect(await utils.scriptTool('openbsd')).toContain( | 
					
						
							|  |  |  |       'Platform openbsd is not supported' | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-06 15:33:58 +05:30
										 |  |  |   it('checking customPackage', async () => { | 
					
						
							|  |  |  |     const script_path: string = path.join('ext', 'pkg.sh'); | 
					
						
							|  |  |  |     expect(await utils.customPackage('pkg', 'ext', '1.2.3', 'linux')).toContain( | 
					
						
							|  |  |  |       script_path + '\nadd_pkg 1.2.3' | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     expect( | 
					
						
							|  |  |  |       await utils.customPackage('pdo_pkg', 'ext', '1.2.3', 'linux') | 
					
						
							|  |  |  |     ).toContain(script_path + '\nadd_pkg 1.2.3'); | 
					
						
							|  |  |  |     expect( | 
					
						
							|  |  |  |       await utils.customPackage('pkg8', 'ext', '1.2.3', 'linux') | 
					
						
							|  |  |  |     ).toContain(script_path + '\nadd_pkg 1.2.3'); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-03-17 04:48:19 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |   it('checking parseExtensionSource', async () => { | 
					
						
							|  |  |  |     expect( | 
					
						
							|  |  |  |       await utils.parseExtensionSource( | 
					
						
							|  |  |  |         'ext-org-name/repo-name@release', | 
					
						
							|  |  |  |         'extension' | 
					
						
							|  |  |  |       ) | 
					
						
							|  |  |  |     ).toContain( | 
					
						
							| 
									
										
										
										
											2021-04-19 17:03:57 +05:30
										 |  |  |       '\nadd_extension_from_source ext https://github.com org-name repo-name release extension' | 
					
						
							| 
									
										
										
										
											2021-03-17 04:48:19 +05:30
										 |  |  |     ); | 
					
						
							|  |  |  |     expect( | 
					
						
							|  |  |  |       await utils.parseExtensionSource( | 
					
						
							|  |  |  |         'ext-https://sub.domain.tld/org/repo@release', | 
					
						
							|  |  |  |         'extension' | 
					
						
							|  |  |  |       ) | 
					
						
							|  |  |  |     ).toContain( | 
					
						
							| 
									
										
										
										
											2021-04-19 17:03:57 +05:30
										 |  |  |       '\nadd_extension_from_source ext https://sub.domain.tld org repo release extension' | 
					
						
							| 
									
										
										
										
											2021-03-17 04:48:19 +05:30
										 |  |  |     ); | 
					
						
							|  |  |  |     expect( | 
					
						
							|  |  |  |       await utils.parseExtensionSource( | 
					
						
							| 
									
										
										
										
											2021-04-19 17:03:57 +05:30
										 |  |  |         'ext-https://sub.domain.XN--tld/org/repo@release', | 
					
						
							| 
									
										
										
										
											2021-03-17 04:48:19 +05:30
										 |  |  |         'extension' | 
					
						
							|  |  |  |       ) | 
					
						
							|  |  |  |     ).toContain( | 
					
						
							| 
									
										
										
										
											2021-04-19 17:03:57 +05:30
										 |  |  |       '\nadd_extension_from_source ext https://sub.domain.XN--tld org repo release extension' | 
					
						
							| 
									
										
										
										
											2021-03-17 04:48:19 +05:30
										 |  |  |     ); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2022-06-30 17:36:40 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-02 20:30:40 +05:30
										 |  |  |   it('checking readPHPVersion', async () => { | 
					
						
							|  |  |  |     expect(await utils.readPHPVersion()).toBe('latest'); | 
					
						
							| 
									
										
										
										
											2023-01-29 13:26:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     process.env['php-version-file'] = '.phpenv-version'; | 
					
						
							| 
									
										
										
										
											2023-04-02 20:30:40 +05:30
										 |  |  |     await expect(utils.readPHPVersion()).rejects.toThrow( | 
					
						
							| 
									
										
										
										
											2023-01-29 13:26:49 +08:00
										 |  |  |       "Could not find '.phpenv-version' file." | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const existsSync = jest.spyOn(fs, 'existsSync').mockImplementation(); | 
					
						
							|  |  |  |     const readFileSync = jest.spyOn(fs, 'readFileSync').mockImplementation(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     existsSync.mockReturnValue(true); | 
					
						
							|  |  |  |     readFileSync.mockReturnValue('8.1'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-02 20:30:40 +05:30
										 |  |  |     expect(await utils.readPHPVersion()).toBe('8.1'); | 
					
						
							| 
									
										
										
										
											2023-01-29 13:26:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     process.env['php-version'] = '8.2'; | 
					
						
							| 
									
										
										
										
											2023-04-02 20:30:40 +05:30
										 |  |  |     expect(await utils.readPHPVersion()).toBe('8.2'); | 
					
						
							| 
									
										
										
										
											2023-01-29 13:26:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-29 19:46:06 -04:00
										 |  |  |     delete process.env['php-version-file']; | 
					
						
							|  |  |  |     delete process.env['php-version']; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-23 15:27:22 +05:30
										 |  |  |     existsSync.mockReturnValue(true); | 
					
						
							|  |  |  |     readFileSync.mockReturnValue('ruby 1.2.3\nphp 8.4.2\nnode 20.1.2'); | 
					
						
							|  |  |  |     expect(await utils.readPHPVersion()).toBe('8.4.2'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     existsSync.mockReturnValue(true); | 
					
						
							|  |  |  |     readFileSync.mockReturnValue('setup-php'); | 
					
						
							|  |  |  |     expect(await utils.readPHPVersion()).toBe('setup-php'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-29 19:46:06 -04:00
										 |  |  |     existsSync.mockReturnValueOnce(false).mockReturnValueOnce(true); | 
					
						
							|  |  |  |     readFileSync.mockReturnValue( | 
					
						
							|  |  |  |       '{ "platform-overrides": { "php": "7.3.25" } }' | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     expect(await utils.readPHPVersion()).toBe('7.3.25'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     existsSync | 
					
						
							|  |  |  |       .mockReturnValueOnce(false) | 
					
						
							|  |  |  |       .mockReturnValueOnce(false) | 
					
						
							|  |  |  |       .mockReturnValueOnce(true); | 
					
						
							|  |  |  |     readFileSync.mockReturnValue( | 
					
						
							|  |  |  |       '{ "config": { "platform": { "php": "7.4.33" } } }' | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     expect(await utils.readPHPVersion()).toBe('7.4.33'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-29 13:26:49 +08:00
										 |  |  |     existsSync.mockClear(); | 
					
						
							|  |  |  |     readFileSync.mockClear(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-30 17:36:40 +05:30
										 |  |  |   it('checking setVariable', async () => { | 
					
						
							|  |  |  |     let script: string = await utils.setVariable('var', 'command', 'linux'); | 
					
						
							|  |  |  |     expect(script).toEqual('\nvar="$(command)"\n'); | 
					
						
							|  |  |  |     script = await utils.setVariable('var', 'command', 'darwin'); | 
					
						
							|  |  |  |     expect(script).toEqual('\nvar="$(command)"\n'); | 
					
						
							|  |  |  |     script = await utils.setVariable('var', 'command', 'win32'); | 
					
						
							|  |  |  |     expect(script).toEqual('\n$var = command\n'); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2019-09-28 08:49:11 +05:30
										 |  |  | }); |