Skip to content

Commit

Permalink
Merge pull request #691 from lucatume/v4-back-compat-work
Browse files Browse the repository at this point in the history
v4 back compat work
  • Loading branch information
lucatume committed Feb 18, 2024
2 parents 4199ac4 + c8ffb71 commit 5c44672
Show file tree
Hide file tree
Showing 85 changed files with 3,731 additions and 464 deletions.
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ labels: bug
assignees: lucatume

---
**Version 3.5**
If you're opening an issue to report a breakage caused by version `3.5`; please read the [migration guide first](https://wpbrowser.wptestkit.dev/migration) first!

**Environment**
OS: [e.g. Windows, Mac, Linux]
Expand Down
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE/documentation-error.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ labels: bug
assignees: lucatume

---
**Version 3.5**
If you're opening an issue to report a breakage caused by version `3.5`; please read the [migration guide first](https://wpbrowser.wptestkit.dev/migration) first!

**wp-browser version**
For what version of wp-browser is this for? [e.g. 2.2.2]
Expand Down
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE/documentation-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ labels: ''
assignees: ''

---
**Version 3.5**
If you're opening an issue to report a breakage caused by version `3.5`; please read the [migration guide first](https://wpbrowser.wptestkit.dev/migration) first!

**Did you search the documentation first?**
You can find it at [https://wpbrowser.wptestkit.dev/](https://wpbrowser.wptestkit.dev/).
Expand Down
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ labels: ''
assignees: ''

---
**Version 3.5**
If you're opening an issue to report a breakage caused by version `3.5`; please read the [migration guide first](https://wpbrowser.wptestkit.dev/migration) first!

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Expand Down
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE/setup-issue.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ labels: ''
assignees: ''

---
**Version 3.5**
If you're opening an issue to report a breakage caused by version `3.5`; please read the [migration guide first](https://wpbrowser.wptestkit.dev/migration) first!

**Environment**
OS: [e.g. Windows, Mac, Linux]
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.DS_Store

.cache
.build

# Composer files.
vendor/
Expand All @@ -26,3 +27,6 @@ composer.lock

# Backup files and folders
*.bak

# Logs
*.log
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased] Unreleased

### Changed

- The `WPTestCase` class will **not** backup globals and static attributes by default. Version `3` of wp-browser did not backup globals and static attributes by default, this change in version `4` is aligned with that behaviour to ease migration from version `3` to version `4`.

### Added

- Restored support for the `@runInSeparateProcess` annotation for test methods. Along with it, improved support for the `@dataProvider` annotation for test methods used in conjunction with the `@runInSeparateProcess` annotation to run data provider methods at most once.
- Implemented support for the `runTestsInSeparateProcesses` annotation for test classes; supporting the `@dataProvider` annotation ro run data provider methods at most once.
- Added support for the `#[RunInSeparateProcess]` attribute for test methods and the `#[RunTestsInSeparateProcesses]` attribute for test classes.

## [4.0.21] 2024-02-12;

### Fixed
Expand Down
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,5 @@ clean_procs:
.PHONY: clean_procs

build_35:
rm -rf vendor composer.lock
composer require --dev rector/rector -W
vendor/bin/rector --config=config/rector-35.php
rm -rf vendor composer.lock composer.json
cp config/composer-35.json composer.json
bin/build_35.sh
.PHONY: build_35
16 changes: 16 additions & 0 deletions bin/build-35-exclusions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.idea
.build
.cache
.git
.github
bin
docs
var
vendor
CHANGELOG.md
docker-compose.yml
dynamicReturnTypeMeta.json
LICENSE
Makefile
mkdocs.yml
README.md
21 changes: 21 additions & 0 deletions bin/build-35.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#! /usr/bin/env bash

set -eu

# Accept an optional set of paths.
files=$@
[ -d ./.build/35 ] && rm -rf ./.build/35
mkdir -p ./.build/35
rsync -av --exclude-from=bin/build-35-exclusions.txt . ./.build/35
cd ./.build/35
rm -rf vendor composer.lock
composer require --dev rector/rector:0.19.2 -W
composer dump-autoload
if [ -z "$files" ]; then
vendor/bin/rector process src --config=config/rector-35.php
else
vendor/bin/rector process --config=config/rector-35.php $files
fi
rm -rf vendor composer.lock composer.json
cp config/composer-35.json composer.json
cd -
61 changes: 33 additions & 28 deletions bin/namespace_global_class_names.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@
use PhpParser\ParserFactory;
use PhpParser\PhpVersion;

require_once dirname(__DIR__) . '/vendor/autoload.php';
$rootDir = dirname(__DIR__);
require_once $rootDir . '/vendor/autoload.php';

// Build a PHP parser using nikic/php-parser
$parser = (new ParserFactory())->createForVersion(PHPVersion::fromComponents(8, 0));

// Build an iterator over all the .php files in the includes directory
$files = new RegexIterator(
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(
dirname(__DIR__) . '/includes/core-phpunit/includes',
RecursiveDirectoryIterator::SKIP_DOTS | RecursiveDirectoryIterator::CURRENT_AS_PATHNAME
)
),
'/\.php$/'
);
$files = [
$rootDir . "/includes/core-phpunit/includes/testcase-ajax.php",
$rootDir . "/includes/core-phpunit/includes/testcase-canonical.php",
$rootDir . "/includes/core-phpunit/includes/testcase-rest-api.php",
$rootDir . "/includes/core-phpunit/includes/testcase-rest-controller.php",
$rootDir . "/includes/core-phpunit/includes/testcase-rest-post-type-controller.php",
$rootDir . "/includes/core-phpunit/includes/testcase-xml.php",
$rootDir . '/includes/core-phpunit/includes/testcase-xmlrpc.php',
];

// Add a node visitor that will resolve to fully qualified namespaces.
$traverser = new NodeTraverser();
Expand All @@ -41,7 +42,7 @@
private function addMatch(string $file, int $line, string $match)
{
// Pick the fragment after the last \ in the match.
$class = substr($match, strrpos($match, '\\') + 1);
$class = substr($match, (strrpos($match, '\\') ?: -1) + 1);
$this->matchesByFile[$file][] = [$line, $class];
}

Expand All @@ -59,7 +60,7 @@ public function leaveNode(Node $node)
{
if ($node instanceof New_) {
$class = $node->class;
if ($class instanceof Name) {
if ($class instanceof Name && count($class->getParts()) > 1) {
$name = $class->toString();
if (!class_exists($name) && !interface_exists($name) && !trait_exists($name)) {
$file = $this->file;
Expand All @@ -71,7 +72,7 @@ public function leaveNode(Node $node)
} elseif ($node instanceof Function_ || $node instanceof ClassMethod) {
foreach ($node->getParams() as $param) {
$type = $param->type;
if ($type instanceof Name) {
if ($type instanceof Name && count($type->getParts()) > 1) {
$name = $type->toString();
if (!class_exists($name) && !interface_exists($name) && !trait_exists($name)) {
$file = $this->file;
Expand All @@ -81,6 +82,17 @@ public function leaveNode(Node $node)
}
}
}
} elseif($node instanceof Node\Expr\Instanceof_){
$class = $node->class;
if ($class instanceof Name && count($class->getParts()) > 1) {
$name = $class->toString();
if (!class_exists($name) && !interface_exists($name) && !trait_exists($name)) {
$file = $this->file;
$line = $node->getAttribute('startLine');
$match = $class->toString();
$this->addMatch($file, $line, $match);
}
}
}
}

Expand All @@ -91,36 +103,29 @@ public function setPossibleNamespaces(array $possibleNamespaces): void
};

$traverser->addVisitor($namespaceFlagVisitor);

// Scan all the files to build the parser information.
foreach ($files as $file) {
$stmts = $parser->parse(file_get_contents($file));
$namespaceFlagVisitor->setFile($file);
$stmts = $traverser->traverse($stmts);
}

$filesToCure = [
dirname(__DIR__) . "/includes/core-phpunit/includes/testcase-ajax.php",
dirname(__DIR__) . "/includes/core-phpunit/includes/testcase-canonical.php",
dirname(__DIR__) . "/includes/core-phpunit/includes/testcase-rest-api.php",
dirname(__DIR__) . "/includes/core-phpunit/includes/testcase-rest-controller.php",
dirname(__DIR__) . "/includes/core-phpunit/includes/testcase-rest-post-type-controller.php",
dirname(__DIR__) . "/includes/core-phpunit/includes/testcase-xml.php",
dirname(__DIR__) . '/includes/core-phpunit/includes/testcase-xmlrpc.php',
];
foreach ($namespaceFlagVisitor->getMatchesByFile() as $file => $matches) {
if (!in_array($file, $filesToCure, true)) {
// Target only the files to cure.
continue;
}
$matchesByFile = $namespaceFlagVisitor->getMatchesByFile();

if (!count($matchesByFile)) {
printf("No replacemenents required.\n");
}

foreach ($matchesByFile as $file => $matches) {
$updatedContents = file($file);

if ($updatedContents === false) {
throw new RuntimeException('Could not read file: ' . $file);
}

foreach ($matches as [$line, $match]) {
$updatedContents[$line - 1] = str_replace($match, '\\' . $match, $updatedContents[$line - 1]);
$updatedContents[$line - 1] = str_replace(ltrim($match, '\\'), '\\' . $match, $updatedContents[$line - 1]);
}

printf('Updating file: %s ... ', $file);
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%"
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@
"src/",
"src/Deprecated"
],
"Codeception\\Extension\\": "src/Extension",
"Hautelook\\Phpass\\": "includes/Hautelook/Phpass",
"lucatume\\WPBrowser\\Opis\\Closure\\" : "includes/opis/closure/src"
},
"files": [
"src/version-4-aliases.php",
"src/Deprecated/deprecated-functions.php",
"src/deprecated-functions.php",
"src/functions.php"
]
},
Expand Down Expand Up @@ -91,6 +92,12 @@
],
"cs-fix": [
"phpcbf --standard=config/phpcs.xml src"
],
"typos": [
"typos --config ./config/typos.toml -w"
],
"pre-commit": [
"@stan", "@cs-fix", "@cs", "@typos"
]
},
"suggest": {
Expand Down
4 changes: 4 additions & 0 deletions config/phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,9 @@
<exclude-pattern>src/MonkeyPatch/FileStreamWrapper.php</exclude-pattern>
</rule>

<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
<exclude-pattern>src/TestCase/WPTestCasePHPUnitMethodsTrait.php</exclude-pattern>
</rule>

<exclude-pattern>./tests/*</exclude-pattern>
</ruleset>
1 change: 1 addition & 0 deletions config/phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ parameters:
treatPhpDocTypesAsCertain: false
excludePaths:
- ./../src/WordPress/Version.php # Using the WordPress version file.
- ./../src/TestCase/WPTestCasePHPUnitMethodsTrait.php # Compat file has missing return types.
4 changes: 0 additions & 4 deletions config/rector-35.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

declare(strict_types=1);

use Codeception\TestInterface;
use lucatume\Rector\RemoveTypeHinting;
use lucatume\Rector\SwapEventDispatcherEventNameParameters;
use Rector\Config\RectorConfig;
use Rector\DowngradePhp72\Rector\ClassMethod\DowngradeParameterTypeWideningRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
Expand Down Expand Up @@ -45,8 +43,6 @@
new MethodCallRename('PHPUnit\Framework\Assert', 'assertFileDoesNotExist', 'assertFileNotExists')
]);

$rectorConfig->rule(SwapEventDispatcherEventNameParameters::class);

$rectorConfig->sets([DowngradeLevelSetList::DOWN_TO_PHP_71]);
$rectorConfig->skip([DowngradeParameterTypeWideningRector::class]);

Expand Down
4 changes: 2 additions & 2 deletions config/rector/src/RemoveTypeHinting.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Contract\Rector\ConfigurableRectorInterface;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand Down
Loading

0 comments on commit 5c44672

Please sign in to comment.