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

PHPUnit 10 #6059

Merged
merged 17 commits into from
Dec 31, 2023
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 .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
extensions: ${{ env.extensions }}
ini-values: ${{ env.ini }}
coverage: pcov
tools: phpunit:9.5.26, psalm:5.15.0
tools: phpunit:10.5.5, psalm:5.15.0

- name: Setup problem matchers
run: |
Expand All @@ -119,7 +119,7 @@ jobs:

- name: Run tests
if: always() && steps.finishPrepare.outcome == 'success'
run: phpunit --coverage-clover ${{ github.workspace }}/clover.xml
run: phpunit --fail-on-skipped --coverage-clover ${{ github.workspace }}/clover.xml

- name: Statically analyze using Psalm
if: always() && steps.finishPrepare.outcome == 'success'
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/.idea

# tests
.phpunit.result.cache
.phpunit.cache
/tests/coverage

# ignore all the vendor cruft
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@
"@test"
],
"fix": "php-cs-fixer fix",
"test": "phpunit --stderr",
"test:coverage": "XDEBUG_MODE=coverage phpunit --stderr --coverage-html=tests/coverage",
"test": "phpunit",
"test:coverage": "XDEBUG_MODE=coverage phpunit --coverage-html=tests/coverage",
"zip": "composer archive --format=zip --file=dist"
}
}
2 changes: 1 addition & 1 deletion config/fields/structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
},
'form' => function (array $values = []) {
return new Form([
'fields' => $this->attrs['fields'],
'fields' => $this->attrs['fields'] ?? [],
'values' => $values,
'model' => $this->model
]);
Expand Down
28 changes: 20 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"

xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
beStrictAboutOutputDuringTests="true"
bootstrap="tests/bootstrap.php"
convertDeprecationsToExceptions="true"
cacheDirectory=".phpunit.cache"
colors="true"
verbose="true"
controlGarbageCollector="true"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
failOnDeprecation="true"
failOnEmptyTestSuite="true"
failOnIncomplete="true"
failOnNotice="true"
failOnRisky="true"
failOnWarning="true"
stderr="true"
>

<coverage ignoreDeprecatedCodeUnits="true">
<source>
<include>
<directory>./config</directory>
<directory>./src</directory>
Expand All @@ -23,7 +33,7 @@
<file>./config/aliases.php</file>
<file>./config/setup.php</file>
</exclude>
</coverage>
</source>

<testsuites>
<testsuite name="Classes">
Expand All @@ -34,4 +44,6 @@
<php>
<ini name="memory_limit" value="2048M" />
</php>

<coverage ignoreDeprecatedCodeUnits="true" />
</phpunit>
8 changes: 4 additions & 4 deletions src/Filesystem/F.php
Original file line number Diff line number Diff line change
Expand Up @@ -800,11 +800,11 @@ public static function size(string|array $file): int
);
}

try {
return filesize($file);
} catch (Throwable) {
return 0;
if ($size = @filesize($file)) {
return $size;
}

return 0;
}

/**
Expand Down
11 changes: 5 additions & 6 deletions src/Session/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Kirby\Http\Url;
use Kirby\Toolkit\Str;
use Kirby\Toolkit\SymmetricCrypto;
use Throwable;

/**
* @package Kirby Session
Expand Down Expand Up @@ -661,6 +660,7 @@ protected function init(): void
// skip if we don't have the key (only the case for moved sessions)
$hmac = Str::before($data, "\n");
$data = trim(Str::after($data, "\n"));

if (
$this->tokenKey !== null &&
hash_equals(hash_hmac('sha256', $data, $this->tokenKey), $hmac) !== true
Expand All @@ -675,16 +675,15 @@ protected function init(): void
}

// decode the serialized data
try {
$data = unserialize($data);
} catch (Throwable $e) {
$data = @unserialize($data);

if ($data === false) {
throw new LogicException([
'key' => 'session.invalid',
'data' => ['token' => $this->token()],
'fallback' => 'Session "' . $this->token() . '" is invalid',
'translate' => false,
'httpCode' => 500,
'previous' => $e
'httpCode' => 500
]);
}

Expand Down
25 changes: 25 additions & 0 deletions src/Toolkit/A.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,31 @@ public static function has(
return in_array($value, $array, $strict);
}

/**
* Join array elements as a string,
* also supporting nested arrays
*/
public static function implode(
array $array,
string $separator = ''
): string {
$result = '';

foreach ($array as $value) {
if (empty($result) === false) {
$result .= $separator;
}

if (is_array($value) === true) {
$value = static::implode($value, $separator);
}

$result .= $value;
}

return $result;
}

/**
* Checks whether an array is associative or not
*
Expand Down
13 changes: 5 additions & 8 deletions src/Toolkit/V.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,13 @@ public static function message(
$value = $params[$index] ?? null;

if (is_array($value) === true) {
try {
foreach ($value as $key => $item) {
if (is_array($item) === true) {
$value[$key] = implode('|', $item);
}
foreach ($value as $key => $item) {
if (is_array($item) === true) {
$value[$key] = A::implode($item, '|');
}
$value = implode(', ', $value);
} catch (Throwable) {
$value = '-';
}

$value = implode(', ', $value);
}

$arguments[$parameter->getName()] = $value;
Expand Down
4 changes: 0 additions & 4 deletions tests/Cms/Helpers/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,6 @@ function (int $errno, string $errstr) {
*/
public function testHandleErrorsWarningCaughtCallbackValue()
{
// TODO: This line should not be necessary
// https://github.com/getkirby/kirby/pull/6093#issuecomment-1872569768
$this->activeErrorHandlers++;

$this->assertSame('handled', Helpers::handleErrors(
fn () => trigger_error('Some warning', E_USER_WARNING),
fn (int $errno, string $errstr) => true,
Expand Down
2 changes: 1 addition & 1 deletion tests/Session/FileSessionStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function tearDown(): void
}

Dir::remove($this->root);
$this->assertDirectoryNotExists($this->root);
$this->assertDirectoryDoesNotExist($this->root);
}

/**
Expand Down
9 changes: 6 additions & 3 deletions tests/Template/SnippetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@ public function testFactory()
]
]);

$openProp = new ReflectionProperty(Snippet::class, 'open');
$openProp->setAccessible(true);

$snippet = Snippet::factory('data', ['message' => 'hello']);
$this->assertSame('hello', $snippet);

$snippet = Snippet::factory('simple', slots: true);
$this->assertInstanceOf(Snippet::class, $snippet);

$openProp = new ReflectionProperty($snippet, 'open');
$openProp->setAccessible(true);
$this->assertTrue($openProp->getValue($snippet));
$snippet->close(); // close output buffers to reset global state

$snippet = Snippet::factory(null, ['message' => 'hello']);
$this->assertSame('', $snippet);
Expand All @@ -57,9 +58,11 @@ public function testFactory()

$snippet = Snippet::factory('missin', ['message' => 'hello'], slots: true);
$this->assertInstanceOf(Snippet::class, $snippet);
$snippet->close(); // close output buffers to reset global state

$snippet = Snippet::factory(null, ['message' => 'hello'], slots: true);
$this->assertInstanceOf(Snippet::class, $snippet);
$snippet->close(); // close output buffers to reset global state
}

/**
Expand Down
16 changes: 16 additions & 0 deletions tests/Toolkit/ATest.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,22 @@ public function testHas()
$this->assertFalse(A::has($array, ['miao']));
}

/**
* @covers ::implode
*/
public function testImplode()
{
$array = ['a', 'b', 'c'];
$this->assertSame('abc', A::implode($array));
$this->assertSame('a|b|c', A::implode($array, '|'));

$array = ['a' => 'A', 'b' => 'B', 'c' => 'C'];
$this->assertSame('ABC', A::implode($array));

$array = ['a' => 'A', 'b' => 'B', 'c' => ['C', 'D']];
$this->assertSame('ABCD', A::implode($array));
}

/**
* @covers ::map
*/
Expand Down
File renamed without changes.