Skip to content

Commit

Permalink
mark testing scope
Browse files Browse the repository at this point in the history
  • Loading branch information
reimic committed Jun 11, 2024
1 parent 0640d11 commit ee4bcf6
Show file tree
Hide file tree
Showing 12 changed files with 215 additions and 54 deletions.
54 changes: 27 additions & 27 deletions examples/blueprint_compiling_simple_progress.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\ConsoleOutput;
//use Symfony\Component\Console\Input\StringInput;
//use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use WordPress\Blueprints\ContainerBuilder;
use WordPress\Blueprints\Model\BlueprintBuilder;
Expand All @@ -17,31 +17,31 @@

$blueprint = BlueprintBuilder::create()
->withWordPressVersion( 'https://wordpress.org/latest.zip' )
->withSiteOptions( [
'blogname' => 'My Playground Blog',
] )
->withWpConfigConstants( [
'WP_DEBUG' => true,
'WP_DEBUG_LOG' => true,
'WP_DEBUG_DISPLAY' => true,
'WP_CACHE' => true,
] )
->withPlugins( [
// Required for withContent():
'https://downloads.wordpress.org/plugin/wordpress-importer.zip',
'https://downloads.wordpress.org/plugin/hello-dolly.zip',
'https://downloads.wordpress.org/plugin/gutenberg.17.7.0.zip',
] )
->withTheme( 'https://downloads.wordpress.org/theme/pendant.zip' )
// ->withContent( 'https://raw.githubusercontent.com/WordPress/theme-test-data/master/themeunittestdata.wordpress.xml' )
->withSiteUrl( 'http://localhost:8081' )
->andRunSQL( <<<'SQL'
CREATE TABLE `tmp_table` ( id INT );
INSERT INTO `tmp_table` VALUES (1);
INSERT INTO `tmp_table` VALUES (2);
SQL
)
->withFile( 'wordpress.txt', 'Data' )
// ->withSiteOptions( [
// 'blogname' => 'My Playground Blog',
// ] )
// ->withWpConfigConstants( [
// 'WP_DEBUG' => true,
// 'WP_DEBUG_LOG' => true,
// 'WP_DEBUG_DISPLAY' => true,
// 'WP_CACHE' => true,
// ] )
// ->withPlugins( [
// // Required for withContent():
// 'https://downloads.wordpress.org/plugin/wordpress-importer.zip',
// 'https://downloads.wordpress.org/plugin/hello-dolly.zip',
// 'https://downloads.wordpress.org/plugin/gutenberg.17.7.0.zip',
// ] )
// ->withTheme( 'https://downloads.wordpress.org/theme/pendant.zip' )
//// ->withContent( 'https://raw.githubusercontent.com/WordPress/theme-test-data/master/themeunittestdata.wordpress.xml' )
// ->withSiteUrl( 'http://localhost:8081' )
// ->andRunSQL( <<<'SQL'
//CREATE TABLE `tmp_table` ( id INT );
//INSERT INTO `tmp_table` VALUES (1);
//INSERT INTO `tmp_table` VALUES (2);
//SQL
// )
// ->withFile( 'wordpress.txt', 'Data' )
->toBlueprint();

$subscriber = new class implements EventSubscriberInterface {
Expand Down
1 change: 1 addition & 0 deletions src/WordPress/AsyncHttp/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public function process_queue() {
foreach ( $streams as $k => $stream ) {
$request = $enqueued[ $k ];
$total = $headers[ $k ]['content-length'];
// $total = $headers[ $k ]['content-length'] ?: 5 * 1024 * 1024;
$this->requests[ $request ]->state = RequestInfo::STATE_STREAMING;
$this->requests[ $request ]->stream = stream_monitor_progress(
$stream,
Expand Down
4 changes: 3 additions & 1 deletion src/WordPress/AsyncHttp/StreamWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class StreamWrapper extends VanillaStreamWrapper {

protected function initialize() {
if ( ! $this->stream ) {
$this->stream = $this->client->get_stream( $this->wrapper_data->request );
$request = $this->wrapper_data->request;

$this->stream = $this->client->get_stream($request);
}
}

Expand Down
15 changes: 7 additions & 8 deletions src/WordPress/AsyncHttp/async_http_streams.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,13 @@ function streams_send_http_requests( array $requests ) {
foreach ( array_keys( $responses ) as $k ) {
$response_statuses[ $k ] = $responses[ $k ]['status'];
$code = $response_statuses[ $k ]['code'];
if ( $code > 399 || $code < 200 ) {
// an optional step's resource should be able to fail the download, but do not
// fail the whole process

// ok for now, would recommend passing code and setting appropriate status RequestInfo::STATE_FAILED
throw new Exception( 'Failed to download file ' . $requests[ $k ]->url . ': Server responded with HTTP code ' . $code );
// still
}
// if ( $code > 399 || $code < 200 ) {
// // an optional step's resource should be able to fail the download, but do not
// // fail the whole process
//
// // ok for now, would recommend passing code and setting appropriate status RequestInfo::STATE_FAILED
// throw new Exception( 'Failed to download file ' . $requests[ $k ]->url . ': Server responded with HTTP code ' . $code );
// }

$response_headers[ $k ] = $responses[ $k ]['headers'];
if ( isset( $response_headers[ $k ]['location'] ) ) {
Expand Down
7 changes: 4 additions & 3 deletions src/WordPress/Blueprints/BlueprintParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public function __construct(
* @return Blueprint
* @throws InvalidArgumentException if unsupported input type or json string can not be decoded
*/
public function parse( $raw_blueprint ) {
public function parse( $raw_blueprint ): Blueprint
{
if ( $raw_blueprint instanceof stdClass ) {
return $this->fromObject( $raw_blueprint );
}
Expand All @@ -60,7 +61,7 @@ public function parse( $raw_blueprint ) {
/**
* @param stdClass $data
*/
public function fromObject( $data ) {
public function fromObject( $data ): Blueprint {
$result = $this->validator->validate( $data );
if ( ! $result->isValid() ) {
print_r( ( new ErrorFormatter() )->format( $result->error() ) );
Expand All @@ -72,7 +73,7 @@ public function fromObject( $data ) {
/**
* @param \WordPress\Blueprints\Model\DataClass\Blueprint $blueprint
*/
public function fromBlueprint( $blueprint ) {
public function fromBlueprint( $blueprint ): Blueprint {
$result = $this->validator->validate( $blueprint );
if ( ! $result->isValid() ) {
print_r( ( new ErrorFormatter() )->format( $result->error() ) );
Expand Down
2 changes: 2 additions & 0 deletions src/WordPress/Blueprints/Runner/Blueprint/BlueprintRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use WordPress\Blueprints\Compile\CompiledBlueprint;
use WordPress\Blueprints\Compile\CompiledStep;
use WordPress\Blueprints\Compile\StepSuccess;
use WordPress\Blueprints\Resources\ResourceManager;
use WordPress\Blueprints\Runtime\RuntimeInterface;

class BlueprintRunner {
Expand All @@ -29,6 +30,7 @@ public function __construct(
*/
public function run( $blueprint ) {
$resourceManagerFactory = $this->resourceManagerFactory;
/** @var ResourceManager $resourceManager */
$resourceManager = $resourceManagerFactory();
$resourceManager->enqueue(
$blueprint->compiledResources
Expand Down
3 changes: 3 additions & 0 deletions src/WordPress/Blueprints/Runner/Step/BaseStepRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use WordPress\Blueprints\Runtime\RuntimeInterface;

abstract class BaseStepRunner implements StepRunnerInterface {
/**
* @var ResourceManager $resourceManager;
*/
protected $resourceManager;

protected $runtime;
Expand Down
11 changes: 9 additions & 2 deletions src/WordPress/Blueprints/Runner/Step/InstallAssetStepRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use WordPress\Blueprints\Model\DataClass\InstallPluginStep;
use WordPress\Blueprints\Progress\Tracker;
use WordPress\Blueprints\Runner\Blueprint\BlueprintRunnerException;
use function WordPress\Blueprints\list_files;
use function WordPress\Blueprints\move_files_from_directory_to_directory;
use function WordPress\Zip\zip_extract_to;
Expand All @@ -15,9 +16,15 @@ protected function unzipAssetTo( $zipResource, $targetPath ) {
if ( ! file_exists( $targetPath ) ) {
mkdir( $targetPath, 0777, true );
}

$resource = $this->getResource($zipResource);
if ( $resource === 'VERY_BAD' ) {
throw new BlueprintRunnerException("Resource not available, because: VERY_BAD");
}

$this->getRuntime()->withTemporaryDirectory(
function ( $tmpPath ) use ( $zipResource, $targetPath ) {
zip_extract_to( $this->getResource( $zipResource ), $tmpPath );
function ( $tmpPath ) use ( $resource, $targetPath ) {
zip_extract_to( $resource, $tmpPath );
$extractedFiles = list_files( $tmpPath, $omitDotFiles = true );
$onlyExtractedSingleDirectory = count( $extractedFiles ) === 1 && is_dir( $tmpPath . '/' . $extractedFiles[0] );
$moveFromPath = $onlyExtractedSingleDirectory ? "$tmpPath/$extractedFiles[0]" : $tmpPath;
Expand Down
9 changes: 9 additions & 0 deletions tests/e2e/BlueprintRunnerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace e2e;

use E2ETestCase;

class BlueprintRunnerTest extends E2ETestCase {

}
6 changes: 3 additions & 3 deletions tests/e2e/ShorthandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function after() {
}

/**
* @dataProvider blueprint_with_word_press_version
* @dataProvider blueprint_with_wp_version
* @param string|stdClass|Blueprint $raw_blueprint
*/
public function testRunningBlueprintWithWordPressVersion(
Expand All @@ -66,7 +66,7 @@ public function testRunningBlueprintWithWordPressVersion(
// For PHP <=7.3 the success message is prefixed with: '#!/usr/bin/env php'
self::assertStringContainsString( $expected_result, $step_result );

$expected_steps = TestConstants::prepare_steps_from_shorthand_word_press_version();
$expected_steps = TestConstants::prepare_steps_from_shorthand_wp_version();

foreach ( $results as $key => $result ) {
self::assertEquals( $result->step, $expected_steps[$key] );
Expand All @@ -78,7 +78,7 @@ public function testRunningBlueprintWithWordPressVersion(
*
* @return array
*/
public function blueprint_with_word_press_version() {
public static function blueprint_with_wp_version(): array {
$json_string = '{"WordPressVersion":"https://wordpress.org/latest.zip"}';

$json_std_class = json_decode( $json_string );
Expand Down
Loading

0 comments on commit ee4bcf6

Please sign in to comment.