Skip to content

Commit

Permalink
Merge pull request #60 from shivammathur/develop
Browse files Browse the repository at this point in the history
Release 1.4.3
  • Loading branch information
shivammathur authored Oct 17, 2019
2 parents 62beed2 + a6aaa1d commit ffc5b02
Show file tree
Hide file tree
Showing 20 changed files with 616 additions and 361 deletions.
3 changes: 2 additions & 1 deletion __tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ describe('Config tests', () => {
it('checking addINIValuesOnLinux', async () => {
let linux: string = await config.addINIValues(
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
'linux'
'linux',
true
);
expect(linux).toContain(
'echo "post_max_size=256M\nshort_open_tag=On\ndate.timezone=Asia/Kolkata" >> $ini_file'
Expand Down
4 changes: 2 additions & 2 deletions __tests__/coverage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ describe('Config tests', () => {
);

win32 = await coverage.addCoverage('pcov', '7.0', 'win32');
expect(win32).toContain('PCOV requires PHP 7.1 or newer');
expect(win32).toContain('PHP 7.1 or newer is required');

win32 = await coverage.addCoverage('pcov', '5.6', 'win32');
expect(win32).toContain('PCOV requires PHP 7.1 or newer');
expect(win32).toContain('PHP 7.1 or newer is required');
});

it('checking addCoverage with PCOV on linux', async () => {
Expand Down
16 changes: 13 additions & 3 deletions __tests__/extensions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ describe('Extension tests', () => {
);
expect(win32).toContain('Install-PhpExtension pcov');

win32 = await extensions.addExtension('does_not_exist', '7.2', 'win32');
win32 = await extensions.addExtension(
'does_not_exist',
'7.2',
'win32',
true
);
expect(win32).toContain(
'Add-Extension does_not_exist "Install-PhpExtension does_not_exist" extension "Add Extension"'
'Add-Extension does_not_exist "Install-PhpExtension does_not_exist" extension'
);

win32 = await extensions.addExtension('xdebug', '7.2', 'fedora');
Expand Down Expand Up @@ -84,7 +89,12 @@ describe('Extension tests', () => {
darwin = await extensions.addExtension('xdebug', '7.2', 'darwin');
expect(darwin).toContain('sudo pecl install xdebug');

darwin = await extensions.addExtension('does_not_exist', '7.2', 'darwin');
darwin = await extensions.addExtension(
'does_not_exist',
'7.2',
'darwin',
false
);
expect(darwin).toContain('add_extension does_not_exist');

darwin = await extensions.addExtension('xdebug', '7.2', 'fedora');
Expand Down
67 changes: 38 additions & 29 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ describe('Utils tests', () => {
expect(await utils.readScript('fedora.sh', '7.3', 'fedora')).toContain(
'Platform fedora is not supported'
);
await cleanup('./config.yaml');
await cleanup('./pcov.sh');
await cleanup('./phalcon.sh');
await cleanup('./php_pcov.dll');
await cleanup('./xdebug_darwin.sh');
});

it('checking writeScripts', async () => {
Expand Down Expand Up @@ -101,53 +106,48 @@ describe('Utils tests', () => {
let message: string = 'Test message';

let warning_log: string = await utils.log(message, 'win32', 'warning');
expect(warning_log).toEqual(
"Write-Host '" + message + "' -ForegroundColor yellow"
);
expect(warning_log).toEqual('printf "\\033[33;1m' + message + ' \\033[0m"');
warning_log = await utils.log(message, 'linux', 'warning');
expect(warning_log).toEqual('echo "\\033[33;1m' + message + '\\033[0m"');
warning_log = await utils.log(message, 'darwin', 'warning');
expect(warning_log).toEqual('echo "\\033[33;1m' + message + '\\033[0m"');

let error_log: string = await utils.log(message, 'win32', 'error');
expect(error_log).toEqual(
"Write-Host '" + message + "' -ForegroundColor red"
);
expect(error_log).toEqual('printf "\\033[31;1m' + message + ' \\033[0m"');
error_log = await utils.log(message, 'linux', 'error');
expect(error_log).toEqual('echo "\\033[31;1m' + message + '\\033[0m"');
error_log = await utils.log(message, 'darwin', 'error');
expect(error_log).toEqual('echo "\\033[31;1m' + message + '\\033[0m"');

let success_log: string = await utils.log(message, 'win32', 'success');
expect(success_log).toEqual(
"Write-Host '" + message + "' -ForegroundColor green"
);
expect(success_log).toEqual('printf "\\033[32;1m' + message + ' \\033[0m"');
success_log = await utils.log(message, 'linux', 'success');
expect(success_log).toEqual('echo "\\033[32;1m' + message + '\\033[0m"');
success_log = await utils.log(message, 'darwin', 'success');
expect(success_log).toEqual('echo "\\033[32;1m' + message + '\\033[0m"');

success_log = await utils.log(message, 'win32', 'success', 'Test win');
expect(success_log).toEqual(
"Write-Host 'Test win: " + message + "' -ForegroundColor green"
);
});

it('checking log with prefix', async () => {
let message: string = 'Test message';
let prefix_log: string = await utils.log(
message,
'linux',
'success',
'Test Prefix'
);
expect(prefix_log).toEqual(
'echo "\\033[32;1mTest Prefix: ' + message + '\\033[0m"'
);
prefix_log = await utils.log(message, 'darwin', 'success', 'Test');
expect(prefix_log).toEqual(
'echo "\\033[32;1mTest: ' + message + '\\033[0m"'
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"');
step_log = await utils.stepLog(message, 'fedora');
expect(step_log).toContain('Platform fedora is not supported');

let add_log: string = await utils.addLog(
'tick',
'xdebug',
'enabled',
'win32'
);
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"');
add_log = await utils.addLog('tick', 'xdebug', 'enabled', 'fedora');
expect(add_log).toContain('Platform fedora is not supported');
});

it('checking getExtensionPrefix', async () => {
Expand All @@ -158,4 +158,13 @@ describe('Utils tests', () => {
expect(await utils.getExtensionPrefix('xdebug')).toEqual('zend_extension');
expect(await utils.getExtensionPrefix('opcache')).toEqual('zend_extension');
});

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');
expect(await utils.suppressOutput('fedora')).toContain(
'Platform fedora is not supported'
);
});
});
42 changes: 36 additions & 6 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,29 @@ const utils = __importStar(require("./utils"));
* @param ini_values_csv
* @param os_version
*/
function addINIValues(ini_values_csv, os_version) {
function addINIValues(ini_values_csv, os_version, no_step = false) {
return __awaiter(this, void 0, void 0, function* () {
let script = '\n';
switch (no_step) {
case true:
script +=
(yield utils.stepLog('Add php.ini values', os_version)) +
(yield utils.suppressOutput(os_version)) +
'\n';
break;
case false:
default:
script += (yield utils.stepLog('Add php.ini values', os_version)) + '\n';
break;
}
switch (os_version) {
case 'win32':
return yield addINIValuesWindows(ini_values_csv);
return script + (yield addINIValuesWindows(ini_values_csv));
case 'darwin':
case 'linux':
return yield addINIValuesUnix(ini_values_csv);
return script + (yield addINIValuesUnix(ini_values_csv));
default:
return yield utils.log('Platform ' + os_version + ' is not supported', os_version, 'error', 'Add Config');
return yield utils.log('Platform ' + os_version + ' is not supported', os_version, 'error');
}
});
}
Expand All @@ -45,7 +58,14 @@ exports.addINIValues = addINIValues;
function addINIValuesUnix(ini_values_csv) {
return __awaiter(this, void 0, void 0, function* () {
let ini_values = yield utils.INIArray(ini_values_csv);
return '\necho "' + ini_values.join('\n') + '" >> $ini_file\n';
let script = '\n';
yield utils.asyncForEach(ini_values, function (line) {
return __awaiter(this, void 0, void 0, function* () {
script +=
(yield utils.addLog('$tick', line, 'Added to php.ini', 'linux')) + '\n';
});
});
return 'echo "' + ini_values.join('\n') + '" >> $ini_file' + script;
});
}
exports.addINIValuesUnix = addINIValuesUnix;
Expand All @@ -57,7 +77,17 @@ exports.addINIValuesUnix = addINIValuesUnix;
function addINIValuesWindows(ini_values_csv) {
return __awaiter(this, void 0, void 0, function* () {
let ini_values = yield utils.INIArray(ini_values_csv);
return ('Add-Content C:\\tools\\php\\php.ini "' + ini_values.join('\n') + '"\n');
let script = '\n';
yield utils.asyncForEach(ini_values, function (line) {
return __awaiter(this, void 0, void 0, function* () {
script +=
(yield utils.addLog('$tick', line, 'Added to php.ini', 'win32')) + '\n';
});
});
return ('Add-Content C:\\tools\\php\\php.ini "' +
ini_values.join('\n') +
'"' +
script);
});
}
exports.addINIValuesWindows = addINIValuesWindows;
29 changes: 17 additions & 12 deletions lib/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ const config = __importStar(require("./config"));
function addCoverage(coverage_driver, version, os_version) {
return __awaiter(this, void 0, void 0, function* () {
coverage_driver.toLowerCase();
let script = '\n' + (yield utils.stepLog('Setup Coverage', os_version));
switch (coverage_driver) {
case 'pcov':
return addCoveragePCOV(version, os_version);
return script + (yield addCoveragePCOV(version, os_version));
case 'xdebug':
return addCoverageXdebug(version, os_version);
return script + (yield addCoverageXdebug(version, os_version));
case 'none':
return disableCoverage(version, os_version);
return script + (yield disableCoverage(version, os_version));
default:
return '';
}
Expand All @@ -50,10 +51,10 @@ exports.addCoverage = addCoverage;
*/
function addCoverageXdebug(version, os_version) {
return __awaiter(this, void 0, void 0, function* () {
let script = '\n';
script += yield extensions.addExtension('xdebug', version, os_version, 'Set Coverage Driver');
script += yield utils.log('Xdebug enabled as coverage driver', os_version, 'success', 'Set Coverage Driver');
return script;
return ((yield extensions.addExtension('xdebug', version, os_version, true)) +
(yield utils.suppressOutput(os_version)) +
'\n' +
(yield utils.addLog('$tick', 'xdebug', 'Xdebug enabled as coverage driver', os_version)));
});
}
exports.addCoverageXdebug = addCoverageXdebug;
Expand All @@ -68,8 +69,12 @@ function addCoveragePCOV(version, os_version) {
let script = '\n';
switch (version) {
default:
script += yield extensions.addExtension('pcov', version, os_version, 'Set Coverage Driver');
script += yield config.addINIValues('pcov.enabled=1', os_version);
script +=
(yield extensions.addExtension('pcov', version, os_version, true)) +
(yield utils.suppressOutput(os_version)) +
'\n';
script +=
(yield config.addINIValues('pcov.enabled=1', os_version, true)) + '\n';
// add command to disable xdebug and enable pcov
switch (os_version) {
case 'linux':
Expand All @@ -90,12 +95,12 @@ function addCoveragePCOV(version, os_version) {
break;
}
// success
script += yield utils.log('PCOV enabled as coverage driver', os_version, 'success', 'Set Coverage Driver');
script += yield utils.addLog('$tick', 'coverage: pcov', 'PCOV enabled as coverage driver', os_version);
// version is not supported
break;
case '5.6':
case '7.0':
script += yield utils.log('PCOV requires PHP 7.1 or newer', os_version, 'warning', 'Set Coverage Driver');
script += yield utils.addLog('$cross', 'pcov', 'PHP 7.1 or newer is required', os_version);
break;
}
return script;
Expand Down Expand Up @@ -139,7 +144,7 @@ function disableCoverage(version, os_version) {
'if(php -m | findstr -i pcov) { Disable-PhpExtension pcov C:\\tools\\php }\n';
break;
}
script += yield utils.log('Disabled Xdebug and PCOV', os_version, 'success', 'Set Coverage Driver');
script += yield utils.addLog('$tick', 'none', 'Disabled Xdebug and PCOV', os_version);
return script;
});
}
Expand Down
Loading

0 comments on commit ffc5b02

Please sign in to comment.