From c022e7e6d29b415c3f84ccaeb3467f77c41832b3 Mon Sep 17 00:00:00 2001 From: recca0120 Date: Thu, 15 May 2025 02:16:38 +0800 Subject: [PATCH] fix command bug --- package.json | 2 +- src/PHPUnit/CommandBuilder/Builder.test.ts | 12 ++++++------ src/PHPUnit/CommandBuilder/Builder.ts | 12 ++++++++---- src/PHPUnit/TestRunner.test.ts | 20 +++----------------- 4 files changed, 18 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index d2b4c4d6..b8edb0cc 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "displayName": "PHPUnit Test Explorer", "icon": "img/icon.png", "publisher": "recca0120", - "version": "3.7.8", + "version": "3.7.9", "private": true, "license": "MIT", "repository": { diff --git a/src/PHPUnit/CommandBuilder/Builder.test.ts b/src/PHPUnit/CommandBuilder/Builder.test.ts index f2b74dfc..282611ef 100644 --- a/src/PHPUnit/CommandBuilder/Builder.test.ts +++ b/src/PHPUnit/CommandBuilder/Builder.test.ts @@ -125,7 +125,7 @@ describe('Builder Test', () => { expect(runtime).toEqual('php'); expect(args).toEqual([ 'vendor/bin/pest', - `--filter="^.*::(it has user's email)(( with (data set )?.*)?)?$"`, + `--filter=^.*::(it has user's email)(( with (data set )?.*)?)?$`, phpUnitProject('tests/AssertionsTest.php'), '--colors=never', '--teamcity', @@ -184,7 +184,7 @@ describe('Builder Test', () => { [ 'php', 'vendor/bin/paratest', - `--filter=^.*::(test_passed)( with data set .*)?$`, + `'--filter=^.*::(test_passed)( with data set .*)?$'`, `--colors=never`, `--teamcity`, `--functional`, @@ -263,7 +263,7 @@ describe('Builder Test', () => { 'php', 'artisan', 'test', - `--filter=^.*::(test_passed)( with data set .*)?$`, + `'--filter=^.*::(test_passed)( with data set .*)?$'`, `--colors=never`, `--teamcity`, ].join(' '), @@ -292,7 +292,7 @@ describe('Builder Test', () => { 'php', 'artisan', 'test', - `--filter=^.*::(test_passed)( with data set .*)?$`, + `'--filter=^.*::(test_passed)( with data set .*)?$'`, '--colors=never', '--teamcity', ].join(' '), @@ -394,7 +394,7 @@ describe('Builder Test', () => { 'php', 'artisan', 'test', - `--filter=^.*::(test_passed)( with data set .*)?$`, + `'--filter=^.*::(test_passed)( with data set .*)?$'`, `--colors=never`, `--teamcity`, ].join(' '), @@ -418,7 +418,7 @@ describe('Builder Test', () => { [ 'php', 'vendor/bin/phpunit', - `--filter=^.*::(test_passed)( with data set .*)?$`, + `'--filter=^.*::(test_passed)( with data set .*)?$'`, '--colors=never', '--teamcity', ].join(' '), diff --git a/src/PHPUnit/CommandBuilder/Builder.ts b/src/PHPUnit/CommandBuilder/Builder.ts index ab270796..977985ec 100644 --- a/src/PHPUnit/CommandBuilder/Builder.ts +++ b/src/PHPUnit/CommandBuilder/Builder.ts @@ -162,7 +162,7 @@ export class Builder { const pattern = new RegExp('^(--filter)=(.*)'); return input.replace(pattern, (_m, ...matched) => { - const value = btoa(matched[1]); + const value = Buffer.from(matched[1], 'utf-8').toString('base64'); return `${matched[0]}='${value}'`; }); @@ -170,14 +170,18 @@ export class Builder { } private decodeFilter(args: string[]) { + const command = args.join(' '); + const needsQuote = isSSH(command) || isShellCommand(command); + return args.map((input) => { const pattern = new RegExp('(--filter)=["\'](.+)?["\']'); return input.replace(pattern, (_m, ...matched) => { - const value = atob(matched[1]); - const quote = value.includes('\'') ? '"' : ''; + const value = Buffer.from(matched[1], 'base64').toString('utf-8'); + const quote = value.includes('\'') ? '"' : '\''; + const filter = `${matched[0]}=${value}`; - return `${matched[0]}=${quote}${value}${quote}`; + return needsQuote ? `${quote}${filter}${quote}` : filter; }); }); } diff --git a/src/PHPUnit/TestRunner.test.ts b/src/PHPUnit/TestRunner.test.ts index 614d5ff2..060def31 100644 --- a/src/PHPUnit/TestRunner.test.ts +++ b/src/PHPUnit/TestRunner.test.ts @@ -346,20 +346,6 @@ describe('TestRunner Test', () => { await shouldRunTestFailed(expected, builder, projectPath, appPath); }); - - it('should run test failed with phpvfscomposer for Docker', async () => { - const expected = [ - 'php', - appPath('vendor/bin/phpunit'), - `--configuration=${appPath('phpunit.xml')}`, - `--filter=^.*::(test_passed|test_failed)( with data set .*)?$`, - appPath('tests/AssertionsTest.php'), - '--colors=never', - '--teamcity', - ]; - - await shouldRunTestFailed(expected, builder, projectPath, appPath, true); - }); }); describe('SSH', () => { @@ -441,7 +427,7 @@ describe('TestRunner Test', () => { 'php', 'vendor/bin/phpunit', `--configuration=${appPath('phpunit.xml')}`, - `--filter=^.*::(test_passed)( with data set .*)?$`, + `'--filter=^.*::(test_passed)( with data set .*)?$'`, appPath('tests/AssertionsTest.php'), `--colors=never`, `--teamcity`, @@ -467,7 +453,7 @@ describe('TestRunner Test', () => { 'php', 'vendor/bin/phpunit', `--configuration=${appPath('phpunit.xml')}`, - `--filter=^.*::(test_passed|test_failed)( with data set .*)?$`, + `'--filter=^.*::(test_passed|test_failed)( with data set .*)?$'`, appPath('tests/AssertionsTest.php'), `--colors=never`, `--teamcity`, @@ -493,7 +479,7 @@ describe('TestRunner Test', () => { 'php', 'vendor/bin/phpunit', `--configuration=${appPath('phpunit.xml')}`, - `--filter=^.*::(test_passed|test_failed)( with data set .*)?$`, + `'--filter=^.*::(test_passed|test_failed)( with data set .*)?$'`, appPath('tests/AssertionsTest.php'), `--colors=never`, `--teamcity`,