Skip to content

Commit

Permalink
build(rector) update rules to build 3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
lucatume committed Oct 20, 2023
1 parent c67e025 commit 74f3a6e
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 121 deletions.
37 changes: 30 additions & 7 deletions config/rector-35.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,49 @@
<?php

declare( strict_types=1 );
declare(strict_types=1);

use lucatume\Rector\SwapEventDispatcherEventNameParameters;
use lucatume\WPBrowser\TestCase\WPTestCase;
use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\Rector\PropertyFetch\RenamePropertyRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Renaming\ValueObject\RenameProperty;
use Rector\Set\ValueObject\DowngradeLevelSetList;
use Rector\TypeDeclaration\Rector\ClassMethod\ArrayShapeFromConstantArrayReturnRector;
use Rector\TypeDeclaration\Rector\Closure\AddClosureReturnTypeRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
dirname(__DIR__) . '/includes',
dirname(__DIR__) . '/src',
// dirname(__DIR__) . '/includes',
// dirname(__DIR__) . '/src',
dirname(__DIR__) . '/tests',
]);

$rectorConfig->ruleWithConfiguration(RenameClassRector::class,[
'Symfony\Contracts\EventDispatcher\Event' => 'Symfony\Component\EventDispatcher\Event'
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, [
'Symfony\Contracts\EventDispatcher\Event' => 'Symfony\Component\EventDispatcher\Event',
'Psr\EventDispatcher\EventDispatcherInterface' => 'Symfony\Component\EventDispatcher\EventDispatcherInterface'
]);
$rectorConfig->ruleWithConfiguration(RenamePropertyRector::class, [
new RenameProperty(
'lucatume\WPBrowser\TestCase\WPTestCase',
'backupStaticAttributesExcludeList',
'backupStaticAttributesBlacklist'
),
new RenameProperty(
'lucatume\WPBrowser\TestCase\WPTestCase',
'backupGlobalsExcludeList',
'backupGlobalsBlacklist'
)
]);
$rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [
new MethodCallRename('PHPUnit\Framework\Assert', 'assertMatchesRegularExpression', 'assertRegExp'),
new MethodCallRename('PHPUnit\Framework\Assert', 'assertDoesNotMatchRegularExpression', 'assertNotRegExp'),
new MethodCallRename('PHPUnit\Framework\Assert', 'assertFileDoesNotExist', 'assertFileNotExists')
]);

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

$rectorConfig->sets([ DowngradeLevelSetList::DOWN_TO_PHP_71 ]);
//
// $rectorConfig->sets([DowngradeLevelSetList::DOWN_TO_PHP_71]);
};
18 changes: 0 additions & 18 deletions src/TestCase/WPTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ class WPTestCase extends Unit
'_wp_registered_theme_features'
];

// Back-compat.
protected $backupGlobalsBlacklist = [];

// Backup, and reset, static class attributes between tests.
protected $backupStaticAttributes = true;

Expand All @@ -63,26 +60,11 @@ class WPTestCase extends Unit
'Automattic\WooCommerce\RestApi\Server' => ['instance']
];

// Back-compat.
protected $backupStaticAttributesBlacklist = [];

/**
* @var array<string,mixed>
*/
protected array $additionalGlobalsBackup = [];

/**
* @param array<mixed> $data
*/
public function __construct(?string $name = null, array $data = [], $dataName = '')
{
parent::__construct($name, $data, $dataName);

// Back-compat.
$this->backupGlobalsBlacklist = $this->backupGlobalsExcludeList;
$this->backupStaticAttributesBlacklist = $this->backupStaticAttributesExcludeList;
}

/**
* @var array<string,WP_UnitTestCase>
*/
Expand Down
26 changes: 13 additions & 13 deletions tests/.env
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
WORDPRESS_ROOT_DIR=var/wordpress
WORDPRESS_URL=http://localhost:3589
WORDPRESS_DOMAIN=localhost:3589
WORDPRESS_SUBDIR_URL=http://localhost:3589/subdir
WORDPRESS_SUBDOMAIN_URL=http://test1.localhost:3589
WORDPRESS_URL=http://localhost:2389
WORDPRESS_DOMAIN=localhost:2389
WORDPRESS_SUBDIR_URL=http://localhost:2389/subdir
WORDPRESS_SUBDOMAIN_URL=http://test1.localhost:2389
WORDPRESS_ADMIN_USER=admin
WORDPRESS_ADMIN_PASSWORD=admin
WORDPRESS_DB_DSN=mysql:host=127.0.0.1;port=3591;dbname=wordpress
WORDPRESS_DB_HOST=127.0.0.1:3591
WORDPRESS_DB_DSN=mysql:host=127.0.0.1;port=2391;dbname=wordpress
WORDPRESS_DB_HOST=127.0.0.1:2391
WORDPRESS_DB_NAME=wordpress
WORDPRESS_DB_USER=root
WORDPRESS_DB_PASSWORD=password
WORDPRESS_DB_URL=mysql://root:password@127.0.0.1:3591/wordpress
WORDPRESS_DB_LOCALHOST_PORT=3591
WORDPRESS_SUBDIR_DB_DSN=mysql:host=127.0.0.1;port=3591;dbname=test_subdir
WORDPRESS_DB_URL=mysql://root:password@127.0.0.1:2391/wordpress
WORDPRESS_DB_LOCALHOST_PORT=2391
WORDPRESS_SUBDIR_DB_DSN=mysql:host=127.0.0.1;port=2391;dbname=test_subdir
WORDPRESS_SUBDIR_DB_NAME=test_subdir
WORDPRESS_SUBDOMAIN_DB_DSN=mysql:host=127.0.0.1;port=3591;dbname=test_subdomain
WORDPRESS_SUBDOMAIN_DB_DSN=mysql:host=127.0.0.1;port=2391;dbname=test_subdomain
WORDPRESS_SUBDOMAIN_DB_NAME=test_subdomain
WORDPRESS_EMPTY_DB_DSN=mysql:host=127.0.0.1;port=3591;dbname=empty
WORDPRESS_EMPTY_DB_DSN=mysql:host=127.0.0.1;port=2391;dbname=empty
WORDPRESS_EMPTY_DB_NAME=empty
WORDPRESS_TABLE_PREFIX=wp_
WORDPRESS_LOCALHOST_PORT=3589
WORDPRESS_LOCALHOST_PORT=2389
CHROMEDRIVER_HOST=localhost
CHROMEDRIVER_PORT=3590
CHROMEDRIVER_PORT=2390
CHROMEDRIVER_BINARY=vendor/bin/chromedriver
TEST_TMP_ROOT_DIR=var/tmp
TEST_CACHE_DIR=var/tmp/_cache
1 change: 1 addition & 0 deletions tests/_data/fs-templates/bedrock/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
}
],
"require": {
"php": ">=8.0",
"composer/installers": "^2.2",
"vlucas/phpdotenv": "^5.5",
"oscarotero/env": "^2.1",
Expand Down
3 changes: 0 additions & 3 deletions tests/unit/Codeception/Template/WpbrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ public function should_scaffold_for_plugin_with_plugin_php_file_custom(): void
$process->mustRun();

// Remove the generated files that are not needed for the snapshot.
unlink($projectDir . '/plugin_89/' . Codeception::dataDir() . '/dump.sql');
FS::rrmdir($projectDir . '/plugin_89/' . Codeception::supportDir() . '/_generated');
FS::rrmdir($projectDir . '/plugin_89/tests/_wordpress');
FS::rrmdir($projectDir . '/plugin_89/vendor');
Expand Down Expand Up @@ -286,7 +285,6 @@ public function should_scaffold_for_plugin_with_non_plugin_php_file_custom(): vo
$process->mustRun();

// Remove the generated files that are not needed for the snapshot.
unlink($projectDir . '/plugin_89/' . Codeception::dataDir() . '/dump.sql');
FS::rrmdir($projectDir . '/plugin_89/' . Codeception::supportDir() . '/_generated');
FS::rrmdir($projectDir . '/plugin_89/tests/_wordpress');
FS::rrmdir($projectDir . '/plugin_89/vendor');
Expand Down Expand Up @@ -480,7 +478,6 @@ public function should_scaffold_for_theme_custom_correctly(): void
$process->mustRun();

// Remove the generated files that are not needed for the snapshot.
unlink($projectDir . '/theme_23/' . Codeception::dataDir() . '/dump.sql');
FS::rrmdir($projectDir . '/theme_23/' . Codeception::supportDir() . '/_generated');
FS::rrmdir($projectDir . '/theme_23/tests/_wordpress');
FS::rrmdir($projectDir . '/theme_23/vendor');
Expand Down
7 changes: 1 addition & 6 deletions tests/unit/lucatume/WPBrowser/Events/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Codeception\Events;
use Codeception\Test\Unit;
use lucatume\WPBrowser\Tests\Traits\UopzFunctions;
use lucatume\WPBrowser\Utils\Property;
use Psr\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;

Expand Down Expand Up @@ -92,11 +91,7 @@ function should_return_a_purposely_built_dispatcher_when_the_codeception_instanc

Dispatcher::setEventDispatcher();

$eventDispatcherInterface = interface_exists(\Psr\EventDispatcher\EventDispatcherInterface::class) ?
EventDispatcherInterface::class
: \Symfony\Component\EventDispatcher\EventDispatcherInterface::class;

$this->assertInstanceOf($eventDispatcherInterface, Dispatcher::getEventDispatcher());
$this->assertInstanceOf(EventDispatcherInterface::class, Dispatcher::getEventDispatcher());
$this->assertNotSame($previousDispatcher, Dispatcher::getEventDispatcher());

$callStack = [];
Expand Down
40 changes: 11 additions & 29 deletions tests/unit/lucatume/WPBrowser/Module/Support/DbDumpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,6 @@

class DbDumpTest extends Unit
{
private function assertMatchesRegularExpressionCompat(string $pattern, string $string, string $message = ''): void
{
if (method_exists(Assert::class, 'assertMatchesRegularExpression')) {
Assert::assertMatchesRegularExpression($pattern, $string, $message);
return;
}
Assert::assertRegExp($pattern, $string, $message);
}

private function assertDoesNotMatchRegularExpressionCompat(string $pattern, string $string, string $message = ''): void
{
if (method_exists(Assert::class, 'assertDoesNotMatchRegularExpression')) {
Assert::assertDoesNotMatchRegularExpression($pattern, $string, $message);
return;
}
Assert::assertNotRegExp($pattern, $string, $message);
}

/**
* @var string
*/
Expand All @@ -49,8 +31,8 @@ public function it_should_not_replace_the_site_domain_if_site_domain_is_same():

$sql = $sut->replaceSiteDomainInSqlString($sql);

$this->assertMatchesRegularExpressionCompat('~.*original.dev.*~', $sql);
$this->assertDoesNotMatchRegularExpressionCompat('/.*some-wp.dev.*/', $sql);
$this->assertMatchesRegularExpression('~.*original.dev.*~', $sql);
$this->assertDoesNotMatchRegularExpression('/.*some-wp.dev.*/', $sql);
}

/**
Expand All @@ -70,8 +52,8 @@ public function it_should_replace_the_site_domain_in_dump(): void

$sql = $sut->replaceSiteDomainInSqlString($sql);

$this->assertMatchesRegularExpressionCompat('/.*some-wp.dev.*/', $sql);
$this->assertDoesNotMatchRegularExpressionCompat('~.*original.dev/wp.*~', $sql);
$this->assertMatchesRegularExpression('/.*some-wp.dev.*/', $sql);
$this->assertDoesNotMatchRegularExpression('~.*original.dev/wp.*~', $sql);
}

/**
Expand All @@ -93,8 +75,8 @@ public function it_should_replace_https_schema_with_http(): void

$sql = $sut->replaceSiteDomainInSqlString($sql);

$this->assertMatchesRegularExpressionCompat('~.*http:\\/\\/some-wp.dev.*~', $sql);
$this->assertDoesNotMatchRegularExpressionCompat('~.*https:\\/\\/original.dev/wp.*~', $sql);
$this->assertMatchesRegularExpression('~.*http:\\/\\/some-wp.dev.*~', $sql);
$this->assertDoesNotMatchRegularExpression('~.*https:\\/\\/original.dev/wp.*~', $sql);
}

/**
Expand All @@ -116,8 +98,8 @@ public function it_should_replace_http_schema_with_https(): void

$sql = $sut->replaceSiteDomainInSqlString($sql);

$this->assertMatchesRegularExpressionCompat('~.*https:\\/\\/some-wp.dev.*~', $sql);
$this->assertDoesNotMatchRegularExpressionCompat('~.*https:\\/\\/original.dev/wp.*~', $sql);
$this->assertMatchesRegularExpression('~.*https:\\/\\/some-wp.dev.*~', $sql);
$this->assertDoesNotMatchRegularExpression('~.*https:\\/\\/original.dev/wp.*~', $sql);
}

/**
Expand Down Expand Up @@ -150,7 +132,7 @@ public function it_should_not_replace_domain_in_sites_and_blogs_table_if_domain_

$sql = $sut->replaceSiteDomainInMultisiteSqlString($sut->replaceSiteDomainInSqlString($sql));

$this->assertMatchesRegularExpressionCompat('~.*original.dev/wp.*~', $sql);
$this->assertMatchesRegularExpression('~.*original.dev/wp.*~', $sql);
}

/**
Expand Down Expand Up @@ -183,8 +165,8 @@ public function it_should_replace_domain_in_sites_and_blogs_table_if_domain_is_n

$sql = $sut->replaceSiteDomainInMultisiteSqlString($sut->replaceSiteDomainInSqlString($sql));

$this->assertMatchesRegularExpressionCompat('~.*some-wp.dev.*~', $sql);
$this->assertDoesNotMatchRegularExpressionCompat('~.*original.dev/wp.*~', $sql);
$this->assertMatchesRegularExpression('~.*some-wp.dev.*~', $sql);
$this->assertDoesNotMatchRegularExpression('~.*original.dev/wp.*~', $sql);
}

/**
Expand Down
Loading

0 comments on commit 74f3a6e

Please sign in to comment.