Skip to content

Commit

Permalink
PHPUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
Luc45 committed Feb 28, 2024
1 parent e7ae62a commit bb1d7be
Show file tree
Hide file tree
Showing 18 changed files with 220 additions and 181 deletions.
12 changes: 10 additions & 2 deletions src/src/Environment/EnvironmentDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,20 @@ public function maybe_download( string $env_name ): void {
throw new \RuntimeException( 'E2E environment not set or incomplete.' );
}


if ( $this->cache->get( 'e2e_environment_hash' ) !== $backend_hashes[ $env_name ]['checksum'] ) {
if ( ! file_exists( Config::get_qit_dir() . '/environments' ) ) {
mkdir( Config::get_qit_dir() . '/environments' );
}
// Download the environment.
file_put_contents( sprintf( Config::get_qit_dir() . '/environments/%s.zip', $env_name ), file_get_contents( $backend_hashes[ $env_name ]['url'] ) );

if ( defined( 'UNIT_TESTS' ) ) {
if ( ! file_exists( sprintf( Config::get_qit_dir() . '/environments/%s.zip', $env_name ) ) ) {
throw new \RuntimeException( $env_name . ' environment not found for tests.' );
}
} else {
// Download the environment.
file_put_contents( sprintf( Config::get_qit_dir() . '/environments/%s.zip', $env_name ), file_get_contents( $backend_hashes[ $env_name ]['url'] ) );
}

// Extract the environment.
$zip = new \ZipArchive();
Expand Down
5 changes: 4 additions & 1 deletion src/src/Environment/EnvironmentMonitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ public function get(): array {
}

public function get_env_info_by_id( string $env_info_id ): EnvInfo {
if ( empty( $env_info_id ) ) {
throw new \Exception( 'Environment not found.' );
}
foreach ( $this->get() as $env_info ) {
if ( $env_info->env_id === $env_info_id ) {
if ( $env_info->env_id == $env_info_id ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
return $env_info;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/tests/EnvironmentMonitorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
class EnvironmentMonitorTest extends QITTestCase {
use \Spatie\Snapshots\MatchesSnapshots;

protected function make_env_info( string $identifier = 'foo' ): EnvInfo {
protected function make_env_info( string $identifier = 'foo', int $env_id = 1234567890 ): EnvInfo {
$env_info = new EnvInfo();
$env_info->type = 'e2e';
$env_info->temporary_env = "/path/to/temporary-envs/$identifier";
$env_info->env_id = $env_id;
$env_info->created_at = 1708728299;
$env_info->status = 'pending';

Expand Down Expand Up @@ -60,7 +61,7 @@ public function test_environment_stops_with_multiple() {
$updated->status = 'running';
$environment_monitor->environment_added_or_updated( $updated );

$environment_monitor->environment_stopped( $this->make_env_info() );
$environment_monitor->environment_stopped( $this->make_env_info( 'foo', 4567890 ) );

$this->assertMatchesJsonSnapshot( $environment_monitor->get() );
}
Expand Down
74 changes: 0 additions & 74 deletions src/tests/RestartEnvironmentTest.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"944daf0ddaaa9d7d9270b6ecacc8f83e": {
"1234567890": {
"type": "e2e",
"temporary_env": "\/path\/to\/temporary-envs\/foo",
"created_at": 1708728299,
"status": "pending",
"env_id": 1234567890,
"nginx_port": null,
"docker_images": null
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
{
"944daf0ddaaa9d7d9270b6ecacc8f83e": {
"type": "e2e",
"temporary_env": "\/path\/to\/temporary-envs\/foo",
"created_at": 1708728299,
"status": "pending",
"docker_images": null
},
"d7714310314d312ed7809de78d6fea27": {
"1234567890": {
"type": "e2e",
"temporary_env": "\/path\/to\/temporary-envs\/bar",
"created_at": 1708728299,
"status": "pending",
"env_id": 1234567890,
"nginx_port": null,
"docker_images": null
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"d7714310314d312ed7809de78d6fea27": {
"1234567890": {
"type": "e2e",
"temporary_env": "\/path\/to\/temporary-envs\/bar",
"created_at": 1708728299,
"status": "running",
"env_id": 1234567890,
"nginx_port": null,
"docker_images": null
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"944daf0ddaaa9d7d9270b6ecacc8f83e": {
"1234567890": {
"type": "e2e",
"temporary_env": "\/path\/to\/temporary-envs\/foo",
"created_at": 1708728299,
"status": "running",
"env_id": 1234567890,
"nginx_port": null,
"docker_images": null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
"temporary_env": "\/path\/to\/temporary-envs\/foo",
"created_at": 1708728299,
"status": "pending",
"env_id": 1234567890,
"nginx_port": null,
"docker_images": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"description": "The WordPress version to use in the test.",
"type": "string",
"enum": [
"6.5-beta2",
"6.5-beta3",
"6.1.5",
"6.2.4",
"6.3.3",
Expand All @@ -63,7 +63,7 @@
"description": "The WooCommerce version to use in the test.",
"type": "string",
"enum": [
"8.6.0-rc.1",
"8.7.0-beta.1",
"8.5.1",
"8.5.2",
"8.6.0",
Expand Down Expand Up @@ -118,7 +118,7 @@
"description": "The WordPress version to use in the test.",
"type": "string",
"enum": [
"6.5-beta2",
"6.5-beta3",
"6.1.5",
"6.2.4",
"6.3.3",
Expand All @@ -132,7 +132,7 @@
"description": "The WooCommerce version to use in the test.",
"type": "string",
"enum": [
"8.6.0-rc.1",
"8.7.0-beta.1",
"8.5.1",
"8.5.2",
"8.6.0",
Expand Down Expand Up @@ -216,7 +216,7 @@
"description": "The WordPress version to use in the test.",
"type": "string",
"enum": [
"6.5-beta2",
"6.5-beta3",
"6.1.5",
"6.2.4",
"6.3.3",
Expand All @@ -230,7 +230,7 @@
"description": "The WooCommerce version to use in the test.",
"type": "string",
"enum": [
"8.6.0-rc.1",
"8.7.0-beta.1",
"8.5.1",
"8.5.2",
"8.6.0",
Expand Down Expand Up @@ -472,7 +472,7 @@
"description": "The WordPress version to use in the test.",
"type": "string",
"enum": [
"6.5-beta2",
"6.5-beta3",
"6.1.5",
"6.2.4",
"6.3.3",
Expand Down Expand Up @@ -588,7 +588,7 @@
"description": "The WordPress version to use in the test.",
"type": "string",
"enum": [
"6.5-beta2",
"6.5-beta3",
"6.1.5",
"6.2.4",
"6.3.3",
Expand Down Expand Up @@ -703,7 +703,7 @@
"description": "The WordPress version to use in the test.",
"type": "string",
"enum": [
"6.5-beta2",
"6.5-beta3",
"6.1.5",
"6.2.4",
"6.3.3",
Expand Down Expand Up @@ -829,7 +829,7 @@
"description": "The WordPress version to use in the test.",
"type": "string",
"enum": [
"6.5-beta2",
"6.5-beta3",
"6.1.5",
"6.2.4",
"6.3.3",
Expand Down Expand Up @@ -963,7 +963,7 @@
"default": "stable",
"type": "string",
"enum": [
"8.6.0-rc.1",
"8.7.0-beta.1",
"8.5.1",
"8.5.2",
"8.6.0",
Expand All @@ -977,7 +977,7 @@
"default": "stable",
"type": "string",
"enum": [
"6.5-beta2",
"6.5-beta3",
"6.1.5",
"6.2.4",
"6.3.3",
Expand Down Expand Up @@ -1121,7 +1121,20 @@
}
],
"environments": {
"e2e": "37fa32aea1dd90c4bbc87fa0c78d03cf"
"e2e": {
"url": "http:\/\/qit.test:8081\/wp-content\/uploads\/environments\/8652cdd0d3e37728784a84446b2a4b0d.zip",
"checksum": "8652cdd0d3e37728784a84446b2a4b0d"
}
},
"versions": {
"woocommerce": {
"stable": "8.6.1",
"rc": "8.7.0-beta.1"
},
"wordpress": {
"stable": "6.4.3",
"rc": "6.5-beta3"
}
},
"hide_e2e": false
}
Expand Down
Loading

0 comments on commit bb1d7be

Please sign in to comment.