Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(v3.5) autobuild #701

Merged
merged 7 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bin/release
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function args()
'checkDiff' => empty($options['no-diff-check']),
'checkUnpushed' => empty($options['no-unpushed-check']),
'dryRun' => isset($options['dry-run']),
'releaseBranch' => $options['release-branch'] ?? 'master'
'releaseBranch' => $options['release-branch'] ?? 'v3.5'
];

return static function ($key, $default = null) use ($map) {
Expand All @@ -69,7 +69,7 @@ if (!in_array($args('releaseType'), ['major', 'minor', 'patch'], true)) {
}

$dryRun = $args('dryRun', false);
$releaseBranch = $args('releaseBranch', 'master');
$releaseBranch = $args('releaseBranch', 'v3.5');

if (!$dryRun) {
$currentGitBranch = trim(shell_exec('git rev-parse --abbrev-ref HEAD'));
Expand Down
10 changes: 10 additions & 0 deletions codeception.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ extensions:
- "lucatume\\WPBrowser\\Extension\\BuiltInServerController"
- "lucatume\\WPBrowser\\Extension\\ChromeDriverController"
- "lucatume\\WPBrowser\\Extension\\DockerComposeController"
- "lucatume\\WPBrowser\\Extension\\IsolationSupport"
config:
"lucatume\\WPBrowser\\Extension\\BuiltInServerController":
docroot: '%WORDPRESS_ROOT_DIR%'
Expand All @@ -37,14 +38,23 @@ extensions:
commands:
- "lucatume\\WPBrowser\\Command\\RunOriginal"
- "lucatume\\WPBrowser\\Command\\RunAll"
- "lucatume\\WPBrowser\\Command\\GenerateWPAjax"
- "lucatume\\WPBrowser\\Command\\GenerateWPCanonical"
- "lucatume\\WPBrowser\\Command\\GenerateWPRestApi"
- "lucatume\\WPBrowser\\Command\\GenerateWPRestController"
- "lucatume\\WPBrowser\\Command\\GenerateWPRestPostTypeController"
- "lucatume\\WPBrowser\\Command\\GenerateWPUnit"
- "lucatume\\WPBrowser\\Command\\GenerateWPXML"
- "lucatume\\WPBrowser\\Command\\GenerateWPXMLRPC"
- "lucatume\\WPBrowser\\Command\\ChromedriverUpdate"
- "lucatume\\WPBrowser\\Command\\DevStart"
- "lucatume\\WPBrowser\\Command\\DevStop"
- "lucatume\\WPBrowser\\Command\\DevRestart"
- "lucatume\\WPBrowser\\Command\\DevInfo"
- "lucatume\\WPBrowser\\Command\\DbImport"
- "lucatume\\WPBrowser\\Command\\DbExport"
- "lucatume\\WPBrowser\\Command\\MonkeyCacheClear"
- "lucatume\\WPBrowser\\Command\\MonkeyCachePath"
snapshot:
refresh: true
version: "%WPBROWSER_VERSION%"
47 changes: 18 additions & 29 deletions includes/cli-server/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,29 @@
* Extracted from the `wp-cli` project: https://wp-cli.org/
*/

if (function_exists('uopz_allow_exit')) {
uopz_allow_exit(true);
}

$root = $_SERVER['DOCUMENT_ROOT'];
$path = '/' . ltrim(parse_url(urldecode($_SERVER['REQUEST_URI']), PHP_URL_PATH), '/');
$path = '/'. ltrim( parse_url( urldecode( $_SERVER['REQUEST_URI'] ),PHP_URL_PATH ), '/' );

define('DB_ENGINE', getenv('DB_ENGINE') ?: 'mysql');

// The self-call will slow down the response handling and will not benefit the test environment.
global $wp_filter;
$wp_filter['do_mu_upgrade'][10][] = [
'accepted_args' => 0,
'function' => static function () {
return false;
}
];
if ( file_exists( $root.$path ) ) {

if (file_exists($root . $path)) {
// Enforces trailing slash, keeping links tidy in the admin
if (is_dir($root . $path) && substr_compare($path, '/', -strlen('/')) !== 0) {
header("Location: $path/");
exit;
}
// Enforces trailing slash, keeping links tidy in the admin
if ( is_dir( $root.$path ) && substr_compare($path, '/', -strlen('/')) !== 0 ) {
header( "Location: $path/" );
exit;
}

// Runs PHP file if it exists
if (strpos($path, '.php') !== false) {
chdir(dirname($root . $path));
require_once $root . $path;
} else {
return false;
}
// Runs PHP file if it exists
if ( strpos($path, '.php') !== false ) {
chdir( dirname( $root.$path ) );
require_once $root.$path;
} else {
return false;
}
} else {
// Otherwise, run `index.php`
chdir($root);
require_once 'index.php';

// Otherwise, run `index.php`
chdir( $root );
require_once 'index.php';
}
1 change: 1 addition & 0 deletions includes/core-phpunit/includes/abstract-testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ public static function flush_cache() {
'site-options',
'site-queries',
'site-transient',
'theme_files',
'rss',
'users',
'user-queries',
Expand Down
16 changes: 16 additions & 0 deletions includes/core-phpunit/includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,26 @@ function _wp_rest_server_class_filter() {
* @since 5.0.0
*/
function _unhook_block_registration() {
// Block types.
require __DIR__ . '/unregister-blocks-hooks.php';
remove_action( 'init', 'register_core_block_types_from_metadata' );
remove_action( 'init', 'register_block_core_legacy_widget' );
remove_action( 'init', 'register_block_core_widget_group' );
remove_action( 'init', 'register_core_block_types_from_metadata' );

// Block binding sources.
remove_action( 'init', '_register_block_bindings_pattern_overrides_source' );
remove_action( 'init', '_register_block_bindings_post_meta_source' );
}
tests_add_filter( 'init', '_unhook_block_registration', 1000 );

/**
* After the init action has been run once, trying to re-register font collections can cause
* errors. To avoid this, unhook the font registration functions.
*
* @since 6.5.0
*/
function _unhook_font_registration() {
remove_action( 'init', '_wp_register_default_font_collections' );
}
tests_add_filter( 'init', '_unhook_font_registration', 1000 );
49 changes: 36 additions & 13 deletions includes/core-phpunit/includes/phpunit6/compat.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,42 @@
<?php

if ( class_exists( 'PHPUnit\Runner\Version' ) && version_compare( PHPUnit\Runner\Version::id(), '6.0', '>=' ) ) {

class_alias( 'PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase' );
class_alias( 'PHPUnit\Framework\Exception', 'PHPUnit_Framework_Exception' );
class_alias( 'PHPUnit\Framework\ExpectationFailedException', 'PHPUnit_Framework_ExpectationFailedException' );
class_alias( 'PHPUnit\Framework\Error\Deprecated', 'PHPUnit_Framework_Error_Deprecated' );
class_alias( 'PHPUnit\Framework\Error\Notice', 'PHPUnit_Framework_Error_Notice' );
class_alias( 'PHPUnit\Framework\Error\Warning', 'PHPUnit_Framework_Error_Warning' );
class_alias( 'PHPUnit\Framework\Test', 'PHPUnit_Framework_Test' );
class_alias( 'PHPUnit\Framework\Warning', 'PHPUnit_Framework_Warning' );
class_alias( 'PHPUnit\Framework\AssertionFailedError', 'PHPUnit_Framework_AssertionFailedError' );
class_alias( 'PHPUnit\Framework\TestSuite', 'PHPUnit_Framework_TestSuite' );
class_alias( 'PHPUnit\Framework\TestListener', 'PHPUnit_Framework_TestListener' );
class_alias( 'PHPUnit\Util\GlobalState', 'PHPUnit_Util_GlobalState' );
if (!class_exists('PHPUnit_Framework_TestCase')) {
class_alias('PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase');
}
if (!class_exists('PHPUnit_Framework_Exception')) {
class_alias('PHPUnit\Framework\Exception', 'PHPUnit_Framework_Exception');
}
if (!class_exists('PHPUnit_Framework_ExpectationFailedException')) {
class_alias('PHPUnit\Framework\ExpectationFailedException', 'PHPUnit_Framework_ExpectationFailedException');
}
if (!class_exists('PHPUnit_Framework_Error_Deprecated')) {
class_alias('PHPUnit\Framework\Error\Deprecated', 'PHPUnit_Framework_Error_Deprecated');
}
if (!class_exists('PHPUnit_Framework_Error_Notice')) {
class_alias('PHPUnit\Framework\Error\Notice', 'PHPUnit_Framework_Error_Notice');
}
if (!class_exists('PHPUnit_Framework_Error_Warning')) {
class_alias('PHPUnit\Framework\Error\Warning', 'PHPUnit_Framework_Error_Warning');
}
if (!class_exists('PHPUnit_Framework_Test')) {
class_alias('PHPUnit\Framework\Test', 'PHPUnit_Framework_Test');
}
if (!class_exists('PHPUnit_Framework_Warning')) {
class_alias('PHPUnit\Framework\Warning', 'PHPUnit_Framework_Warning');
}
if (!class_exists('PHPUnit_Framework_AssertionFailedError')) {
class_alias('PHPUnit\Framework\AssertionFailedError', 'PHPUnit_Framework_AssertionFailedError');
}
if (!class_exists('PHPUnit_Framework_TestSuite')) {
class_alias('PHPUnit\Framework\TestSuite', 'PHPUnit_Framework_TestSuite');
}
if (!class_exists('PHPUnit_Framework_TestListener')) {
class_alias('PHPUnit\Framework\TestListener', 'PHPUnit_Framework_TestListener');
}
if (!class_exists('PHPUnit_Util_GlobalState')) {
class_alias('PHPUnit\Util\GlobalState', 'PHPUnit_Util_GlobalState');
}
if ( class_exists( 'PHPUnit\Util\Getopt' ) ) {
class_alias( 'PHPUnit\Util\Getopt', 'PHPUnit_Util_Getopt' );
}
Expand Down
2 changes: 1 addition & 1 deletion includes/core-phpunit/includes/testcase-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
abstract class WPRestApiTestCase extends WPTestCase {
protected function assertErrorResponse( $code, $response, $status = null ) {

if ( $response instanceof WP_REST_Response ) {
if ( $response instanceof \WP_REST_Response ) {
$response = $response->as_error();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,16 @@ protected function check_post_data( $post, $data, $context, $links ) {
$this->assertSame( get_page_template_slug( $post->ID ), $data['template'] );
}

if ( post_type_supports( $post->post_type, 'thumbnail' ) ) {
if (
post_type_supports( $post->post_type, 'thumbnail' ) ||
(
'attachment' === $post->post_type &&
(
post_type_supports( 'attachment:audio', 'thumbnail' ) ||
post_type_supports( 'attachment:video', 'thumbnail' )
)
)
) {
$this->assertSame( (int) get_post_thumbnail_id( $post->ID ), $data['featured_media'] );
} else {
$this->assertArrayNotHasKey( 'featured_media', $data );
Expand Down
25 changes: 19 additions & 6 deletions src/Adapters/Symfony/Component/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

namespace lucatume\WPBrowser\Adapters\Symfony\Component\Process;

use ReflectionMethod;
use ReflectionProperty;
use Symfony\Component\Process\Exception\LogicException;
use Symfony\Component\Process\Pipes\PipesInterface;
use Symfony\Component\Process\Process as SymfonyProcess;

class Process extends SymfonyProcess
{
/**
* @var bool|null
*/
private static $inheritEnvironmentVariables;
/**
* @var bool
*/
Expand All @@ -27,8 +33,15 @@ public function __construct(
?float $timeout = 60,
array $options = null
) {
if (method_exists($this, 'inheritEnvironmentVariables')) {
parent::__construct($command, $cwd, $env, $input, $timeout, $options); //@phpstan-ignore-line
parent::__construct($command, $cwd, $env, $input, $timeout, $options); //@phpstan-ignore-line

if (self::$inheritEnvironmentVariables === null) {
self::$inheritEnvironmentVariables = method_exists($this, 'inheritEnvironmentVariables')
&& strpos((string)(new ReflectionMethod($this, 'inheritEnvironmentVariables'))->getDocComment(), '@deprecated') === false;
}

if (self::$inheritEnvironmentVariables) {
// @phpstan-ignore-next-line
$this->inheritEnvironmentVariables(true);
}

Expand All @@ -45,7 +58,7 @@ public function getStartTime(): float
throw new LogicException('Start time is only available after process start.');
}

$startTimeReflectionProperty = new \ReflectionProperty(SymfonyProcess::class, 'starttime');
$startTimeReflectionProperty = new ReflectionProperty(SymfonyProcess::class, 'starttime');
$startTimeReflectionProperty->setAccessible(true);
/** @var float $startTime */
$startTime = $startTimeReflectionProperty->getValue($this);
Expand All @@ -56,7 +69,7 @@ public function getStartTime(): float
public function __destruct()
{
if ($this->createNewConsole) {
$processPipesProperty = new \ReflectionProperty(SymfonyProcess::class, 'processPipes');
$processPipesProperty = new ReflectionProperty(SymfonyProcess::class, 'processPipes');
$processPipesProperty->setAccessible(true);
/** @var PipesInterface $processPipes */
$processPipes = $processPipesProperty->getValue($this);
Expand All @@ -72,7 +85,7 @@ public function createNewConsole(): void
{
$this->createNewConsole = true;

$optionsReflectionProperty = new \ReflectionProperty(SymfonyProcess::class, 'options');
$optionsReflectionProperty = new ReflectionProperty(SymfonyProcess::class, 'options');
$optionsReflectionProperty->setAccessible(true);
$options = $optionsReflectionProperty->getValue($this);
$options = is_array($options) ? $options : [];
Expand All @@ -90,7 +103,7 @@ public static function __callStatic(string $name, array $arguments)
if ($name === 'fromShellCommandline') {
$command = array_shift($arguments);
$process = new self([], ...$arguments); // @phpstan-ignore-line
$processCommandLineProperty = new \ReflectionProperty(SymfonyProcess::class, 'commandline');
$processCommandLineProperty = new ReflectionProperty(SymfonyProcess::class, 'commandline');
$processCommandLineProperty->setAccessible(true);
$processCommandLineProperty->setValue($process, $command);

Expand Down
27 changes: 27 additions & 0 deletions src/Command/GenerateWPAjax.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace lucatume\WPBrowser\Command;

use lucatume\WPBrowser\Lib\Generator\AbstractGenerator;
use lucatume\WPBrowser\Lib\Generator\WPAjax;

class GenerateWPAjax extends GenerateWPUnit
{
public static function getCommandName(): string
{
return "generate:wpajax";
}

public function getDescription(): string
{
return 'Generates a WPAjaxTestCase: a test case with Codeception super-powers to test AJAX handling.';
}

/**
* @param array{namespace: string, actor: string} $config The generator configuration.
*/
protected function getGenerator(array $config, string $class): AbstractGenerator
{
return new WPAjax($config, $class);
}
}
27 changes: 27 additions & 0 deletions src/Command/GenerateWPCanonical.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace lucatume\WPBrowser\Command;

use lucatume\WPBrowser\Lib\Generator\AbstractGenerator;
use lucatume\WPBrowser\Lib\Generator\WPCanonical;

class GenerateWPCanonical extends GenerateWPUnit
{
public static function getCommandName(): string
{
return "generate:wpcanonical";
}

public function getDescription(): string
{
return 'Generates a WPCanonicalTestCase: a test case with Codeception super-powers to test rewrite handling.';
}

/**
* @param array{namespace: string, actor: string} $config The generator configuration.
*/
protected function getGenerator(array $config, string $class): AbstractGenerator
{
return new WPCanonical($config, $class);
}
}
27 changes: 27 additions & 0 deletions src/Command/GenerateWPRestApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace lucatume\WPBrowser\Command;

use lucatume\WPBrowser\Lib\Generator\AbstractGenerator;
use lucatume\WPBrowser\Lib\Generator\WPRestApi;

class GenerateWPRestApi extends GenerateWPUnit
{
public static function getCommandName(): string
{
return "generate:wprestapi";
}

public function getDescription(): string
{
return 'Generates a WPRestApiTestCase: a test case with Codeception super-powers to test REST API handling.';
}

/**
* @param array{namespace: string, actor: string} $config The generator configuration.
*/
protected function getGenerator(array $config, string $class): AbstractGenerator
{
return new WPRestApi($config, $class);
}
}
Loading
Loading