Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/php_unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,28 @@ jobs:
cp phpcs.xml dist/phpcs.xml
cp phpunit.xml dist/phpunit.xml
cp -r tests dist/tests
cp -r utils dist/utils

- name: Install Dist Composer Dependencies
if: matrix.php != '8.5'
working-directory: dist
run: composer install --no-interaction --no-progress --no-suggest --optimize-autoloader

- name: Build Conflict Plugin
if: matrix.php != '8.5'
working-directory: dist
run: npm run build-conflict

- name: Start Dist Docker environment
if: matrix.php != '8.5'
working-directory: dist
run: npm run wp-env start

- name: Install Conflict Plugin
if: matrix.php != '8.5'
working-directory: dist
run: npm run install-conflict

- name: Log running Dist Docker containers
if: matrix.php != '8.5'
working-directory: dist
Expand Down
29 changes: 15 additions & 14 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
{
"core": "WordPress/WordPress",
"plugins": [ "." ],
"config": {
"core": "WordPress/WordPress",
"plugins": [ "." ],
"config": {
"WP_ENVIRONMENT_TYPE": "production",
"WP_ENV": "production",
"WP_DEBUG": true,
"WP_DEBUG_LOG": true,
"WP_DEBUG_DISPLAY": true
},
"env": {
"tests": {
"mappings": {
"wp-content/plugins/rollbar": "./"
}
}
}
"WP_DEBUG": true,
"WP_DEBUG_LOG": true,
"WP_DEBUG_DISPLAY": true
},
"env": {
"tests": {
"mappings": {
"wp-content/plugins/rollbar": "./",
"wp-content/plugins/conflict": "./tests/conflict"
}
}
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
},
"autoload-dev": {
"psr-4": {
"Rollbar\\WordPress\\Tests\\": "tests/"
"Rollbar\\WordPress\\Tests\\": "tests/",
"Rollbar\\WordPress\\BuildUtils\\": "utils/"
}
},
"extra": {
Expand Down
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
"test": "npm-run-all test:php test:phpcs",
"tests-composer-update": "WP_ENV_PHP_VERSION='8.1' npm run wp-env -- run --env-cwd='wp-content/plugins/rollbar' tests-cli composer update",
"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",
"pretest:php": "npm-run-all tests-composer-install",
"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",
"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",
"start": "npm run wp-env start",
"build": "cp -f node_modules/rollbar/dist/rollbar.snippet.js public/js/rollbar.snippet.js"
"build": "cp -f node_modules/rollbar/dist/rollbar.snippet.js public/js/rollbar.snippet.js",
"build-conflict": "cd tests/conflict && composer install --no-interaction --no-progress --no-suggest --optimize-autoloader",
"install-conflict": "npm run wp-env -- run tests-cli wp plugin activate conflict"
},
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<file>./mu-plugin</file>
<file>./src</file>
<file>./tests</file>
<file>./utils</file>
<file>./rollbar.php</file>

<!-- Show sniff codes in all reports -->
Expand Down
15 changes: 7 additions & 8 deletions scoper.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

declare(strict_types=1);

require_once './utils/NamespaceTokenFixer.php';

$finder = Isolated\Symfony\Component\Finder\Finder::class;
$fixer = new Rollbar\WordPress\BuildUtils\NamespaceTokenFixer();

return [
'prefix' => 'RollbarWP',
Expand Down Expand Up @@ -46,14 +49,10 @@
'zend_monitor_custom_event',
],
'patchers' => [
static function (string $filePath, string $prefix, string $content): string {
// Fix ClassLoader in string not being prefixed.
if ($filePath === __DIR__ . '/build/vendor/composer/autoload_real.php') {
$content = str_replace(
'(\'Composer\\\\Autoload\\\\ClassLoader\' === $class)',
'(\'RollbarWP\Composer\Autoload\ClassLoader\' === $class)',
$content,
);
static function (string $filePath, string $prefix, string $content) use ($fixer): string {
if ($fixer->fileIsFixable($filePath)) {
$fixer->configure($filePath, $content);
$content = $fixer->fix();
}

return $content;
Expand Down
15 changes: 15 additions & 0 deletions tests/conflict/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "conflict/conflict",
"description": "This is a test plugin that has dependency conflicts.",
"minimum-stability": "stable",
"license": "MIT",
"require": {
"psr/log": "^1.0",
"monolog/monolog": "^1.0"
},
"autoload": {
"psr-4": {
"Conflict\\": "src/"
}
}
}
155 changes: 155 additions & 0 deletions tests/conflict/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions tests/conflict/conflict.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* Plugin Name: Conflict
* Plugin URI: https://github.com/rollbar/rollbar-php-wordpress/tree/master/tests/conflict
* Description: A test plugin that conflicts with Rollbar.
* Version: 1.0.0
* Author: Rollbar
* Author URI: https://rollbar.com
* Text Domain: conflict
* License: MIT
* Requires PHP: 8.1
* Tested up to: 6.9
* Requires at least: 6.5
*/

// Exit if accessed directly
defined('ABSPATH') || exit;

const CONFLICT_PLUGIN_DIR = __DIR__;

require_once CONFLICT_PLUGIN_DIR . '/vendor/autoload.php';

\Conflict\Plugin::init();
49 changes: 49 additions & 0 deletions tests/conflict/src/Plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Conflict;

use Monolog\Handler\StreamHandler;
use Monolog\Logger;

/**
* This is a tiny plugin that will create a conflict with any other plugin that also uses Monolog unscoped.
*
* This is used to validate the scoping of Rollbar plugin's Monolog dependency.
*/
final class Plugin
{
/**
* @var Logger $logger The logger instance.
*/
private static Logger $logger;

/**
* Private constructor to prevent instantiation.
*/
private function __construct()
{
}

/**
* Initializes the plugin.
*
* @return void
*/
public static function init(): void
{
self::$logger = new Logger('conflict');
self::$logger->pushHandler(new StreamHandler(WP_CONTENT_DIR . '/logs/conflict.log', Logger::WARNING));

add_action('init', self::onInit(...));
}

/**
* Logs when the plugin is initialized.
*
* @return void
*/
public static function onInit(): void
{
self::$logger->warning('Conflict plugin initialized.');
}
}
Loading