Skip to content

Commit

Permalink
Merge pull request #177 from woocommerce/24-06/woo-and-plugin-woocomm…
Browse files Browse the repository at this point in the history
…erce

Fix issue with "--plugins=woocommerce" and "--woo" parameter
  • Loading branch information
Luc45 authored Jun 17, 2024
2 parents 77d0514 + fbec564 commit f1eac23
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 5 deletions.
8 changes: 8 additions & 0 deletions _tests/custom_tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@

1. Append "UPDATE_SNAPSHOTS" env var, eg: `UPDATE_SNAPSHOTS=true ./vendor/bin/paratest`

### Running a single file

1. `./vendor/bin/phpunit tests/RunE2ETest.php`

### Running a single test

1. `./vendor/bin/phpunit tests/RunE2ETest.php --filter=test_cannot_use_woo_and_plugin_woocommerce`

### How it works

1. The tests are regular PHPUnit tests
Expand Down
32 changes: 32 additions & 0 deletions _tests/custom_tests/tests/RunE2ETest.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,36 @@ public function test_playwright_config_override() {

$this->assertMatchesNormalizedSnapshot( $output );
}

public function test_cannot_use_woo_and_plugin_woocommerce() {
$output = qit( [
'run:e2e',
'automatewoo',
$this->scaffold_test(),
'--woo',
'8.6.2',
'--plugin',
'woocommerce',
],
[],
2
);

$output = $this->normalize_scaffolded_test_run_output( $output );

$this->assertMatchesNormalizedSnapshot( $output );
}

public function test_can_use_equal_signs() {
$output = qit( [
'run:e2e',
'automatewoo',
$this->scaffold_test(),
'--plugin=woocommerce',
] );

$output = $this->normalize_scaffolded_test_run_output( $output );

$this->assertMatchesNormalizedSnapshot( $output );
}
}
3 changes: 3 additions & 0 deletions _tests/custom_tests/tests/Traits/SnapshotHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public function assertMatchesNormalizedSnapshot( string $actual, ?\Spatie\Snapsh
continue;
}

// Normalize "woocommerce.8.8.5.zip" or "woocommerce.8.8.5-RC1.zip", etc to "woocommerce.VERSION.zip"
$line = preg_replace( '/woocommerce\.[^ ]+\.zip/', 'woocommerce.VERSION.zip', $line );

// Normalize lines.
$normalized_spaces .= trim( $line ) . "\n";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Downloading plugins and themes...
No test tag "default" found for extension "woocommerce".
Setting up Docker...
Setting up WordPress...
Activating plugins...
Environment ready.

Bootstrapping Plugins
Bootstrapping automatewoo /qit/tests/e2e/automatewoo/local/bootstrap/bootstrap.php
Bootstrapping automatewoo /qit/tests/e2e/automatewoo/local/bootstrap/bootstrap.sh
Running E2E Tests
Running 1 test using 1 worker
[1/1] [automatewoo-local] › automatewoo/local/example.spec.js:9:5 › I can see my plugin menu
1 passed (TIME)
Test artifacts being saved to: /tmp-normalized/qit-results-normalizedid
Uploading zip...


[OK] Tests passed. Run 'qit e2e-report' to view the report.


Shutting down environment...

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cannot use "--woo" and "--plugin woocommerce" at the same time. Use one or another.

Binary file modified qit
Binary file not shown.
11 changes: 11 additions & 0 deletions src/src/Commands/CustomTests/RunE2ECommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ protected function execute( InputInterface $input, OutputInterface $output ): in
$source = $input->getOption( 'source' ) ?? $woo_extension;
$sut_action = $input->getOption( 'sut_action' );

// Prevent usage of "--woo" and "--plugin woocommerce" together.
if ( ! empty( $woocommerce_version ) && ! empty( $input->getOption( 'plugin' ) ) ) {
foreach ( $input->getOption( 'plugin' ) as $p ) {
if ( $p === 'woocommerce' ) {
$output->writeln( '<error>Both "--woo" and "--plugin woocommerce" cannot be used at the same time. Please use one or another when running the test.</error>' );

return Command::INVALID;
}
}
}

if ( ! empty( $pw_options ) ) {
// Remove wrapping double quotes if they exist.
if ( substr( $pw_options, 0, 1 ) === '"' && substr( $pw_options, - 1 ) === '"' ) {
Expand Down
6 changes: 6 additions & 0 deletions src/src/Commands/Environment/UpEnvironmentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,14 @@ protected function parse_options( InputInterface $input, bool $filter_to_send =
$found_override = false;

foreach ( $GLOBALS['argv'] as $arg ) {
// Remove leading dashes.
// Example: --woo=8.6.1 => woo=8.6.1.
$normalized_arg = ltrim( $arg, '-' );

// Extract the part before the equals sign if it exists.
// Example: woo=8.6.1 => woo.
$normalized_arg = preg_match( '/^([a-zA-Z0-9_]+)=/', $normalized_arg, $matches ) ? $matches[1] : $normalized_arg;

if ( $normalized_arg === $key || ( isset( $shortcuts[ $normalized_arg ] ) && $shortcuts[ $normalized_arg ] === $key ) ) {
$options_to_env_info['overrides'][ $key ] = $value;
$found_override = true;
Expand Down
10 changes: 5 additions & 5 deletions src/src/Environment/ExtensionDownload/Handlers/URLHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ public function maybe_download_extensions( array $extensions, string $cache_dir
throw new \InvalidArgumentException( 'We currently only support .zip URLs' );
}

// As version is "undefined", cache burst is shorter: Hour of the day (0-24).
$cache_burst = gmdate( 'G' );
// Cache burst: Day of the year (0-365), hour of the day (0-23), and current 5-minute interval of the hour (0-11).
// Effectively, this will cache-bust every 5 minutes.
$cache_burst = gmdate( 'z-G-' ) . floor( (int) gmdate( 'i' ) / 5 );

$cache_file = $this->make_cache_path( $cache_dir, $e->type, $e->slug, $e->version, $e->source, $cache_burst );

// Cache hit?
if ( file_exists( $cache_file ) ) {
if ( $output->isVeryVerbose() ) {
$output->writeln( "Using cached {$e->type} {$e->slug}." );
}
$output->writeln( "Using cached {$e->type} {$e->slug}." );

$e->downloaded_source = $cache_file;

continue;
Expand Down

0 comments on commit f1eac23

Please sign in to comment.