Skip to content

Commit b451011

Browse files
authored
Adding with_debug and with_multisite helpers (#639)
* Adding with_debug and with_multisite helpers * CHANGELOG
1 parent d12f22e commit b451011

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## v1.5.4 - 2025-03-06
99

10+
### Added
11+
12+
- Added `with_debug()` and `with_multisite()` methods to the installation manager.
13+
1014
### Fixed
1115

1216
- Fix the `Post::for()`/`Term::for()` methods to properly set the post

src/mantle/testing/class-installation-manager.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,38 @@ public function with_url( ?string $home = null, ?string $site = null, bool $set_
265265
return $this;
266266
}
267267

268+
/**
269+
* Enable or disable the debug mode.
270+
*
271+
* @param bool $enable Whether to enable debug mode.
272+
*/
273+
public function with_debug( bool $enable = true ): static {
274+
return $this->before(
275+
fn () => putenv( 'MANTLE_TESTING_DEBUG=' . ( $enable ? '1' : '0' ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_putenv
276+
);
277+
}
278+
279+
/**
280+
* Enable or disable multisite mode.
281+
*
282+
* This is commonly set on the CI matrix but made available here as well.
283+
*
284+
* @param bool $enable Whether to enable multisite.
285+
*/
286+
public function with_multisite( bool $enable = true ): static {
287+
return $this->before(
288+
function () use ( $enable ): void {
289+
if ( $enable ) {
290+
putenv( 'WP_MULTISITE=1' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_putenv
291+
putenv( 'WP_TESTS_MULTISITE=1' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_putenv
292+
} else {
293+
putenv( 'WP_MULTISITE=0' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_putenv
294+
putenv( 'WP_TESTS_MULTISITE=0' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_putenv
295+
}
296+
},
297+
);
298+
}
299+
268300
/**
269301
* Install the Mantle Testing Framework.
270302
*

src/mantle/testing/class-utils.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,10 @@ public static function is_debug_mode(): bool {
433433
return true;
434434
}
435435

436+
if ( self::env_bool( 'MANTLE_TESTING_DEBUG', false ) ) {
437+
return true;
438+
}
439+
436440
return ! empty(
437441
array_intersect(
438442
(array) ( $_SERVER['argv'] ?? [] ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized

0 commit comments

Comments
 (0)