Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jdamner committed May 22, 2024
1 parent 8582c93 commit 952c59b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 14 deletions.
8 changes: 3 additions & 5 deletions packages/editor-tools/src/AssetLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand All @@ -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;
Expand Down Expand Up @@ -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()
);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/editor-tools/tests/TestAssetLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
6 changes: 0 additions & 6 deletions tests/bootstrap-phpstan.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
3 changes: 0 additions & 3 deletions tests/bootstrap-phpunit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit 952c59b

Please sign in to comment.