Skip to content

Commit

Permalink
Merge pull request #74 from inpsyde/3.x-proposal
Browse files Browse the repository at this point in the history
refactor: Update package to support php >=8 and Psr Log 2 || 3
  • Loading branch information
luislard authored Mar 7, 2024
2 parents a0c8bd8 + 6861514 commit db77d35
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-service: [ '72', '73', '74', '80', '81', '82' ]
php-service: [ '81', '82' ]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/php-static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@ jobs:
uses: inpsyde/reusable-workflows/.github/workflows/lint-php.yml@main
if: ${{ (github.event_name != 'workflow_dispatch') || ((github.event.inputs.jobs == 'Run all') || (github.event.inputs.jobs == 'Run lint only')) }}
with:
PHP_MATRIX: '["7.2", "7.3", "7.4", "8.0", "8.1", "8.2"]'
PHP_MATRIX: '["8.1", "8.2"]'

coding-standards-analysis-php:
if: ${{ (github.event_name != 'workflow_dispatch') || ((github.event.inputs.jobs == 'Run all') || (github.event.inputs.jobs == 'Run PHPCS only')) }}
uses: inpsyde/reusable-workflows/.github/workflows/coding-standards-php.yml@main
with:
PHP_VERSION: '8.1'

static-code-analysis-php:
if: ${{ (github.event_name != 'workflow_dispatch') || ((github.event.inputs.jobs == 'Run all') || (github.event.inputs.jobs == 'Run Psalm only')) }}
uses: inpsyde/reusable-workflows/.github/workflows/static-analysis-php.yml@main
strategy:
matrix:
php-version: [ '8.1', '8.2' ]
with:
PHP_VERSION: ${{ matrix.php-version }}
5 changes: 4 additions & 1 deletion .github/workflows/php-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
php-versions: [ '8.1', '8.2' ]
dependency-versions: ['highest', 'lowest']

steps:
- name: Checkout
Expand All @@ -44,6 +45,8 @@ jobs:

- name: Install Composer dependencies
uses: ramsey/composer-install@v2
with:
dependency-versions: ${{ matrix.dependency-versions }}

- name: Run unit tests
run: composer tests:unit:${{ ((env.USE_COVERAGE == 'yes') && 'codecov') || 'no-cov' }}
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@

# Docker
.github/workflows/docker/php*/*.sh

# Adding a folder to put things temporarily
temp/

# IDE
.idea/

11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,23 @@
}
],
"require": {
"php": ">=7.2 < 8.3",
"psr/log": "^1.1.4",
"php": ">=8.1 < 8.3",
"psr/log": "^2.0||^3.0",
"wecodemore/wordpress-early-hook": "^1.1.0",
"monolog/monolog": "^2.3.5"
},
"require-dev": {
"phpunit/phpunit": "^8.5.33",
"brain/monkey": "^2.6.1",
"mockery/mockery": "^1.3.6",
"mikey179/vfsstream": "~v1.6.11",
"inpsyde/php-coding-standards": "^1",
"vimeo/psalm": "^4.30.0",
"inpsyde/wp-stubs-versions": "dev-latest",
"roots/wordpress-no-content": ">=6.1.1",
"symfony/process": "^v4.4.44",
"globalis/wp-cli-bin": "^2.7.1"
"globalis/wp-cli-bin": "^2.7.1",
"vimeo/psalm": "^5.15",
"phpunit/phpunit": "^9.6",
"fig/log-test": "^1.1"
},
"provide": {
"psr/log-implementation": "1.0.0"
Expand Down
60 changes: 28 additions & 32 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
convertDeprecationsToExceptions="true"
processIsolation="false"
stopOnFailure="false">

<extensions>
<extension class="Inpsyde\Wonolog\Tests\IntegrationTestsExtension"/>
</extensions>

<testsuites>
<testsuite name="unit">
<directory suffix="Test.php">tests/unit</directory>
</testsuite>
<testsuite name="integration">
<directory suffix="Test.php">tests/integration</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
convertDeprecationsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<extensions>
<extension class="Inpsyde\Wonolog\Tests\IntegrationTestsExtension"/>
</extensions>
<testsuites>
<testsuite name="unit">
<directory suffix="Test.php">tests/unit</directory>
</testsuite>
<testsuite name="integration">
<directory suffix="Test.php">tests/integration</directory>
</testsuite>
</testsuites>
</phpunit>
14 changes: 12 additions & 2 deletions src/Data/FailedLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,25 @@ private function countAttempts(int $ttl = 300): void
|| !isset($attempts[$userIp]['count'])
|| !isset($attempts[$userIp]['last_logged'])
) {
$attempts[$userIp] = ['count' => 0, 'last_logged' => 0];
/**
* @var array<string, array{count: int, last_logged: int}> $data
*/
$data = ['count' => 0, 'last_logged' => 0];
$attempts[$userIp] = $data;
}

/** @psalm-suppress MixedOperand */
$attempts[$userIp]['count']++;
/** @psalm-suppress PropertyTypeCoercion */
/** @psalm-suppress InvalidPropertyAssignmentValue */
$this->attemptsData = $attempts;

/**
* Psalm warns us about count and last_logged possibly being bool to int converted
* We assume the value retrieved when calling get_site_transient is an integer on both
* @psalm-suppress RiskyCast
*/
$count = (int)$attempts[$userIp]['count'];
/** @psalm-suppress RiskyCast */
$lastLogged = (int)$attempts[$userIp]['last_logged'];

/**
Expand Down
4 changes: 4 additions & 0 deletions src/DefaultHandler/LogsFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ public static function determineFolder(?string $customFolder = null): ?string
* them, and package could be fully functional even if failures happen.
* Silence looks like best option here.
*
* Also for some reason __return_true seems not to be a valid argument?
* I found this related issue https://github.com/vimeo/psalm/issues/3571
*
* phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_set_error_handler
* @psalm-suppress PossiblyInvalidArgument
*/
set_error_handler('__return_true');

Expand Down
2 changes: 1 addition & 1 deletion src/HookListener/CronDebugListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private function registerEventListener(LogActionUpdater $updater): void
}

$cronArray = _get_cron_array();
/** @psalm-suppress DocblockTypeContradiction */
/** @psalm-suppress TypeDoesNotContainType,DocblockTypeContradiction */
if (!$cronArray || !is_array($cronArray)) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/PsrBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function withDefaultChannel(string $defaultChannel): PsrBridge
*
* phpcs:disable Generic.Metrics.CyclomaticComplexity
*/
public function log($level, $message, array $context = [])
public function log($level, $message, array $context = []): void
{
// phpcs:enable Generic.Metrics.CyclomaticComplexity
$throwable = null;
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/HookListener/CronDebugListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ static function (LogData $log) use (&$logs): void {

$regxp = '~^Cron action "%s" performed\. Duration: [0|1]\.[0-9]+ seconds\.$~';

static::assertRegExp(sprintf($regxp, 'wp_scheduled_delete'), $logs[0]);
static::assertRegExp(sprintf($regxp, 'wp_update_plugins'), $logs[1]);
static::assertRegExp(sprintf($regxp, 'wp_version_check'), $logs[2]);
static::assertMatchesRegularExpression(sprintf($regxp, 'wp_scheduled_delete'), $logs[0]);
static::assertMatchesRegularExpression(sprintf($regxp, 'wp_update_plugins'), $logs[1]);
static::assertMatchesRegularExpression(sprintf($regxp, 'wp_version_check'), $logs[2]);
}
}

0 comments on commit db77d35

Please sign in to comment.