Skip to content

Commit 30f7fbd

Browse files
authored
Merge pull request #149 from rollbar/fixed/issue-147-class-name-collision
Fixed #147 Added NamespaceTokenFixer to fix unscoped namespace strings
2 parents 3257087 + a39ae2a commit 30f7fbd

File tree

13 files changed

+582
-26
lines changed

13 files changed

+582
-26
lines changed

.github/workflows/php_unit.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,28 @@ jobs:
102102
cp phpcs.xml dist/phpcs.xml
103103
cp phpunit.xml dist/phpunit.xml
104104
cp -r tests dist/tests
105+
cp -r utils dist/utils
105106
106107
- name: Install Dist Composer Dependencies
107108
if: matrix.php != '8.5'
108109
working-directory: dist
109110
run: composer install --no-interaction --no-progress --no-suggest --optimize-autoloader
110111

112+
- name: Build Conflict Plugin
113+
if: matrix.php != '8.5'
114+
working-directory: dist
115+
run: npm run build-conflict
116+
111117
- name: Start Dist Docker environment
112118
if: matrix.php != '8.5'
113119
working-directory: dist
114120
run: npm run wp-env start
115121

122+
- name: Install Conflict Plugin
123+
if: matrix.php != '8.5'
124+
working-directory: dist
125+
run: npm run install-conflict
126+
116127
- name: Log running Dist Docker containers
117128
if: matrix.php != '8.5'
118129
working-directory: dist

.wp-env.json

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
{
2-
"core": "WordPress/WordPress",
3-
"plugins": [ "." ],
4-
"config": {
2+
"core": "WordPress/WordPress",
3+
"plugins": [ "." ],
4+
"config": {
55
"WP_ENVIRONMENT_TYPE": "production",
66
"WP_ENV": "production",
7-
"WP_DEBUG": true,
8-
"WP_DEBUG_LOG": true,
9-
"WP_DEBUG_DISPLAY": true
10-
},
11-
"env": {
12-
"tests": {
13-
"mappings": {
14-
"wp-content/plugins/rollbar": "./"
15-
}
16-
}
17-
}
7+
"WP_DEBUG": true,
8+
"WP_DEBUG_LOG": true,
9+
"WP_DEBUG_DISPLAY": true
10+
},
11+
"env": {
12+
"tests": {
13+
"mappings": {
14+
"wp-content/plugins/rollbar": "./",
15+
"wp-content/plugins/conflict": "./tests/conflict"
16+
}
17+
}
18+
}
1819
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
},
3737
"autoload-dev": {
3838
"psr-4": {
39-
"Rollbar\\WordPress\\Tests\\": "tests/"
39+
"Rollbar\\WordPress\\Tests\\": "tests/",
40+
"Rollbar\\WordPress\\BuildUtils\\": "utils/"
4041
}
4142
},
4243
"extra": {

package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
"test": "npm-run-all test:php test:phpcs",
1313
"tests-composer-update": "WP_ENV_PHP_VERSION='8.1' npm run wp-env -- run --env-cwd='wp-content/plugins/rollbar' tests-cli composer update",
1414
"tests-composer-install": "WP_ENV_PHP_VERSION='8.1' npm run wp-env -- run --env-cwd='wp-content/plugins/rollbar' tests-cli composer install --no-interaction",
15-
"pretest:php": "npm-run-all tests-composer-install",
1615
"test:php": "npm run wp-env -- run tests-wordpress /var/www/html/wp-content/plugins/rollbar/vendor/bin/phpunit -c /var/www/html/wp-content/plugins/rollbar/phpunit.xml",
1716
"test:phpcs": "npm run wp-env -- run tests-wordpress /var/www/html/wp-content/plugins/rollbar/vendor/bin/phpcs --standard=/var/www/html/wp-content/plugins/rollbar/phpcs.xml -p",
1817
"start": "npm run wp-env start",
19-
"build": "cp -f node_modules/rollbar/dist/rollbar.snippet.js public/js/rollbar.snippet.js"
18+
"build": "cp -f node_modules/rollbar/dist/rollbar.snippet.js public/js/rollbar.snippet.js",
19+
"build-conflict": "cd tests/conflict && composer install --no-interaction --no-progress --no-suggest --optimize-autoloader",
20+
"install-conflict": "npm run wp-env -- run tests-cli wp plugin activate conflict"
2021
},
2122
"repository": {
2223
"type": "git",

phpcs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<file>./mu-plugin</file>
1414
<file>./src</file>
1515
<file>./tests</file>
16+
<file>./utils</file>
1617
<file>./rollbar.php</file>
1718

1819
<!-- Show sniff codes in all reports -->

scoper.inc.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
declare(strict_types=1);
44

5+
require_once './utils/NamespaceTokenFixer.php';
6+
57
$finder = Isolated\Symfony\Component\Finder\Finder::class;
8+
$fixer = new Rollbar\WordPress\BuildUtils\NamespaceTokenFixer();
69

710
return [
811
'prefix' => 'RollbarWP',
@@ -46,14 +49,10 @@
4649
'zend_monitor_custom_event',
4750
],
4851
'patchers' => [
49-
static function (string $filePath, string $prefix, string $content): string {
50-
// Fix ClassLoader in string not being prefixed.
51-
if ($filePath === __DIR__ . '/build/vendor/composer/autoload_real.php') {
52-
$content = str_replace(
53-
'(\'Composer\\\\Autoload\\\\ClassLoader\' === $class)',
54-
'(\'RollbarWP\Composer\Autoload\ClassLoader\' === $class)',
55-
$content,
56-
);
52+
static function (string $filePath, string $prefix, string $content) use ($fixer): string {
53+
if ($fixer->fileIsFixable($filePath)) {
54+
$fixer->configure($filePath, $content);
55+
$content = $fixer->fix();
5756
}
5857

5958
return $content;

tests/conflict/composer.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "conflict/conflict",
3+
"description": "This is a test plugin that has dependency conflicts.",
4+
"minimum-stability": "stable",
5+
"license": "MIT",
6+
"require": {
7+
"psr/log": "^1.0",
8+
"monolog/monolog": "^1.0"
9+
},
10+
"autoload": {
11+
"psr-4": {
12+
"Conflict\\": "src/"
13+
}
14+
}
15+
}

tests/conflict/composer.lock

Lines changed: 155 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/conflict/conflict.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/**
4+
* Plugin Name: Conflict
5+
* Plugin URI: https://github.com/rollbar/rollbar-php-wordpress/tree/master/tests/conflict
6+
* Description: A test plugin that conflicts with Rollbar.
7+
* Version: 1.0.0
8+
* Author: Rollbar
9+
* Author URI: https://rollbar.com
10+
* Text Domain: conflict
11+
* License: MIT
12+
* Requires PHP: 8.1
13+
* Tested up to: 6.9
14+
* Requires at least: 6.5
15+
*/
16+
17+
// Exit if accessed directly
18+
defined('ABSPATH') || exit;
19+
20+
const CONFLICT_PLUGIN_DIR = __DIR__;
21+
22+
require_once CONFLICT_PLUGIN_DIR . '/vendor/autoload.php';
23+
24+
\Conflict\Plugin::init();

0 commit comments

Comments
 (0)