diff --git a/packages/editor-tools/src/AssetLoader.php b/packages/editor-tools/src/AssetLoader.php index bd4dff5..f02ac09 100644 --- a/packages/editor-tools/src/AssetLoader.php +++ b/packages/editor-tools/src/AssetLoader.php @@ -38,7 +38,7 @@ public function __construct( private string $base_path = '', private string $pre */ public function load( string $handle ): void { if ( ! file_exists( $this->get_asset_path( $handle ) ) ) { - if ( \WP_DEBUG ) { + if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { wp_die( sprintf( 'Could not load asset %s from %s. Please ensure assets have been compiled.', @@ -53,7 +53,7 @@ public function load( string $handle ): void { $asset = require $this->get_asset_path( $handle ); // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable -- This is required. if ( ! is_array( $asset ) ) { - if ( \WP_DEBUG ) { + if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { wp_die( sprintf( 'Asset %s is not valid. Please ensure assets have been compiled.', esc_html( $handle ) ) ); } return; @@ -129,9 +129,7 @@ protected function get_base_path(): string { * @return string */ protected function get_base_url(): string { - return str_replace( - WP_CONTENT_DIR, - WP_CONTENT_URL, + return plugin_dir_url( $this->get_base_path() ); } diff --git a/packages/editor-tools/tests/TestAssetLoader.php b/packages/editor-tools/tests/TestAssetLoader.php index 7c4715f..b45dcd8 100644 --- a/packages/editor-tools/tests/TestAssetLoader.php +++ b/packages/editor-tools/tests/TestAssetLoader.php @@ -27,6 +27,10 @@ public function testLoad(): void { ->once() ->andReturn( __DIR__ . '/fixtures/AssetLoader' ); + \WP_Mock::userFunction( 'plugin_dir_url' ) + ->atLeast()->once() + ->andReturn( 'http://localhost' ); + \WP_Mock::userFunction( 'wp_enqueue_script' ) ->once() ->with( 'box-test', \WP_Mock\Functions::type( 'string' ), array(), '1', true ); diff --git a/tests/bootstrap-phpstan.php b/tests/bootstrap-phpstan.php index 83196a4..3c04228 100644 --- a/tests/bootstrap-phpstan.php +++ b/tests/bootstrap-phpstan.php @@ -7,12 +7,6 @@ declare ( strict_types=1 ); -/** - * Load Environment Configuration -*/ -define( 'PROJECT_NAME', 'boxuk-base-wp-plugin' ); -define( 'WP_CONTENT_URL', 'http://localhost' ); - /* Load Stubs */ $files = glob( __DIR__ . '/stubs/*.php' ); foreach ( $files as $file ) { diff --git a/tests/bootstrap-phpunit.php b/tests/bootstrap-phpunit.php index 19119d7..48a16b4 100644 --- a/tests/bootstrap-phpunit.php +++ b/tests/bootstrap-phpunit.php @@ -11,7 +11,4 @@ require_once $root_dir . '/vendor/autoload.php'; define( 'WP_DEBUG', true ); -define( 'WP_CONTENT_DIR', $root_dir ); -define( 'WP_CONTENT_URL', 'http://localhost' ); - WP_Mock::bootstrap();