Skip to content

Commit

Permalink
Log error when wrong Xdebug version is requested
Browse files Browse the repository at this point in the history
  • Loading branch information
shivammathur committed Nov 25, 2021
1 parent 92b4784 commit b330664
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 30 deletions.
5 changes: 3 additions & 2 deletions __tests__/coverage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ describe('Config tests', () => {
${'pcov'} | ${'7.4'} | ${'linux'} | ${'add_extension pcov,disable_extension xdebug false'}
${'pcov'} | ${'7.4'} | ${'darwin'} | ${'add_brew_extension pcov,disable_extension xdebug false'}
${'xdebug'} | ${'7.4'} | ${'win32'} | ${'Add-Extension xdebug'}
${'xdebug3'} | ${'7.4'} | ${'win32'} | ${'Add-Extension xdebug'}
${'xdebug3'} | ${'7.1'} | ${'win32'} | ${'xdebug3 is not supported on PHP 7.1'}
${'xdebug2'} | ${'7.4'} | ${'win32'} | ${'Add-Extension xdebug stable 2.9.8'}
${'xdebug'} | ${'8.0'} | ${'linux'} | ${'add_extension xdebug'}
${'xdebug3'} | ${'8.0'} | ${'linux'} | ${'add_extension xdebug'}
${'xdebug2'} | ${'7.4'} | ${'linux'} | ${'add_pecl_extension xdebug 2.9.8 zend_extension'}
${'xdebug'} | ${'7.4'} | ${'darwin'} | ${'add_brew_extension xdebug'}
${'xdebug3'} | ${'7.4'} | ${'darwin'} | ${'add_brew_extension xdebug'}
${'xdebug3'} | ${'7.1'} | ${'darwin'} | ${'xdebug3 is not supported on PHP 7.1'}
${'xdebug2'} | ${'7.4'} | ${'darwin'} | ${'add_brew_extension xdebug2'}
${'xdebug2'} | ${'8.0'} | ${'darwin'} | ${'xdebug2 is not supported on PHP 8.0'}
${'none'} | ${'7.4'} | ${'win32'} | ${'Disable-Extension xdebug false,Disable-Extension pcov false'}
${'none'} | ${'7.4'} | ${'linux'} | ${'disable_extension xdebug false,disable_extension pcov false'}
${'none'} | ${'7.4'} | ${'darwin'} | ${'disable_extension xdebug false,disable_extension pcov false'}
Expand Down
36 changes: 25 additions & 11 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,33 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.addCoverage = exports.disableCoverage = exports.addCoveragePCOV = exports.addCoverageXdebug = void 0;
exports.addCoverage = exports.disableCoverage = exports.addCoveragePCOV = exports.addCoverageXdebug = exports.checkXdebugError = void 0;
const utils = __importStar(__nccwpck_require__(918));
const extensions = __importStar(__nccwpck_require__(390));
const config = __importStar(__nccwpck_require__(88));
async function checkXdebugError(extension, version) {
if ((/^5\.[3-6]$|^7\.[0-1]$/.test(version) && extension == 'xdebug3') ||
(/^8\.[0-9]$/.test(version) && extension == 'xdebug2')) {
return extension + ' is not supported on PHP ' + version;
}
return '';
}
exports.checkXdebugError = checkXdebugError;
async function addCoverageXdebug(extension, version, os_version, pipe) {
let script = '\n';
script +=
(await extensions.addExtension(':pcov:false', version, os_version, true)) +
pipe;
script +=
(await extensions.addExtension(extension, version, os_version, true)) +
pipe;
script += await utils.addLog('$tick', extension, 'Xdebug enabled as coverage driver', os_version);
let message = await checkXdebugError(extension, version);
let status = '$cross';
if (!message) {
script +=
(await extensions.addExtension(':pcov:false', version, os_version, true)) + pipe;
extension = extension == 'xdebug3' ? 'xdebug' : extension;
script +=
(await extensions.addExtension(extension, version, os_version, true)) +
pipe;
message = 'Xdebug enabled as coverage driver';
status = '$tick';
}
script += await utils.addLog(status, extension, message, os_version);
return script;
}
exports.addCoverageXdebug = addCoverageXdebug;
Expand Down Expand Up @@ -159,10 +173,10 @@ async function addCoverage(coverage_driver, version, os_version) {
case 'pcov':
return script + (await addCoveragePCOV(version, os_version, pipe));
case 'xdebug':
case 'xdebug3':
return (script + (await addCoverageXdebug('xdebug', version, os_version, pipe)));
case 'xdebug2':
return (script + (await addCoverageXdebug('xdebug2', version, os_version, pipe)));
case 'xdebug3':
return (script +
(await addCoverageXdebug(coverage_driver, version, os_version, pipe)));
case 'none':
return script + (await disableCoverage(version, os_version, pipe));
default:
Expand Down
51 changes: 34 additions & 17 deletions src/coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ import * as utils from './utils';
import * as extensions from './extensions';
import * as config from './config';

export async function checkXdebugError(
extension: string,
version: string
): Promise<string> {
if (
(/^5\.[3-6]$|^7\.[0-1]$/.test(version) && extension == 'xdebug3') ||
(/^8\.[0-9]$/.test(version) && extension == 'xdebug2')
) {
return extension + ' is not supported on PHP ' + version;
}
return '';
}

/**
* Function to setup Xdebug
*
Expand All @@ -17,18 +30,24 @@ export async function addCoverageXdebug(
pipe: string
): Promise<string> {
let script = '\n';
script +=
(await extensions.addExtension(':pcov:false', version, os_version, true)) +
pipe;
script +=
(await extensions.addExtension(extension, version, os_version, true)) +
pipe;
script += await utils.addLog(
'$tick',
extension,
'Xdebug enabled as coverage driver',
os_version
);
let message: string = await checkXdebugError(extension, version);
let status = '$cross';
if (!message) {
script +=
(await extensions.addExtension(
':pcov:false',
version,
os_version,
true
)) + pipe;
extension = extension == 'xdebug3' ? 'xdebug' : extension;
script +=
(await extensions.addExtension(extension, version, os_version, true)) +
pipe;
message = 'Xdebug enabled as coverage driver';
status = '$tick';
}
script += await utils.addLog(status, extension, message, os_version);
return script;
}

Expand Down Expand Up @@ -136,13 +155,11 @@ export async function addCoverage(
case 'pcov':
return script + (await addCoveragePCOV(version, os_version, pipe));
case 'xdebug':
case 'xdebug3':
return (
script + (await addCoverageXdebug('xdebug', version, os_version, pipe))
);
case 'xdebug2':
case 'xdebug3':
return (
script + (await addCoverageXdebug('xdebug2', version, os_version, pipe))
script +
(await addCoverageXdebug(coverage_driver, version, os_version, pipe))
);
case 'none':
return script + (await disableCoverage(version, os_version, pipe));
Expand Down

0 comments on commit b330664

Please sign in to comment.