diff --git a/.github/workflows/build-35.yml b/.github/workflows/build-35.yml index 56ce6c633..e592ab266 100644 --- a/.github/workflows/build-35.yml +++ b/.github/workflows/build-35.yml @@ -19,26 +19,64 @@ jobs: run: composer validate --no-interaction --strict - name: Install dependencies uses: ramsey/composer-install@v2 - - name: "Check PSR-4 mapping" - run: "composer dump-autoload --no-interaction --optimize --strict-psr" - - name: "Require rector" - run: "composer require --dev rector/rector" - - name: Build v3.5 - run: | - vendor/bin/rector --config=config/rector-35.php - - name: Create Pull Request - uses: peter-evans/create-pull-request@v5 + - name: Check PSR-4 mapping" + run: composer dump-autoload --no-interaction --optimize --strict-psr + - name: Require rector + run: composer require --dev rector/rector + - name: Get changed files + id: changed-files + uses: yumemi-inc/changed-files@v3 with: - base: "v3.5" - token: ${{ secrets.V35_BUILD_TOKEN }} - commit-message: "v3.5 automated build change" - committer: "lucatume " - branch: "v3.5-automated-build" - delete-branch: true - title: "v3.5 automated build" - body: "v3.5 automated build changes created by the v3.5 automated build workflow" - assignees: "lucatume" - add-paths: | - includes/*.php - src/*.php - tests/*.php + separator: " " + patterns: | + src/**/*.php + includes/**/*.php + tests/**/*.php + - name: Transpile to v3.5 + run: | + vendor/bin/rector process --config=config/rector-35.php -- ${{ steps.changed-files.outputs.files }} + - name: Set up git credentials + run: | + git config --global user.name "Luca Tumedei" + git config --global user.email "luca@theaveragedev.com" + - name: Save changes to stash + run: | + git stash push --include-untracked -- 'src/*.php' 'includes/*.php' 'tests/*.php' + - name: Reset HEAD + run: | + git reset HEAD --hard + - name: Checkout v3.5 from origin + run: | + git fetch origin + git checkout v3.5 + git pull origin v3.5 + - name: Remove the v3.5-auto-build-from-v4 branch from origin if it exists + run: | + git push origin --delete v3.5-auto-build-from-v4 || true + - name: Create auto-build branch from v3.5 + run: | + git checkout -B v3.5-auto-build-from-v4 + git push origin v3.5-auto-build-from-v4 + - name: Checkout the changed files from the HEAD branch + run: | + git checkout ${{ github.sha }} -- ${{ steps.changed-files.outputs.files }} + - name: Pop changes from stash and commit them + run: | + git stash pop || true + git add -- 'src/*.php' 'includes/*.php' 'tests/*.php' + git commit -m "v3.5 auto-build from v4" + - name: Push changes to v3.5-auto-build-from-v4 + run: | + git push origin v3.5-auto-build-from-v4 --force + - name: Create Pull Request on v3.5 + run: | + gh pr create \ + --base v3.5 \ + --draft \ + --assignee lucatume \ + --title "v4 -> v3.5 auto-build" \ + --body "v3.5 automated build changes from v4" \ + --label "auto-build" \ + --label "v3.5" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/composer.json b/composer.json index 9aaf3c445..e1fcc1ab7 100644 --- a/composer.json +++ b/composer.json @@ -47,7 +47,7 @@ "phpstan/extension-installer": "^1.3", "phpstan/phpstan-symfony": "^1.3", "squizlabs/php_codesniffer": "^3.7", - "rector/rector": "^0.18.5" + "rector/rector": "^0.18.12" }, "autoload": { "psr-4": { diff --git a/tests/unit/lucatume/WPBrowser/Events/Module/WPLoaderTest.php b/tests/unit/lucatume/WPBrowser/Events/Module/WPLoaderTest.php index 5ac694ea1..090902dfb 100644 --- a/tests/unit/lucatume/WPBrowser/Events/Module/WPLoaderTest.php +++ b/tests/unit/lucatume/WPBrowser/Events/Module/WPLoaderTest.php @@ -28,20 +28,13 @@ use lucatume\WPBrowser\WordPress\InstallationException; use lucatume\WPBrowser\WordPress\InstallationState\InstallationStateInterface; use lucatume\WPBrowser\WordPress\InstallationState\Scaffolded; -use PHPUnit\Framework\AssertionFailedError; +use PHPUnit\Framework\Assert; use PHPUnit\Framework\TestResult; use stdClass; use tad\Codeception\SnapshotAssertions\SnapshotAssertions; use UnitTester; use WP_Theme; -use function PHPUnit\Framework\assertEquals; -use function PHPUnit\Framework\assertFalse; -use function PHPUnit\Framework\assertFileExists; -use function PHPUnit\Framework\assertInstanceOf; -use function PHPUnit\Framework\assertNotEquals; -use function PHPUnit\Framework\assertTrue; - use const ABSPATH; use const WP_DEBUG; @@ -204,8 +197,8 @@ public function should_allow_specifying_the_wp_root_folder_as_a_relative_path_to $this->assertInIsolation(static function () use ($rootDir, $wpLoader1) { chdir($rootDir); $wpLoader1->_initialize(); - assertEquals($rootDir . '/test/wordpress/', $wpLoader1->_getConfig('wpRootFolder')); - assertEquals($rootDir . '/test/wordpress/', $wpLoader1->getWpRootFolder()); + Assert::assertEquals($rootDir . '/test/wordpress/', $wpLoader1->_getConfig('wpRootFolder')); + Assert::assertEquals($rootDir . '/test/wordpress/', $wpLoader1->getWpRootFolder()); }, $rootDir); $this->config = [ @@ -221,8 +214,8 @@ public function should_allow_specifying_the_wp_root_folder_as_a_relative_path_to $this->assertInIsolation(static function () use ($rootDir, $wpLoader2) { chdir($rootDir); $wpLoader2->_initialize(); - assertEquals($rootDir . '/test/wordpress/', $wpLoader2->_getConfig('wpRootFolder')); - assertEquals($rootDir . '/test/wordpress/', $wpLoader2->getWpRootFolder()); + Assert::assertEquals($rootDir . '/test/wordpress/', $wpLoader2->_getConfig('wpRootFolder')); + Assert::assertEquals($rootDir . '/test/wordpress/', $wpLoader2->getWpRootFolder()); }, $rootDir); } @@ -251,8 +244,8 @@ public function should_allow_specifying_the_wp_root_folder_including_the_home_sy $_SERVER['HOME'] = $homeDir; $wpLoader->_initialize(); - assertEquals($homeDir . '/projects/work/acme/wordpress/', $wpLoader->_getConfig('wpRootFolder')); - assertEquals($homeDir . '/projects/work/acme/wordpress/', $wpLoader->getWpRootFolder()); + Assert::assertEquals($homeDir . '/projects/work/acme/wordpress/', $wpLoader->_getConfig('wpRootFolder')); + Assert::assertEquals($homeDir . '/projects/work/acme/wordpress/', $wpLoader->getWpRootFolder()); }); } @@ -278,8 +271,8 @@ public function should_allow_specifying_the_wp_root_folder_as_an_absolute_path() $this->assertInIsolation(static function () use ($wpRootDir, $wpLoader) { $wpLoader->_initialize(); - assertEquals($wpRootDir . '/', $wpLoader->_getConfig('wpRootFolder')); - assertEquals($wpRootDir . '/', $wpLoader->getWpRootFolder()); + Assert::assertEquals($wpRootDir . '/', $wpLoader->_getConfig('wpRootFolder')); + Assert::assertEquals($wpRootDir . '/', $wpLoader->getWpRootFolder()); }); } @@ -305,8 +298,8 @@ public function should_allow_specifying_the_wp_root_folder_as_absolute_path_with $this->assertInIsolation(static function () use ($wpRootDir, $wpLoader) { $wpLoader->_initialize(); - assertEquals($wpRootDir . '/Word Press/', $wpLoader->_getConfig('wpRootFolder')); - assertEquals($wpRootDir . '/Word Press/', $wpLoader->getWpRootFolder()); + Assert::assertEquals($wpRootDir . '/Word Press/', $wpLoader->_getConfig('wpRootFolder')); + Assert::assertEquals($wpRootDir . '/Word Press/', $wpLoader->getWpRootFolder()); }); } @@ -331,7 +324,7 @@ public function should_scaffold_the_installation_if_the_wp_root_folder_is_empty( $this->assertInIsolation(static function () use ($wpLoader) { $wpLoader->_initialize(); - assertInstanceOf(Scaffolded::class, $wpLoader->getInstallation()->getState()); + Assert::assertInstanceOf(Scaffolded::class, $wpLoader->getInstallation()->getState()); }); } @@ -363,14 +356,14 @@ public function should_read_salts_from_configured_installation(): void $wpLoader->_initialize(); $installation = $wpLoader->getInstallation(); - assertEquals($installation->getAuthKey(), $wpLoader->_getConfig('AUTH_KEY')); - assertEquals($installation->getSecureAuthKey(), $wpLoader->_getConfig('SECURE_AUTH_KEY')); - assertEquals($installation->getLoggedInKey(), $wpLoader->_getConfig('LOGGED_IN_KEY')); - assertEquals($installation->getNonceKey(), $wpLoader->_getConfig('NONCE_KEY')); - assertEquals($installation->getAuthSalt(), $wpLoader->_getConfig('AUTH_SALT')); - assertEquals($installation->getSecureAuthSalt(), $wpLoader->_getConfig('SECURE_AUTH_SALT')); - assertEquals($installation->getLoggedInSalt(), $wpLoader->_getConfig('LOGGED_IN_SALT')); - assertEquals($installation->getNonceSalt(), $wpLoader->_getConfig('NONCE_SALT')); + Assert::assertEquals($installation->getAuthKey(), $wpLoader->_getConfig('AUTH_KEY')); + Assert::assertEquals($installation->getSecureAuthKey(), $wpLoader->_getConfig('SECURE_AUTH_KEY')); + Assert::assertEquals($installation->getLoggedInKey(), $wpLoader->_getConfig('LOGGED_IN_KEY')); + Assert::assertEquals($installation->getNonceKey(), $wpLoader->_getConfig('NONCE_KEY')); + Assert::assertEquals($installation->getAuthSalt(), $wpLoader->_getConfig('AUTH_SALT')); + Assert::assertEquals($installation->getSecureAuthSalt(), $wpLoader->_getConfig('SECURE_AUTH_SALT')); + Assert::assertEquals($installation->getLoggedInSalt(), $wpLoader->_getConfig('LOGGED_IN_SALT')); + Assert::assertEquals($installation->getNonceSalt(), $wpLoader->_getConfig('NONCE_SALT')); }); } @@ -396,9 +389,9 @@ public function should_allow_getting_paths_from_the_wp_root_folder(): void $this->assertInIsolation(static function () use ($wpRootDir, $wpLoader) { $wpLoader->_initialize(); - assertEquals($wpRootDir . '/foo-bar', $wpLoader->getWpRootFolder('foo-bar')); - assertEquals($wpRootDir . '/foo-bar/baz', $wpLoader->getWpRootFolder('foo-bar/baz')); - assertEquals($wpRootDir . '/wp-config.php', $wpLoader->getWpRootFolder('wp-config.php')); + Assert::assertEquals($wpRootDir . '/foo-bar', $wpLoader->getWpRootFolder('foo-bar')); + Assert::assertEquals($wpRootDir . '/foo-bar/baz', $wpLoader->getWpRootFolder('foo-bar/baz')); + Assert::assertEquals($wpRootDir . '/wp-config.php', $wpLoader->getWpRootFolder('wp-config.php')); }); } @@ -435,9 +428,9 @@ public function should_set_some_default_values_for_salt_keys(): void ]; foreach ($var as $i => $key) { if ($i > 0) { - assertNotEquals($var[$i - 1], $wpLoader->_getConfig($key)); + Assert::assertNotEquals($var[$i - 1], $wpLoader->_getConfig($key)); } - assertEquals(64, strlen($wpLoader->_getConfig($key))); + Assert::assertEquals(64, strlen($wpLoader->_getConfig($key))); } }); } @@ -463,7 +456,7 @@ public function should_load_config_files_if_set(): void $this->assertInIsolation(static function () use ($wpLoader) { $wpLoader->_initialize(); - assertEquals('test_file_001.php', getenv('LOADED')); + Assert::assertEquals('test_file_001.php', getenv('LOADED')); }); $this->config = [ @@ -483,8 +476,8 @@ public function should_load_config_files_if_set(): void $this->assertInIsolation(static function () use ($wpLoader) { $wpLoader->_initialize(); - assertEquals(getenv('LOADED_2'), 'test_file_002.php'); - assertEquals(getenv('LOADED_3'), 'test_file_003.php'); + Assert::assertEquals(getenv('LOADED_2'), 'test_file_002.php'); + Assert::assertEquals(getenv('LOADED_3'), 'test_file_003.php'); }); } @@ -512,10 +505,10 @@ public function should_throw_if_config_files_do_not_exist(): void try { $wpLoader->_initialize(); } catch (Exception $e) { - assertInstanceOf(ModuleConfigException::class, $e); + Assert::assertInstanceOf(ModuleConfigException::class, $e); $captured = true; } - assertTrue($captured); + Assert::assertTrue($captured); }); $this->config = [ @@ -700,8 +693,8 @@ public function should_load_word_press_before_suite_if_load_only_w_config_files( $this->assertInIsolation(static function () use ($wpRootDir, $wpLoader) { $wpLoader->_initialize(); - assertEquals('', getenv('LOADED_2')); - assertFalse(defined('ABSPATH')); + Assert::assertEquals('', getenv('LOADED_2')); + Assert::assertFalse(defined('ABSPATH')); $actions = []; Dispatcher::addListener(WPLoader::EVENT_BEFORE_LOADONLY, static function () use (&$actions) { @@ -713,13 +706,13 @@ public function should_load_word_press_before_suite_if_load_only_w_config_files( Dispatcher::dispatch(Events::SUITE_BEFORE); - assertEquals('test_file_002.php', getenv('LOADED_2')); - assertEquals($wpRootDir . '/', ABSPATH); - assertEquals([ + Assert::assertEquals('test_file_002.php', getenv('LOADED_2')); + Assert::assertEquals($wpRootDir . '/', ABSPATH); + Assert::assertEquals([ WPLoader::EVENT_BEFORE_LOADONLY, WPLoader::EVENT_AFTER_LOADONLY, ], $actions); - assertInstanceOf(FactoryStore::class, $wpLoader->factory()); + Assert::assertInstanceOf(FactoryStore::class, $wpLoader->factory()); }); } @@ -803,7 +796,7 @@ public function should_not_throw_when_load_only_true_and_using_db_module( Dispatcher::dispatch(Events::SUITE_BEFORE); - assertEquals($wpRootDir . '/', ABSPATH); + Assert::assertEquals($wpRootDir . '/', ABSPATH); }); } @@ -944,11 +937,11 @@ public function should_should_install_and_bootstrap_single_site_using_constants_ $this->assertInIsolation(static function () use ($wpLoader, $wpRootDir) { $wpLoader->_initialize(); - assertEquals('test_file_001.php', getenv('LOADED')); - assertEquals('test_file_002.php', getenv('LOADED_2')); - assertEquals($wpRootDir . '/', ABSPATH); - assertTrue(defined('WP_DEBUG')); - assertTrue(WP_DEBUG); + Assert::assertEquals('test_file_001.php', getenv('LOADED')); + Assert::assertEquals('test_file_002.php', getenv('LOADED_2')); + Assert::assertEquals($wpRootDir . '/', ABSPATH); + Assert::assertTrue(defined('WP_DEBUG')); + Assert::assertTrue(WP_DEBUG); }); } @@ -1038,31 +1031,31 @@ public function should_install_and_bootstrap_single_installation(): void if (PHP_VERSION >= 7.4) { $expectedActivePlugins[] = 'woocommerce/woocommerce.php'; } - assertEquals($expectedActivePlugins, get_option('active_plugins')); - assertEquals([ + Assert::assertEquals($expectedActivePlugins, get_option('active_plugins')); + Assert::assertEquals([ 'before_install', 'after_install', ], $actions); - assertEquals('twentytwenty', get_option('template')); - assertEquals('twentytwenty', get_option('stylesheet')); - assertEquals('test_file_001.php', getenv('LOADED')); - assertEquals('test_file_002.php', getenv('LOADED_2')); - assertEquals($wpRootDir . '/', ABSPATH); - assertTrue(defined('WP_DEBUG')); - assertTrue(WP_DEBUG); - assertInstanceOf(\wpdb::class, $GLOBALS['wpdb']); - assertFalse(is_multisite()); - assertEquals($wpRootDir . '/wp-content/', $wpLoader->getContentFolder()); - assertEquals($wpRootDir . '/wp-content/some/path', $wpLoader->getContentFolder('some/path')); - assertEquals( + Assert::assertEquals('twentytwenty', get_option('template')); + Assert::assertEquals('twentytwenty', get_option('stylesheet')); + Assert::assertEquals('test_file_001.php', getenv('LOADED')); + Assert::assertEquals('test_file_002.php', getenv('LOADED_2')); + Assert::assertEquals($wpRootDir . '/', ABSPATH); + Assert::assertTrue(defined('WP_DEBUG')); + Assert::assertTrue(WP_DEBUG); + Assert::assertInstanceOf(\wpdb::class, $GLOBALS['wpdb']); + Assert::assertFalse(is_multisite()); + Assert::assertEquals($wpRootDir . '/wp-content/', $wpLoader->getContentFolder()); + Assert::assertEquals($wpRootDir . '/wp-content/some/path', $wpLoader->getContentFolder('some/path')); + Assert::assertEquals( $wpRootDir . '/wp-content/some/path/some-file.php', $wpLoader->getContentFolder('some/path/some-file.php') ); - assertEquals( + Assert::assertEquals( $wpRootDir . '/wp-content/plugins/some-file.php', $wpLoader->getPluginsFolder('/some-file.php') ); - assertEquals( + Assert::assertEquals( $wpRootDir . '/wp-content/themes/some-file.php', $wpLoader->getThemesFolder('/some-file.php') ); @@ -1129,32 +1122,32 @@ public function should_install_and_bootstrap_multisite_installation(): void if (PHP_VERSION >= 7.4) { $expectedActivePlugins[] = 'woocommerce/woocommerce.php'; } - assertEquals($expectedActivePlugins, array_keys(get_site_option('active_sitewide_plugins'))); - assertEquals([ + Assert::assertEquals($expectedActivePlugins, array_keys(get_site_option('active_sitewide_plugins'))); + Assert::assertEquals([ 'before_install', 'after_install', ], $actions); - assertEquals('twentytwenty', get_option('template')); - assertEquals('twentytwenty', get_option('stylesheet')); - assertEquals(['twentytwenty' => true], WP_Theme::get_allowed()); - assertEquals('test_file_001.php', getenv('LOADED')); - assertEquals('test_file_002.php', getenv('LOADED_2')); - assertEquals($wpRootDir . '/', ABSPATH); - assertTrue(defined('WP_DEBUG')); - assertTrue(WP_DEBUG); - assertInstanceOf(\wpdb::class, $GLOBALS['wpdb']); - assertTrue(is_multisite()); - assertEquals($wpRootDir . '/wp-content/', $wpLoader->getContentFolder()); - assertEquals($wpRootDir . '/wp-content/some/path', $wpLoader->getContentFolder('some/path')); - assertEquals( + Assert::assertEquals('twentytwenty', get_option('template')); + Assert::assertEquals('twentytwenty', get_option('stylesheet')); + Assert::assertEquals(['twentytwenty' => true], WP_Theme::get_allowed()); + Assert::assertEquals('test_file_001.php', getenv('LOADED')); + Assert::assertEquals('test_file_002.php', getenv('LOADED_2')); + Assert::assertEquals($wpRootDir . '/', ABSPATH); + Assert::assertTrue(defined('WP_DEBUG')); + Assert::assertTrue(WP_DEBUG); + Assert::assertInstanceOf(\wpdb::class, $GLOBALS['wpdb']); + Assert::assertTrue(is_multisite()); + Assert::assertEquals($wpRootDir . '/wp-content/', $wpLoader->getContentFolder()); + Assert::assertEquals($wpRootDir . '/wp-content/some/path', $wpLoader->getContentFolder('some/path')); + Assert::assertEquals( $wpRootDir . '/wp-content/some/path/some-file.php', $wpLoader->getContentFolder('some/path/some-file.php') ); - assertEquals( + Assert::assertEquals( $wpRootDir . '/wp-content/plugins/some-file.php', $wpLoader->getPluginsFolder('/some-file.php') ); - assertEquals( + Assert::assertEquals( $wpRootDir . '/wp-content/themes/some-file.php', $wpLoader->getThemesFolder('/some-file.php') ); @@ -1420,8 +1413,8 @@ public function should_correctly_activate_child_theme_in_single_installation(): $installationOutput = $this->assertInIsolation(static function () use ($wpLoader, $wpRootDir) { $wpLoader->_initialize(); - assertEquals('twentytwenty', get_option('template')); - assertEquals('some-child-theme', get_option('stylesheet')); + Assert::assertEquals('twentytwenty', get_option('template')); + Assert::assertEquals('some-child-theme', get_option('stylesheet')); return [ 'bootstrapOutput' => $wpLoader->_getBootstrapOutput(), @@ -1488,8 +1481,8 @@ public function should_correctly_activate_child_theme_in_multisite_installation( $installationOutput = $this->assertInIsolation(static function () use ($wpLoader, $wpRootDir) { $wpLoader->_initialize(); - assertEquals('twentytwenty', get_option('template')); - assertEquals('twentytwenty-child', get_option('stylesheet')); + Assert::assertEquals('twentytwenty', get_option('template')); + Assert::assertEquals('twentytwenty-child', get_option('stylesheet')); return [ 'bootstrapOutput' => $wpLoader->_getBootstrapOutput(), @@ -1620,7 +1613,7 @@ public function should_allow_loading_a_database_dump_before_tests(): void $this->assertInIsolation(static function () use ($wpLoader) { $wpLoader->_initialize(); - assertEquals('value_1', get_option('option_1')); + Assert::assertEquals('value_1', get_option('option_1')); }); } @@ -1655,9 +1648,9 @@ public function should_allow_loading_multiple_database_dumps_before_the_tests(): $this->assertInIsolation(static function () use ($wpLoader) { $wpLoader->_initialize(); - assertEquals('value_1', get_option('option_1')); - assertEquals('value_2', get_option('option_2')); - assertEquals('value_3', get_option('option_3')); + Assert::assertEquals('value_1', get_option('option_1')); + Assert::assertEquals('value_2', get_option('option_2')); + Assert::assertEquals('value_3', get_option('option_3')); }); } @@ -1723,7 +1716,7 @@ public function should_place_sq_lite_dropin_if_using_sq_lite_database_for_tests( $this->assertInIsolation(static function () use ($wpRootDir, $wpLoader) { $wpLoader->_initialize(); - assertFileExists($wpRootDir . '/wp-content/db.php'); + Assert::assertFileExists($wpRootDir . '/wp-content/db.php'); }); } @@ -1750,8 +1743,8 @@ public function should_initialize_correctly_with_sqlite_database(): void $this->assertInIsolation(static function () use ($wpLoader) { $wpLoader->_initialize(); - assertTrue(function_exists('do_action')); - assertInstanceOf(\WP_User::class, wp_get_current_user()); + Assert::assertTrue(function_exists('do_action')); + Assert::assertInstanceOf(\WP_User::class, wp_get_current_user()); }); } @@ -1788,8 +1781,8 @@ public function should_initialize_correctly_with_sqlite_database_in_load_only_mo $wpLoader->_initialize(); Dispatcher::dispatch(Events::SUITE_BEFORE); - assertTrue(function_exists('do_action')); - assertInstanceOf(\WP_User::class, wp_get_current_user()); + Assert::assertTrue(function_exists('do_action')); + Assert::assertInstanceOf(\WP_User::class, wp_get_current_user()); }); } @@ -1861,12 +1854,12 @@ function plugin_2_canary() {} $this->assertInIsolation(static function () use ($wpLoader) { $wpLoader->_initialize(); - assertTrue(function_exists('do_action')); - assertTrue(function_exists('plugin_1_canary')); - assertTrue(is_plugin_active('plugin-1/plugin.php')); - assertTrue(function_exists('plugin_2_canary')); - assertTrue(is_plugin_active('plugin-2/plugin.php')); - assertEquals('theme-1', wp_get_theme()->get_stylesheet()); + Assert::assertTrue(function_exists('do_action')); + Assert::assertTrue(function_exists('plugin_1_canary')); + Assert::assertTrue(is_plugin_active('plugin-1/plugin.php')); + Assert::assertTrue(function_exists('plugin_2_canary')); + Assert::assertTrue(is_plugin_active('plugin-2/plugin.php')); + Assert::assertEquals('theme-1', wp_get_theme()->get_stylesheet()); }); } @@ -1917,8 +1910,8 @@ public function should_correctly_load_with_different_database_names(string $dbNa $this->assertInIsolation(static function () use ($wpLoader) { $wpLoader->_initialize(); - assertTrue(function_exists('do_action')); - assertInstanceOf(\WP_User::class, wp_get_current_user()); + Assert::assertTrue(function_exists('do_action')); + Assert::assertInstanceOf(\WP_User::class, wp_get_current_user()); return $wpLoader->getInstallation()->getDb()->getDbName(); }) @@ -1962,7 +1955,7 @@ public function should_allow_controlling_the_backup_of_global_variables_in_the_w $this->assertInIsolation(static function () use ($wpLoader, $testcaseFile) { $wpLoader->_initialize(); - assertTrue(function_exists('do_action')); + Assert::assertTrue(function_exists('do_action')); require_once $testcaseFile; @@ -1970,7 +1963,7 @@ public function should_allow_controlling_the_backup_of_global_variables_in_the_w /** @var TestResult $result */ $result = $testCase->run(); - assertTrue($result->wasSuccessful()); + Assert::assertTrue($result->wasSuccessful()); }); // Set `WPLoader.backupGlobals` to `true`. @@ -1984,7 +1977,7 @@ public function should_allow_controlling_the_backup_of_global_variables_in_the_w $this->assertInIsolation(static function () use ($wpLoader, $testcaseFile) { $wpLoader->_initialize(); - assertTrue(function_exists('do_action')); + Assert::assertTrue(function_exists('do_action')); require_once $testcaseFile; @@ -1992,7 +1985,7 @@ public function should_allow_controlling_the_backup_of_global_variables_in_the_w /** @var TestResult $result */ $result = $testCase->run(); - assertTrue($result->wasSuccessful()); + Assert::assertTrue($result->wasSuccessful()); }); // Do not set `WPLoader.backupGlobals`, but use the default value. @@ -2006,7 +1999,7 @@ public function should_allow_controlling_the_backup_of_global_variables_in_the_w $this->assertInIsolation(static function () use ($wpLoader, $testcaseFile) { $wpLoader->_initialize(); - assertTrue(function_exists('do_action')); + Assert::assertTrue(function_exists('do_action')); require_once $testcaseFile; @@ -2014,7 +2007,7 @@ public function should_allow_controlling_the_backup_of_global_variables_in_the_w /** @var TestResult $result */ $result = $testCase->run(); - assertTrue($result->wasSuccessful()); + Assert::assertTrue($result->wasSuccessful()); }); // Set `WPLoader.backupGlobals` to `true`, but use a use-case that sets it explicitly to `false`. @@ -2028,7 +2021,7 @@ public function should_allow_controlling_the_backup_of_global_variables_in_the_w $this->assertInIsolation(static function () use ($wpLoader, $overridingTestCaseFile) { $wpLoader->_initialize(); - assertTrue(function_exists('do_action')); + Assert::assertTrue(function_exists('do_action')); require_once $overridingTestCaseFile; @@ -2036,7 +2029,7 @@ public function should_allow_controlling_the_backup_of_global_variables_in_the_w /** @var TestResult $result */ $result = $testCase->run(); - assertTrue($result->wasSuccessful()); + Assert::assertTrue($result->wasSuccessful()); }); $this->config = [ @@ -2049,7 +2042,7 @@ public function should_allow_controlling_the_backup_of_global_variables_in_the_w $this->assertInIsolation(static function () use ($wpLoader, $testcaseFile) { $wpLoader->_initialize(); - assertTrue(function_exists('do_action')); + Assert::assertTrue(function_exists('do_action')); // Set the initial value of the global variable. global $_wpbrowser_test_global_var; @@ -2061,10 +2054,10 @@ public function should_allow_controlling_the_backup_of_global_variables_in_the_w /** @var TestResult $result */ $result = $testCase->run(); - assertTrue($result->wasSuccessful()); + Assert::assertTrue($result->wasSuccessful()); // Check that the value of the global variable has been updated. - assertEquals('initial_value', $_wpbrowser_test_global_var); + Assert::assertEquals('initial_value', $_wpbrowser_test_global_var); }); $this->config = [ @@ -2078,7 +2071,7 @@ public function should_allow_controlling_the_backup_of_global_variables_in_the_w $this->assertInIsolation(static function () use ($wpLoader, $testcaseFile) { $wpLoader->_initialize(); - assertTrue(function_exists('do_action')); + Assert::assertTrue(function_exists('do_action')); // Set the initial value of the global variable. global $_wpbrowser_test_global_var; @@ -2090,10 +2083,10 @@ public function should_allow_controlling_the_backup_of_global_variables_in_the_w /** @var TestResult $result */ $result = $testCase->run(); - assertTrue($result->wasSuccessful()); + Assert::assertTrue($result->wasSuccessful()); // Check that the value of the global variable has been updated. - assertEquals('updated_value', $_wpbrowser_test_global_var); + Assert::assertEquals('updated_value', $_wpbrowser_test_global_var); }); } @@ -2134,7 +2127,7 @@ public function should_allow_controlling_the_backup_of_static_attributes_in_the_ $this->assertInIsolation(static function () use ($wpLoader, $testcaseFile) { $wpLoader->_initialize(); - assertTrue(function_exists('do_action')); + Assert::assertTrue(function_exists('do_action')); require_once $testcaseFile; @@ -2142,9 +2135,9 @@ public function should_allow_controlling_the_backup_of_static_attributes_in_the_ /** @var TestResult $result */ $result = $testCase->run(); - assertTrue($result->wasSuccessful()); + Assert::assertTrue($result->wasSuccessful()); - assertEquals('updated_value', \BackupControlTestCaseStore::$staticAttribute); + Assert::assertEquals('updated_value', \BackupControlTestCaseStore::$staticAttribute); }); // Don't set`WPLoader.backupStaticAttributes`, it should be `true` by default. @@ -2157,7 +2150,7 @@ public function should_allow_controlling_the_backup_of_static_attributes_in_the_ $this->assertInIsolation(static function () use ($wpLoader, $testcaseFile) { $wpLoader->_initialize(); - assertTrue(function_exists('do_action')); + Assert::assertTrue(function_exists('do_action')); require_once $testcaseFile; @@ -2165,9 +2158,9 @@ public function should_allow_controlling_the_backup_of_static_attributes_in_the_ /** @var TestResult $result */ $result = $testCase->run(); - assertTrue($result->wasSuccessful()); + Assert::assertTrue($result->wasSuccessful()); - assertEquals('initial_value', \BackupControlTestCaseStore::$staticAttribute); + Assert::assertEquals('initial_value', \BackupControlTestCaseStore::$staticAttribute); }); // Set the value of `WPLoader.backupStaticAttributes` to `true`, but use a use-case that sets it explicitly to `false`. @@ -2181,7 +2174,7 @@ public function should_allow_controlling_the_backup_of_static_attributes_in_the_ $this->assertInIsolation(static function () use ($wpLoader, $overridingTestCaseFile) { $wpLoader->_initialize(); - assertTrue(function_exists('do_action')); + Assert::assertTrue(function_exists('do_action')); require_once $overridingTestCaseFile; @@ -2189,9 +2182,9 @@ public function should_allow_controlling_the_backup_of_static_attributes_in_the_ /** @var TestResult $result */ $result = $testCase->run(); - assertTrue($result->wasSuccessful()); + Assert::assertTrue($result->wasSuccessful()); - assertEquals('updated_value', \BackupControlTestCaseOverridingStore::$staticAttribute); + Assert::assertEquals('updated_value', \BackupControlTestCaseOverridingStore::$staticAttribute); }); // Set the value of the `WPLoader.backupStaticAttributesExcludeList` to not back up the static attribute. @@ -2209,7 +2202,7 @@ public function should_allow_controlling_the_backup_of_static_attributes_in_the_ static function () use ($wpLoader, $testcaseFile) { $wpLoader->_initialize(); - assertTrue(function_exists('do_action')); + Assert::assertTrue(function_exists('do_action')); require_once $testcaseFile; @@ -2217,16 +2210,16 @@ static function () use ($wpLoader, $testcaseFile) { /** @var TestResult $result */ $result = $testCase->run(); - assertTrue($result->wasSuccessful()); + Assert::assertTrue($result->wasSuccessful()); - assertEquals('updated_value', \BackupControlTestCaseStore::$staticAttribute); - assertEquals('initial_value', \BackupControlTestCaseStore::$staticAttributeTwo); - assertEquals('updated_value', \BackupControlTestCaseStore::$staticAttributeThree); - assertEquals('initial_value', \BackupControlTestCaseStore::$staticAttributeFour); - assertEquals('initial_value', \BackupControlTestCaseStoreTwo::$staticAttribute); - assertEquals('initial_value', \BackupControlTestCaseStoreTwo::$staticAttributeTwo); - assertEquals('initial_value', \BackupControlTestCaseStoreTwo::$staticAttributeThree); - assertEquals('updated_value', \BackupControlTestCaseStoreTwo::$staticAttributeFour); + Assert::assertEquals('updated_value', \BackupControlTestCaseStore::$staticAttribute); + Assert::assertEquals('initial_value', \BackupControlTestCaseStore::$staticAttributeTwo); + Assert::assertEquals('updated_value', \BackupControlTestCaseStore::$staticAttributeThree); + Assert::assertEquals('initial_value', \BackupControlTestCaseStore::$staticAttributeFour); + Assert::assertEquals('initial_value', \BackupControlTestCaseStoreTwo::$staticAttribute); + Assert::assertEquals('initial_value', \BackupControlTestCaseStoreTwo::$staticAttributeTwo); + Assert::assertEquals('initial_value', \BackupControlTestCaseStoreTwo::$staticAttributeThree); + Assert::assertEquals('updated_value', \BackupControlTestCaseStoreTwo::$staticAttributeFour); } ); } @@ -2431,14 +2424,14 @@ static function () use ($wpLoader, $moduleSplObjectHash) { $activePlugins = $wpdb->get_var( "SELECT option_value FROM {$wpdb->options} WHERE option_name = 'active_plugins'" ); - assertEquals(['woocommerce/woocommerce.php'], unserialize($activePlugins)); - assertNotEquals('1', getenv('WP_TESTS_SKIP_INSTALL')); - assertTrue(function_exists('do_action')); - assertTrue($beforeInstallCalled); - assertTrue($afterInstallCalled); - assertTrue($afterBootstrapCalled); - assertTrue(function_exists('wc_get_product')); - assertEquals('twentytwenty', wp_get_theme()->get_stylesheet()); + Assert::assertEquals(['woocommerce/woocommerce.php'], unserialize($activePlugins)); + Assert::assertNotEquals('1', getenv('WP_TESTS_SKIP_INSTALL')); + Assert::assertTrue(function_exists('do_action')); + Assert::assertTrue($beforeInstallCalled); + Assert::assertTrue($afterInstallCalled); + Assert::assertTrue($afterBootstrapCalled); + Assert::assertTrue(function_exists('wc_get_product')); + Assert::assertEquals('twentytwenty', wp_get_theme()->get_stylesheet()); // Set a canary value. update_option('canary', $moduleSplObjectHash); @@ -2478,15 +2471,15 @@ static function () use ($moduleSplObjectHash, $wpLoader) { $activePlugins = $wpdb->get_var( "SELECT option_value FROM {$wpdb->options} WHERE option_name = 'active_plugins'" ); - assertEquals(['woocommerce/woocommerce.php'], unserialize($activePlugins)); - assertEquals('1', getenv('WP_TESTS_SKIP_INSTALL')); - assertTrue(function_exists('do_action')); - assertTrue($beforeInstallCalled); - assertTrue($afterInstallCalled); - assertTrue($afterBootstrapCalled); - assertTrue(function_exists('wc_get_product')); - assertEquals('twentytwenty', wp_get_theme()->get_stylesheet()); - assertEquals($moduleSplObjectHash, get_option('canary')); + Assert::assertEquals(['woocommerce/woocommerce.php'], unserialize($activePlugins)); + Assert::assertEquals('1', getenv('WP_TESTS_SKIP_INSTALL')); + Assert::assertTrue(function_exists('do_action')); + Assert::assertTrue($beforeInstallCalled); + Assert::assertTrue($afterInstallCalled); + Assert::assertTrue($afterBootstrapCalled); + Assert::assertTrue(function_exists('wc_get_product')); + Assert::assertEquals('twentytwenty', wp_get_theme()->get_stylesheet()); + Assert::assertEquals($moduleSplObjectHash, get_option('canary')); } ); @@ -2515,15 +2508,15 @@ static function () use ($wpLoader) { $activePlugins = $wpdb->get_var( "SELECT option_value FROM {$wpdb->options} WHERE option_name = 'active_plugins'" ); - assertEquals(['woocommerce/woocommerce.php'], unserialize($activePlugins)); - assertNotEquals('1', getenv('WP_TESTS_SKIP_INSTALL')); - assertTrue(function_exists('do_action')); - assertTrue($beforeInstallCalled); - assertTrue($afterInstallCalled); - assertTrue($afterBootstrapCalled); - assertTrue(function_exists('wc_get_product')); - assertEquals('twentytwenty', wp_get_theme()->get_stylesheet()); - assertEquals( + Assert::assertEquals(['woocommerce/woocommerce.php'], unserialize($activePlugins)); + Assert::assertNotEquals('1', getenv('WP_TESTS_SKIP_INSTALL')); + Assert::assertTrue(function_exists('do_action')); + Assert::assertTrue($beforeInstallCalled); + Assert::assertTrue($afterInstallCalled); + Assert::assertTrue($afterBootstrapCalled); + Assert::assertTrue(function_exists('wc_get_product')); + Assert::assertEquals('twentytwenty', wp_get_theme()->get_stylesheet()); + Assert::assertEquals( '', get_option('canary'), 'The value set in the previous installation should be gone.' @@ -2683,8 +2676,8 @@ function activate_my_plugin(){ static function () use ($wpLoader) { $wpLoader->_initialize(); - assertEquals('', get_option('my_plugin_activated')); - assertEquals('__loaded__', get_option('my_plugin_loaded')); + Assert::assertEquals('', get_option('my_plugin_activated')); + Assert::assertEquals('__loaded__', get_option('my_plugin_loaded')); } ); }