| @@ -1,88 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | declare( strict_types=1 ); |
| 4 | 4 | |
| 5 | -$args = $_SERVER['argv'] ?? []; | |
| 6 | - | |
| 7 | -$currentTestsuite = null; | |
| 8 | -$testsuiteIndex = array_search( '--testsuite', $args, true ); | |
| 9 | -if ( $testsuiteIndex !== false && isset( $args[ $testsuiteIndex + 1 ] ) ) { | |
| 10 | - $currentTestsuite = $args[ $testsuiteIndex + 1 ]; | |
| 11 | -} | |
| 12 | - | |
| 13 | -if ( $currentTestsuite === null ) { | |
| 14 | - foreach ( $args as $arg ) { | |
| 15 | - if ( strpos( $arg, '--testsuite=' ) === 0 ) { | |
| 16 | - $currentTestsuite = substr( $arg, strlen( '--testsuite=' ) ); | |
| 17 | - | |
| 18 | - break; | |
| 19 | - } | |
| 20 | - } | |
| 21 | -} | |
| 22 | - | |
| 23 | -$allowedTestsuites = [ 'unit', 'integration' ]; | |
| 24 | - | |
| 25 | -if ( ! in_array( $currentTestsuite, $allowedTestsuites, true ) ) { | |
| 26 | - die( "Invalid testsuite provided or testsuite detection failed.\n" ); | |
| 27 | -} | |
| 28 | - | |
| 29 | -if ( $currentTestsuite === 'unit' ) { | |
| 30 | - require_once __DIR__ . '/../vendor/autoload.php'; | |
| 31 | - require_once __DIR__ . '/../vendor/php-stubs/wordpress-stubs/wordpress-stubs.php'; | |
| 32 | - require_once __DIR__ . '/../vendor/php-stubs/woocommerce-stubs/woocommerce-stubs.php'; | |
| 33 | - require_once __DIR__ . '/../vendor/php-stubs/woocommerce-stubs/woocommerce-packages-stubs.php'; | |
| 34 | - require_once __DIR__ . '/../deps/scoper-autoload.php'; | |
| 35 | - require_once __DIR__ . '/../constants.php'; | |
| 36 | - // To import constants. | |
| 37 | - require_once __DIR__ . '/../vendor/szepeviktor/phpstan-wordpress/bootstrap.php'; | |
| 38 | -} | |
| 39 | - | |
| 40 | -if ( $currentTestsuite === 'integration' ) { | |
| 41 | - // TODO later: install demo web and plugin from zip | |
| 42 | - | |
| 43 | - function loadConfigFromInstallScript( $filePath ): array { | |
| 44 | - if ( ! file_exists( $filePath ) ) { | |
| 45 | - throw new RuntimeException( "Configuration file not found: $filePath" ); | |
| 46 | - } | |
| 47 | - | |
| 48 | - $content = file_get_contents( $filePath ); | |
| 49 | - if ( $content === false ) { | |
| 50 | - throw new RuntimeException( "Could not read configuration file: $filePath" ); | |
| 51 | - } | |
| 52 | - | |
| 53 | - $config = []; | |
| 54 | - $lines = explode( "\n", $content ); | |
| 55 | - | |
| 56 | - foreach ( $lines as $line ) { | |
| 57 | - if ( preg_match( '/^([A-Z_]+)="(.*)"$/', $line, $matches ) ) { | |
| 58 | - $config[ $matches[1] ] = $matches[2]; | |
| 59 | - } | |
| 60 | - } | |
| 61 | - | |
| 62 | - return $config; | |
| 63 | - } | |
| 64 | - | |
| 65 | - $demoInstallDirectory = __DIR__ . '/../cli/demo-install/'; | |
| 66 | - $demoInstallConfiguration = $demoInstallDirectory . 'install-wpwc.sh'; | |
| 67 | - if ( is_file( $demoInstallDirectory . 'install-wpwc.config.local.sh' ) ) { | |
| 68 | - $demoInstallConfiguration = $demoInstallDirectory . 'install-wpwc.config.local.sh'; | |
| 69 | - } | |
| 70 | - $configuration = loadConfigFromInstallScript( $demoInstallConfiguration ); | |
| 71 | - | |
| 72 | - if ( ! is_file( $configuration['NEW_WP_ROOT'] . '/wp-config.php' ) ) { | |
| 73 | - throw new RuntimeException( 'WordPress installation not found in ' . $configuration['NEW_WP_ROOT'] ); | |
| 74 | - } | |
| 75 | - | |
| 76 | - $pluginDir = $configuration['NEW_WP_ROOT'] . '/wp-content/plugins/packeta/'; | |
| 77 | - $mainPluginFile = $pluginDir . 'packeta.php'; | |
| 78 | - if ( ! is_file( $mainPluginFile ) ) { | |
| 79 | - throw new RuntimeException( 'Packeta plugin installation not found in ' . $configuration['NEW_WP_ROOT'] ); | |
| 80 | - } | |
| 81 | - | |
| 82 | - // Force WordPress to use the direct filesystem method instead of FTP - prevent `ftp_nlist(): Argument #1 ($ftp) must be of type FTP\Connection, null given` | |
| 83 | - if ( ! defined( 'FS_METHOD' ) ) { | |
| 84 | - define( 'FS_METHOD', 'direct' ); | |
| 85 | - } | |
| 86 | - | |
| 87 | - require_once $configuration['NEW_WP_ROOT'] . '/wp-load.php'; | |
| 88 | -} | |
| 5 | +require_once __DIR__ . '/../vendor/autoload.php'; | |
| 6 | +require_once __DIR__ . '/../vendor/php-stubs/wordpress-stubs/wordpress-stubs.php'; | |
| 7 | +require_once __DIR__ . '/../vendor/php-stubs/woocommerce-stubs/woocommerce-stubs.php'; | |
| 8 | +require_once __DIR__ . '/../vendor/php-stubs/woocommerce-stubs/woocommerce-packages-stubs.php'; | |
| 9 | +require_once __DIR__ . '/../deps/scoper-autoload.php'; | |
| 10 | +require_once __DIR__ . '/../constants.php'; | |
| 11 | +// To import constants. | |
| 12 | +require_once __DIR__ . '/../vendor/szepeviktor/phpstan-wordpress/bootstrap.php'; | |