Skip to content
Merged
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
17 changes: 3 additions & 14 deletions tests/Integration/PartialDeployTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
namespace DeepWebSolutions\PluginTemplate\Tests\Integration;

use DeepWebSolutions\PluginTemplate\Scoped\DeepWebSolutions\Framework\Core\Uninstall\Uninstaller;
use DeepWebSolutions\PluginTemplate\Tests\Support\RunsRequestsTrait;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\TestCase;

#[CoversNothing]
final class PartialDeployTest extends TestCase {
use RunsRequestsTrait;

public function test_a_missing_blocks_manifest_shows_the_build_notice_and_loads_nothing_built(): void {
$manifest = \dirname( DWS_TPL_FILE ) . '/blocks/build/blocks-manifest.php';
\rename( $manifest, "$manifest.hidden" );
Expand Down Expand Up @@ -83,18 +86,4 @@ static function ( string $class_name ): void {
\unlink( $log );
update_option( DWS_TPL_OPTION_DELETE_DATA, 'no' );
}

/**
* @return array{status: int, output: string, last: string}
*/
protected static function request( string $php ): array {
\exec( 'wp --path=' . \escapeshellarg( ABSPATH ) . ' eval ' . \escapeshellarg( $php ) . ' 2>&1', $output, $status ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.system_calls_exec -- Each row needs a fresh request that loads the plugin.
$output = \array_values( \array_filter( $output, static fn ( string $line ): bool => '' !== \trim( $line ) ) );

return array(
'status' => $status,
'output' => \implode( "\n", $output ),
'last' => (string) \end( $output ),
);
}
}
13 changes: 12 additions & 1 deletion tests/Integration/PluginBootTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
use DeepWebSolutions\PluginTemplate\Scoped\DeepWebSolutions\Framework\Core\Migration\MigrationRunner;
use DeepWebSolutions\PluginTemplate\Scoped\DeepWebSolutions\Framework\Core\Scheduling\Scheduler;
use DeepWebSolutions\PluginTemplate\Settings;
use DeepWebSolutions\PluginTemplate\Tests\Support\RunsRequestsTrait;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\TestCase;

#[CoversNothing]
final class PluginBootTest extends TestCase {
use RunsRequestsTrait;

public function test_the_plugin_boots_with_the_greeting_gated_off_until_a_site_switches_it_on(): void {
$plugin = dws_tpl_plugin();

Expand All @@ -26,7 +29,15 @@ public function test_the_entry_loads_every_include_but_those_whose_names_start_w
$includes = \dirname( DWS_TPL_FILE ) . '/includes/';

self::assertContains( $includes . 'index.php', \get_included_files() );
self::assertNotContains( $includes . '_disabled-example.php', \get_included_files() );
self::assertIsInt( \file_put_contents( $includes . '_skipped-include.php', "<?php\nconst DWS_TPL_SKIPPED_INCLUDE = true;\n" ) );
try {
$request = self::request( 'echo 0 < did_action( "dws_tpl/boot/succeeded" ) ? ( defined( "DWS_TPL_SKIPPED_INCLUDE" ) ? "loaded" : "skipped" ) : "not booted";' );
} finally {
\unlink( $includes . '_skipped-include.php' );
}

self::assertSame( 0, $request['status'], $request['output'] );
self::assertSame( 'skipped', $request['last'], $request['output'] );
}

public function test_the_entry_loads_its_safeguards_before_the_bootstrap_package_and_its_floor_gate(): void {
Expand Down
19 changes: 19 additions & 0 deletions tests/Support/RunsRequestsTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php declare( strict_types=1 );

namespace DeepWebSolutions\PluginTemplate\Tests\Support;

trait RunsRequestsTrait {
/**
* @return array{status: int, output: string, last: string}
*/
protected static function request( string $php ): array {
\exec( 'wp --path=' . \escapeshellarg( ABSPATH ) . ' eval ' . \escapeshellarg( $php ) . ' 2>&1', $output, $status ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.system_calls_exec -- Each row needs a fresh request that loads the plugin.
$output = \array_values( \array_filter( $output, static fn ( string $line ): bool => '' !== \trim( $line ) ) );

return array(
'status' => $status,
'output' => \implode( "\n", $output ),
'last' => (string) \end( $output ),
);
}
}
Loading