Skip to content

Commit

Permalink
fix(src) second testing pass
Browse files Browse the repository at this point in the history
  • Loading branch information
lucatume committed Jun 6, 2023
1 parent b7fcbfc commit cd877c5
Show file tree
Hide file tree
Showing 279 changed files with 11,691 additions and 21,358 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow

name: "Integrate"
name: "Static Analysis"

on: # yamllint disable-line rule:truthy
push:
Expand Down Expand Up @@ -41,8 +41,8 @@ jobs:
name: "Check PSR-4 mapping"
run: "composer dump-autoload --no-interaction --optimize --strict-psr"
-
name: "Install WordPress extension for PHPStan"
run: "composer require --dev szepeviktor/phpstan-wordpress"
name: "Run PHPHStan"
run: "composer run stan"
-
name: "Perform static analysis"
run: "composer exec -- phpstan"
name: "Run PHP Code Sniffer"
run: "composer run cs"
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Added support for the `dbUrl` configuration parameter to the `WPDb` module; it allows providing the database username, password and DSN with a single URL; e.g. `mysql://user:password@host:port/db_name`.
- Rewrite the `WPCLI` module to use the `Symfony\Component\Process\Process` class under the hood.
- Added the `WPCLI::dontSeeShellOutputMatches` method
- Removed the `WithWordPressFilters` trai
- Update the `WPCLI` module to use supported configuration parameters as strict arguments by default
- Removed the `WithWordPressFilters` trait
- Temporarily remove the `preserveGlobalState` test method support to reimplement support later.

## [3.1.6] 2022-04-28;

Expand Down
5 changes: 3 additions & 2 deletions bin/stack
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function print_help() {
echo " phpstan Run PHPStan for the specified PHP version."
echo " ps Show the status of the containers for the specified PHP version."
echo " ssh SSH into a service for the specified PHP version."
echo " test Run all the tests for the specified PHP version."
echo " up Starts the containers for the specified PHP version."
echo " xdebug-off Deactivates XDebug in the WordPress and Codeception service."
echo " xdebug-on Activates XDebug in the WordPress and Codeception service."
Expand Down Expand Up @@ -85,9 +86,9 @@ export PWD="$(pwd)"

# If the current architecture is arm64, use the arm64v8 images.
if [ "$(arch)" = "arm64" ]; then
export DOCKER_CHROME_IMAGE="seleniarm/standalone-chromium:112.0-20230422"
export DOCKER_CHROME_IMAGE="seleniarm/standalone-chromium:113.0-20230508"
else
export DOCKER_CHROME_IMAGE="selenium/standalone-chrome:3.141.59-20210105"
export DOCKER_CHROME_IMAGE="selenium/standalone-chrome:113.0-20230508"
fi

function ensure_twentytwenty_theme() {
Expand Down
8 changes: 2 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"_hash": "11223344",
"name": "lucatume/wp-browser",
"type": "library",
"description": "WordPress extension of the PhpBrowser class.",
"description": "A set of Codeception modules to test WordPress projects.",
"keywords": [
"wordpress",
"codeception"
Expand Down Expand Up @@ -64,10 +63,7 @@
"autoload-dev": {
"psr-4": {
"lucatume\\WPBrowser\\Tests\\": "tests/_support"
},
"files": [
"tests/_support/functions.php"
]
}
},
"extra": {
"_hash": "484f861f69198089cab0e642f27e5653"
Expand Down
2 changes: 2 additions & 0 deletions config/phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
<exclude-pattern>src/MonkeyPatch/FileStreamWrapper.php</exclude-pattern>
</rule>

<exclude-pattern>./tests/*</exclude-pattern>
</ruleset>
11 changes: 11 additions & 0 deletions cronaca.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
2023-05-04
Anno 0.
Il gruppo si forma.
Primavera anno 0: Khitri guida un gruppo di Barkoff (Anton, Yana, Marko) nella foresta a nord di Sievepie per la caccia. Il suo tentativo di evitare che Marko uccida una orsa le costa il lavoro ed una quasi uccisione da parte di Marko. La guardia del corpo dei Barkoff la mette fuori gioco.
Aster tenta di sedurre Yana Barkoff e viene catturato dagli uomini di Barkoff.
Marko Barkoff intende sacrificare Aster a Belal per ricevere potere.
Queona ed Emdur irrompono sulla scena, Marko Barkoff ucciso da Queona nello scontro.
Fuga di Queona, Emdur e Aster verso il tempio di Cendur a Shin.
Taglia sugli assassini di Marko da parte dei Barkoff.
Sulla strada incontrano Khitri che cerca fuggitivi, Aster mette Khitri sotto un incantesimo di charme.

4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ services:
retries: 5
chrome:
container_name: wpbrowser_php_${PHP_VERSION:-8.0}_chrome
image: ${DOCKER_CHROME_IMAGE:-selenium/standalone-chrome:3.141.59-20210105}
image: ${DOCKER_CHROME_IMAGE:-selenium/standalone-chrome:113.0-20230508}
networks:
- test
ports:
- "8959:5900" # VNC, password: secret
depends_on:
wordpress:
condition: service_healthy
Expand Down
3 changes: 3 additions & 0 deletions includes/core-phpunit/wp-tests-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
* @var array<string,mixed> $wpLoaderConfig A map of configuration values hydrated by the WPLoader module.
*/

use Codeception\Exception\ModuleConfigException;
use lucatume\WPBrowser\Module\WPLoader;
use lucatume\WPBrowser\Utils\CorePHPUnit;
use lucatume\WPBrowser\Utils\Filesystem;

$didReadConfigFromEnvVar = false;
global $wpLoaderConfig, $wpLoaderIncludeWpSettings;
Expand Down
2 changes: 1 addition & 1 deletion src/Command/GenerateWPAjax.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function getDescription(): string
*
* @return WPUnit The built generator.
*/
protected function getGenerator(array $config, string $class): \lucatume\WPBrowser\Lib\Generator\WPUnit
protected function getGenerator(array $config, string $class): WPUnit
{
return new WPUnit($config, $class, WPAjaxTestCase::class);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/GenerateWPCanonical.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function getDescription(): string
*
* @return WPUnit The built generator.
*/
protected function getGenerator(array $config, string $class): \lucatume\WPBrowser\Lib\Generator\WPUnit
protected function getGenerator(array $config, string $class): WPUnit
{
return new WPUnit($config, $class, WPCanonicalTestCase::class);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Command/RunAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Codeception\Command\Run as CodeceptionRunCommand;
use Codeception\Command\Shared\ConfigTrait;
use Codeception\CustomCommandInterface;
use Exception;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -57,7 +58,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if (!$process->isSuccessful()) {
return 1;
}
} catch (\Exception $e) {
} catch (Exception $e) {
$output->writeln($e->getMessage());
return 1;
}
Expand Down
8 changes: 5 additions & 3 deletions src/Generators/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace lucatume\WPBrowser\Generators;

use InvalidArgumentException;

/**
* Class Date
*
Expand All @@ -20,9 +22,9 @@ class Date
public const DATE_FORMAT = 'Y-m-d H:i:s';

/**
* @var int An injectable time value, used in tests.
* @var ?int An injectable time value, used in tests.
*/
protected static int $time;
protected static ?int $time = null;

/**
* Returns the current time in WordPress specific format.
Expand Down Expand Up @@ -89,7 +91,7 @@ public static function fromString(string $strtotime): string
$timestamp = strtotime($strtotime);

if ($timestamp === false) {
throw new \InvalidArgumentException('Invalid time: ' . $strtotime);
throw new InvalidArgumentException('Invalid time: ' . $strtotime);
}

return date(self::DATE_FORMAT);
Expand Down
12 changes: 7 additions & 5 deletions src/Generators/Tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

namespace lucatume\WPBrowser\Generators;

use InvalidArgumentException;
use lucatume\WPBrowser\Utils\Strings;
use RuntimeException;

/**
* Class Tables
Expand Down Expand Up @@ -90,12 +92,12 @@ private function alterableTables(): array
*
* @return string The rendered SQL query.
*
* @throws \InvalidArgumentException If the table name is not a valid table name.
* @throws InvalidArgumentException If the table name is not a valid table name.
*/
protected function renderQuery(string $table, array $data): string
{
if (!in_array($table, $this->tables(), true)) {
throw new \InvalidArgumentException('Table ' . $table . ' is not a valid table name');
throw new InvalidArgumentException('Table ' . $table . ' is not a valid table name');
}

$template = $this->templates($table);
Expand Down Expand Up @@ -144,20 +146,20 @@ public static function multisiteTables(string $table_prefix = ''): array
*
* @return string The SQL query.
*
* @throws \RuntimeException If the SQL query cannot be fetched.
* @throws RuntimeException If the SQL query cannot be fetched.
*/
protected function templates(string $table): string
{
$templateFile = $this->templatesDir . DIRECTORY_SEPARATOR . "{$table}.handlebars";

if (!is_file($templateFile)) {
throw new \RuntimeException("Template file {$templateFile} not found.");
throw new RuntimeException("Template file {$templateFile} not found.");
}

$queryTemplate = file_get_contents($templateFile);

if (false === $queryTemplate) {
throw new \RuntimeException("Template file {$templateFile} could not be read.");
throw new RuntimeException("Template file {$templateFile} could not be read.");
}

return $queryTemplate;
Expand Down
2 changes: 1 addition & 1 deletion src/Generators/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static function generateUserTableDataFrom(string $user_login, array $user
'user_pass' => WP::passwordHash($user_login),
'user_nicename' => $user_login,
'user_email' => $login . "@example.com",
'user_url' => "https://{$login}.example.com",
'user_url' => "https://$login.example.com",
'user_registered' => Date::now() ?: '0000-00-00 00:00:00',
'user_activation_key' => '',
'user_status' => '0',
Expand Down
2 changes: 1 addition & 1 deletion src/Iterators/Filters/ActionsQueriesFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ActionsQueriesFilter extends QueriesCallerBasedKeepingFilterIterator
/**
* ClassMethodQueriesFilter constructor.
*
* @param Iterator<string> $iterator The iterator to filter.
* @param Iterator<array{0: string, 1: float, 2: string, 3: float, 4?: array<int|string,mixed>}> $iterator
* @param string $action The action to filter queries by.
*/
public function __construct(Iterator $iterator, $action)
Expand Down
2 changes: 1 addition & 1 deletion src/Iterators/Filters/ClassMethodQueriesFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ClassMethodQueriesFilter extends QueriesCallerBasedKeepingFilterIterator
/**
* ClassMethodQueriesFilter constructor.
*
* @param Iterator<string> $iterator The iterator to filter.
* @param Iterator<array{0: string, 1: float, 2: string, 3: float, 4?: array<int|string,mixed>}> $iterator
* @param string $class The class to filter queries by.
* @param string $method The class method to filter queries by.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Iterators/Filters/FiltersQueriesFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FiltersQueriesFilter extends QueriesCallerBasedKeepingFilterIterator
{
/**
* ClassMethodQueriesFilter constructor.
* @param Iterator<string> $iterator The iterator to filter.
* @param Iterator<array{0: string, 1: float, 2: string, 3: float, 4?: array<int|string,mixed>}> $iterator
* @param string $filter The filter handle to filter queries by.
*/
public function __construct(Iterator $iterator, $filter)
Expand Down
2 changes: 1 addition & 1 deletion src/Iterators/Filters/FunctionQueriesFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FunctionQueriesFilter extends QueriesCallerBasedKeepingFilterIterator
/**
* ClassMethodQueriesFilter constructor.
*
* @param Iterator<string> $iterator The iterator to filter.
* @param Iterator<array{0: string, 1: float, 2: string, 3: float, 4?: array<int|string,mixed>}> $iterator
* @param string $function The function to filter queries by.
*/
public function __construct(Iterator $iterator, $function)
Expand Down
7 changes: 4 additions & 3 deletions src/Iterators/Filters/MainStatementQueriesFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace lucatume\WPBrowser\Iterators\Filters;

use FilterIterator;
use Iterator;
use lucatume\WPBrowser\Utils\Strings;

Expand All @@ -15,12 +16,12 @@
*
* @package lucatume\WPBrowser\Iterators\Filters
*/
class MainStatementQueriesFilter extends \FilterIterator
class MainStatementQueriesFilter extends FilterIterator
{
/**
* MainStatementQueriesFilter constructor.
*
* @param Iterator<string> $iterator
* @param Iterator<array{0: string, 1: float, 2: string, 3: float, 4?: array<int|string,mixed>}> $iterator
* @param string $statement The statement to keep queries for.
*/
public function __construct(Iterator $iterator, protected $statement = 'SELECT')
Expand All @@ -37,7 +38,7 @@ public function __construct(Iterator $iterator, protected $statement = 'SELECT')
*/
public function accept(): bool
{
/** @var array{0: string, 1: int, 2: string} $query */
/** @var array{0: string, 1: float, 2: string, 3: float, 4?: array<int|string,mixed>} $query */
$query = $this->getInnerIterator()->current();
$pattern = Strings::isRegex($this->statement) ? $this->statement : '/^' . $this->statement . '/i';
/** @noinspection NotOptimalRegularExpressionsInspection */
Expand Down
4 changes: 3 additions & 1 deletion src/Iterators/Filters/QueriesCallerBasedFilterIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

namespace lucatume\WPBrowser\Iterators\Filters;

use FilterIterator;

/**
* Class QueriesCallerBasedFilterIterator
*
* @package lucatume\WPBrowser\Iterators\Filters
*/
abstract class QueriesCallerBasedFilterIterator extends \FilterIterator
abstract class QueriesCallerBasedFilterIterator extends FilterIterator
{
/**
* The list of callers to look for.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

namespace lucatume\WPBrowser\Iterators\Filters;

use FilterIterator;

/**
* Class QueriesCallerBasedKeepingFilterIterator
*
* @package lucatume\WPBrowser\Iterators\Filters
*/
class QueriesCallerBasedKeepingFilterIterator extends \FilterIterator
class QueriesCallerBasedKeepingFilterIterator extends FilterIterator
{

/**
Expand All @@ -31,7 +33,7 @@ class QueriesCallerBasedKeepingFilterIterator extends \FilterIterator
*/
public function accept(): bool
{
/** @var array{0: string, 1: int, 2: string} $query */
/** @var array{0: string, 1: float, 2: string, 3: float, 4?: array<int|string,mixed>} $query */
$query = $this->getInnerIterator()->current();
foreach ($this->needles as $needle) {
if (preg_match("/(?<!\\(')" . preg_quote($needle, '/') . "(?!'\\))/", $query[2])) {
Expand Down
5 changes: 3 additions & 2 deletions src/Lib/Generator/AbstractGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace lucatume\WPBrowser\Lib\Generator;

use BadMethodCallException;
use Codeception\Util\Template;

abstract class AbstractGenerator
Expand Down Expand Up @@ -40,7 +41,7 @@ protected function ensureSettings(): bool

foreach (static::$requiredSettings as $requiredSetting) {
if (!isset($this->settings[$requiredSetting])) {
throw new \BadMethodCallException('Required template setting [{' . $requiredSetting . '}] is missing.');
throw new BadMethodCallException('Required template setting [{' . $requiredSetting . '}] is missing.');
}
}

Expand All @@ -59,7 +60,7 @@ protected function ensureSettingsAreAllStrings(): bool
foreach (static::$requiredSettings as $requiredSetting) {
if (!is_string($this->settings[$requiredSetting])) {
$message = 'Required template setting [{' . $requiredSetting . '}] is not a string.';
throw new \BadMethodCallException($message);
throw new BadMethodCallException($message);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Module/WPBrowserMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,12 +521,12 @@ protected function validateConfig(): void
{
$this->configBackCompat();

parent::validateConfig();

foreach (['adminUsername', 'adminPassword', 'adminPath'] as $param) {
if (!is_string($this->config[$param])) {
throw new ModuleConfigException($this, "Configuration parameter $param must be a string.");
}
}

parent::validateConfig();
}
}
Loading

0 comments on commit cd877c5

Please sign in to comment.