2019-09-20 09:41:20 +07:00
|
|
|
import * as features from '../src/features';
|
|
|
|
|
|
|
|
let valid_extensions = ['xdebug', 'pcov'];
|
|
|
|
jest.mock('../src/pecl', () => ({
|
|
|
|
checkPECLExtension: jest.fn().mockImplementation(extension => {
|
|
|
|
return valid_extensions.indexOf(extension) !== -1;
|
|
|
|
})
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('Features tests', () => {
|
|
|
|
it('checking addExtensionOnWindows', async () => {
|
|
|
|
let win32: string = await features.addExtension(
|
|
|
|
'xdebug, pcov',
|
|
|
|
'7.2',
|
|
|
|
'win32'
|
|
|
|
);
|
2019-09-28 21:39:05 +07:00
|
|
|
expect(win32).toContain('Install-PhpExtension xdebug');
|
|
|
|
expect(win32).toContain('Install-PhpExtension pcov');
|
2019-09-20 09:41:20 +07:00
|
|
|
win32 = await features.addExtension('xdebug, pcov', '7.4', 'win32');
|
2019-09-28 21:39:05 +07:00
|
|
|
const extension_url: string =
|
|
|
|
'https://xdebug.org/files/php_xdebug-2.8.0beta2-7.4-vc15.dll';
|
2019-09-20 09:41:20 +07:00
|
|
|
expect(win32).toContain(
|
2019-09-28 21:39:05 +07:00
|
|
|
'Invoke-WebRequest -Uri ' +
|
|
|
|
extension_url +
|
|
|
|
' -OutFile C:\\tools\\php\\ext\\php_xdebug.dll'
|
2019-09-20 09:41:20 +07:00
|
|
|
);
|
2019-09-28 21:39:05 +07:00
|
|
|
expect(win32).toContain('Install-PhpExtension pcov');
|
2019-09-20 09:41:20 +07:00
|
|
|
|
2019-09-26 04:03:39 +07:00
|
|
|
win32 = await features.addExtension('does_not_exist', '7.2', 'win32');
|
2019-09-28 04:36:41 +07:00
|
|
|
expect(win32).toContain('Could not find does_not_exist for PHP7.2 on PECL');
|
2019-09-26 04:03:39 +07:00
|
|
|
|
|
|
|
win32 = await features.addExtension('xdebug', '7.2', 'fedora');
|
|
|
|
expect(win32).toContain('Platform fedora is not supported');
|
2019-09-20 09:41:20 +07:00
|
|
|
});
|
2019-09-26 04:03:39 +07:00
|
|
|
|
2019-09-20 09:41:20 +07:00
|
|
|
it('checking addExtensionOnLinux', async () => {
|
|
|
|
let linux: string = await features.addExtension(
|
|
|
|
'xdebug, pcov',
|
|
|
|
'7.2',
|
|
|
|
'linux'
|
|
|
|
);
|
|
|
|
expect(linux).toContain(
|
|
|
|
'sudo DEBIAN_FRONTEND=noninteractive apt install -y php7.2-xdebug'
|
|
|
|
);
|
|
|
|
expect(linux).toContain(
|
|
|
|
'sudo DEBIAN_FRONTEND=noninteractive apt install -y php7.2-pcov'
|
|
|
|
);
|
2019-09-26 04:03:39 +07:00
|
|
|
|
2019-09-28 21:39:05 +07:00
|
|
|
linux = await features.addExtension('xdebug, pcov', '7.4', 'linux');
|
|
|
|
expect(linux).toContain('./xdebug.sh');
|
|
|
|
expect(linux).toContain('./pcov.sh');
|
|
|
|
|
2019-09-26 04:03:39 +07:00
|
|
|
linux = await features.addExtension('xdebug', '7.2', 'fedora');
|
|
|
|
expect(linux).toContain('Platform fedora is not supported');
|
2019-09-20 09:41:20 +07:00
|
|
|
});
|
2019-09-26 04:03:39 +07:00
|
|
|
|
2019-09-20 09:41:20 +07:00
|
|
|
it('checking addExtensionOnDarwin', async () => {
|
|
|
|
let darwin: string = await features.addExtension(
|
|
|
|
'xdebug, pcov',
|
|
|
|
'7.2',
|
|
|
|
'darwin'
|
|
|
|
);
|
|
|
|
expect(darwin).toContain('sudo pecl install xdebug');
|
|
|
|
expect(darwin).toContain('sudo pecl install pcov');
|
|
|
|
|
2019-09-28 10:19:11 +07:00
|
|
|
darwin = await features.addExtension('pcov', '5.6', 'darwin');
|
|
|
|
expect(darwin).toContain('sudo pecl install pcov');
|
|
|
|
|
|
|
|
darwin = await features.addExtension('pcov', '7.2', 'darwin');
|
|
|
|
expect(darwin).toContain('sudo pecl install pcov');
|
|
|
|
|
2019-09-26 04:03:39 +07:00
|
|
|
darwin = await features.addExtension('xdebug', '5.6', 'darwin');
|
|
|
|
expect(darwin).toContain('sudo pecl install xdebug-2.5.5');
|
|
|
|
|
2019-09-28 21:39:05 +07:00
|
|
|
darwin = await features.addExtension('xdebug', '7.4', 'darwin');
|
|
|
|
expect(darwin).toContain('sh ./xdebug_darwin.sh');
|
|
|
|
|
|
|
|
darwin = await features.addExtension('pcov', '7.4', 'darwin');
|
|
|
|
expect(darwin).toContain('sh ./pcov.sh');
|
|
|
|
|
2019-09-28 10:19:11 +07:00
|
|
|
darwin = await features.addExtension('xdebug', '7.2', 'darwin');
|
|
|
|
expect(darwin).toContain('sudo pecl install xdebug');
|
|
|
|
|
2019-09-26 04:03:39 +07:00
|
|
|
darwin = await features.addExtension('does_not_exist', '7.2', 'darwin');
|
2019-09-28 04:36:41 +07:00
|
|
|
expect(darwin).toContain(
|
|
|
|
'Could not find does_not_exist for PHP7.2 on PECL'
|
|
|
|
);
|
2019-09-26 04:03:39 +07:00
|
|
|
|
|
|
|
darwin = await features.addExtension('xdebug', '7.2', 'fedora');
|
|
|
|
expect(darwin).toContain('Platform fedora is not supported');
|
2019-09-20 09:41:20 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
it('checking addINIValuesOnWindows', async () => {
|
|
|
|
let win32: string = await features.addINIValues(
|
|
|
|
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
|
|
|
|
'win32'
|
|
|
|
);
|
|
|
|
expect(win32).toContain(
|
2019-09-21 23:06:03 +07:00
|
|
|
'Add-Content C:\\tools\\php\\php.ini "post_max_size=256M"'
|
2019-09-20 09:41:20 +07:00
|
|
|
);
|
|
|
|
expect(win32).toContain(
|
2019-09-21 23:06:03 +07:00
|
|
|
'Add-Content C:\\tools\\php\\php.ini "short_open_tag=On"'
|
2019-09-20 09:41:20 +07:00
|
|
|
);
|
|
|
|
expect(win32).toContain(
|
2019-09-21 23:06:03 +07:00
|
|
|
'Add-Content C:\\tools\\php\\php.ini "date.timezone=Asia/Kolkata"'
|
2019-09-20 09:41:20 +07:00
|
|
|
);
|
2019-09-26 04:03:39 +07:00
|
|
|
|
|
|
|
win32 = await features.addINIValues(
|
|
|
|
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
|
|
|
|
'fedora'
|
|
|
|
);
|
|
|
|
expect(win32).toContain('Platform fedora is not supported');
|
2019-09-20 09:41:20 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
it('checking addINIValuesOnLinux', async () => {
|
|
|
|
let linux: string = await features.addINIValues(
|
|
|
|
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
|
|
|
|
'linux'
|
|
|
|
);
|
|
|
|
expect(linux).toContain('echo "post_max_size=256M" >> $ini_file');
|
|
|
|
expect(linux).toContain('echo "short_open_tag=On" >> $ini_file');
|
|
|
|
expect(linux).toContain('echo "date.timezone=Asia/Kolkata" >> $ini_file');
|
2019-09-26 04:03:39 +07:00
|
|
|
|
|
|
|
linux = await features.addINIValues(
|
|
|
|
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
|
|
|
|
'fedora'
|
|
|
|
);
|
|
|
|
expect(linux).toContain('Platform fedora is not supported');
|
2019-09-20 09:41:20 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
it('checking addINIValuesOnDarwin', async () => {
|
|
|
|
let darwin: string = await features.addINIValues(
|
|
|
|
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
|
|
|
|
'darwin'
|
|
|
|
);
|
|
|
|
expect(darwin).toContain('echo "post_max_size=256M" >> $ini_file');
|
|
|
|
expect(darwin).toContain('echo "short_open_tag=On" >> $ini_file');
|
|
|
|
expect(darwin).toContain('echo "date.timezone=Asia/Kolkata" >> $ini_file');
|
2019-09-26 04:03:39 +07:00
|
|
|
|
|
|
|
darwin = await features.addINIValues(
|
|
|
|
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
|
|
|
|
'fedora'
|
|
|
|
);
|
|
|
|
expect(darwin).toContain('Platform fedora is not supported');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('checking addCoverage on windows', async () => {
|
|
|
|
let win32: string = await features.addCoverage('xdebug', '7.4', 'win32');
|
2019-09-28 21:39:05 +07:00
|
|
|
const extension_url: string =
|
|
|
|
'https://xdebug.org/files/php_xdebug-2.8.0beta2-7.4-vc15.dll';
|
2019-09-26 04:03:39 +07:00
|
|
|
expect(win32).toContain(
|
2019-09-28 21:39:05 +07:00
|
|
|
'Invoke-WebRequest -Uri ' +
|
|
|
|
extension_url +
|
|
|
|
' -OutFile C:\\tools\\php\\ext\\php_xdebug.dll'
|
2019-09-26 04:03:39 +07:00
|
|
|
);
|
|
|
|
|
|
|
|
win32 = await features.addCoverage('xdebug', '7.3', 'win32');
|
2019-09-28 21:39:05 +07:00
|
|
|
expect(win32).toContain('Install-PhpExtension xdebug');
|
2019-09-26 04:03:39 +07:00
|
|
|
|
|
|
|
win32 = await features.addCoverage('pcov', '7.4', 'win32');
|
2019-09-28 21:39:05 +07:00
|
|
|
expect(win32).toContain('Install-PhpExtension pcov');
|
2019-09-26 04:03:39 +07:00
|
|
|
expect(win32).toContain(
|
|
|
|
'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug C:\\tools\\php'
|
|
|
|
);
|
|
|
|
|
|
|
|
win32 = await features.addCoverage('pcov', '7.3', 'win32');
|
2019-09-28 21:39:05 +07:00
|
|
|
expect(win32).toContain('Install-PhpExtension pcov');
|
2019-09-26 04:03:39 +07:00
|
|
|
expect(win32).toContain(
|
|
|
|
'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug C:\\tools\\php'
|
|
|
|
);
|
|
|
|
|
|
|
|
win32 = await features.addCoverage('nocov', '7.3', 'win32');
|
|
|
|
expect(win32).toContain('');
|
|
|
|
|
|
|
|
win32 = await features.addCoverage('pcov', '7.0', 'win32');
|
2019-10-04 21:04:05 +07:00
|
|
|
expect(win32).toContain('PCOV requires PHP 7.1 or newer');
|
2019-09-26 04:03:39 +07:00
|
|
|
|
|
|
|
win32 = await features.addCoverage('pcov', '5.6', 'win32');
|
2019-10-04 21:04:05 +07:00
|
|
|
expect(win32).toContain('PCOV requires PHP 7.1 or newer');
|
2019-09-26 04:03:39 +07:00
|
|
|
|
|
|
|
win32 = await features.addCoverage('', '7.4', 'win32');
|
|
|
|
expect(win32).toEqual('');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('checking addCoverage on linux', async () => {
|
|
|
|
let linux: string = await features.addCoverage('xdebug', '7.4', 'linux');
|
2019-09-28 21:39:05 +07:00
|
|
|
expect(linux).toContain('./xdebug.sh');
|
2019-09-26 04:03:39 +07:00
|
|
|
|
|
|
|
linux = await features.addCoverage('pcov', '7.4', 'linux');
|
2019-09-28 21:39:05 +07:00
|
|
|
expect(linux).toContain('./pcov.sh');
|
|
|
|
expect(linux).toContain('sudo sed -i "/xdebug/d" $ini_file');
|
2019-10-04 21:04:05 +07:00
|
|
|
expect(linux).toContain('sudo phpdismod xdebug');
|
2019-09-26 04:03:39 +07:00
|
|
|
|
|
|
|
linux = await features.addCoverage('', '7.4', 'linux');
|
|
|
|
expect(linux).toEqual('');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('checking addCoverage on darwin', async () => {
|
|
|
|
let darwin: string = await features.addCoverage('xdebug', '7.4', 'darwin');
|
2019-09-28 21:39:05 +07:00
|
|
|
expect(darwin).toContain('sh ./xdebug_darwin.sh');
|
2019-09-26 04:03:39 +07:00
|
|
|
|
|
|
|
darwin = await features.addCoverage('xdebug', '5.6', 'darwin');
|
|
|
|
expect(darwin).toContain('sudo pecl install xdebug-2.5.5');
|
|
|
|
|
|
|
|
darwin = await features.addCoverage('pcov', '7.4', 'darwin');
|
2019-09-28 21:39:05 +07:00
|
|
|
expect(darwin).toContain('sh ./pcov.sh');
|
2019-09-26 04:03:39 +07:00
|
|
|
|
|
|
|
darwin = await features.addCoverage('', '7.4', 'win32');
|
|
|
|
expect(darwin).toEqual('');
|
2019-09-20 09:41:20 +07:00
|
|
|
});
|
|
|
|
});
|