Skip to content
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
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ README text eol=lf
*.sqlite binary

# Ignore paths that should not be included in an archive (eg for a distribution version)
/.github export-ignore
/docs export-ignore
/test export-ignore
phpunit.xml export-ignore
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ jobs:
fail-fast: false
matrix:
php_version:
- '8.1'
- '8.2'
- '8.3'
dependencies:
- 'default'
include:
- php_version: '8.1'
dependencies: 'lowest'
- php_version: '8.2'
dependencies: 'lowest'
- php_version: '8.3'
dependencies: 'lowest'
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
### Unreleased

### v2.1.0 (2024-08-02)

* Support PHP 8.3
* Upgrade tests to support PHPUnit 11
* Drop support for PHP 8.1

### v2.0.0 (2023-10-27)

* Support psr/log ^1.1 || ^2.0 || ^3.0
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
],
"require": {
"ext-json": "*",
"ext-mbstring": "~8.1.0 || ~8.2.0",
"ext-pdo": "~8.1.0 || ~8.2.0",
"ext-sodium": "~8.1.0 || ~8.2.0",
"php": "~8.1.0 || ~8.2.0",
"ext-mbstring": "~8.2.0 || ~8.3.0",
"ext-pdo": "~8.2.0 || ~8.3.0",
"ext-sodium": "~8.2.0 || ~8.3.0",
"php": "~8.2.0 || ~8.3.0",
"psr/log": "^1.1 || ^2.0 || ^3.0"
},
"require-dev": {
"johnkary/phpunit-speedtrap": "^3.3",
"mikey179/vfsstream": "^1.6.11",
"phpunit/phpunit": "^9.5.5"
"phpunit/phpunit": "^11.0",
"ergebnis/phpunit-slow-test-detector": "^2.15"
},
"support": {
"source": "https://github.com/ingenerator/php-utils",
Expand Down
56 changes: 27 additions & 29 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,31 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="test/phpunit-bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
convertDeprecationsToExceptions="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="unit">
<directory>test/unit</directory>
</testsuite>
</testsuites>
<listeners>
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener">
<arguments>
<array>
<element key="slowThreshold">
<integer>200</integer>
</element>
<element key="reportLength">
<integer>20</integer>
</element>
</array>
</arguments>
</listener>
</listeners>
failOnDeprecation="true"
failOnNotice="true"
failOnWarning="true"
failOnRisky="true"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd">
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
<testsuites>
<testsuite name="unit">
<directory>test/unit</directory>
</testsuite>
</testsuites>
<extensions>
<bootstrap class="Ergebnis\PHPUnit\SlowTestDetector\Extension">
<parameter name="maximum-count" value="20"/>
<parameter name="maximum-duration" value="200"/>
</bootstrap>
</extensions>
</phpunit>
37 changes: 15 additions & 22 deletions test/unit/ArrayHelpers/AssociativeArrayUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@


use Ingenerator\PHPUtils\ArrayHelpers\AssociativeArrayUtils;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\TestCase;

class AssociativeArrayUtilsTest extends \PHPUnit\Framework\TestCase
class AssociativeArrayUtilsTest extends TestCase
{

/**
* @testWith [["one", "two", "three"], false]
* [{"1": "mixed indices", "5": "also mixed"}, true]
* [{"one": "o clock", "two": "o clock", "three": "o clock"}, true]
*/
#[TestWith([['one', 'two', 'three'], false])]
#[TestWith([[1 => 'mixed indices', 5 => 'also mixed'], true])]
#[TestWith([['one' => 'o clock', 'two' => 'o clock', 'three' => 'o clock'], true])]
public function test_is_associative(array $array, $expected)
{
$this->assertSame(
Expand All @@ -25,7 +26,7 @@ public function test_is_associative(array $array, $expected)
);
}

public function provider_paths_to_nested()
public static function provider_paths_to_nested(): array
{
return [
[
Expand All @@ -51,15 +52,13 @@ public function provider_paths_to_nested()
];
}

/**
* @dataProvider provider_paths_to_nested
*/
#[DataProvider('provider_paths_to_nested')]
public function test_it_converts_pathed_hash_to_nested_arrays($input, $expect)
{
$this->assertSame($expect, AssociativeArrayUtils::pathsToNested($input));
}

public function provider_pop_keys()
public static function provider_pop_keys(): array
{
return [
[
Expand Down Expand Up @@ -90,9 +89,7 @@ public function provider_pop_keys()
];
}

/**
* @dataProvider provider_pop_keys
*/
#[DataProvider('provider_pop_keys')]
public function test_it_can_pop_keys_from_a_source_array($source, $pop_keys, $expect)
{
$result = AssociativeArrayUtils::popKeys($source, $pop_keys);
Expand All @@ -104,7 +101,7 @@ public function test_it_can_pop_keys_from_a_source_array($source, $pop_keys, $ex
*
* @return array
*/
public function provider_set_path()
public static function provider_set_path(): array
{
return [
// Tests returns normal values
Expand All @@ -125,9 +122,7 @@ public function provider_set_path()
];
}

/**
* @dataProvider provider_set_path
*/
#[DataProvider('provider_set_path')]
public function test_set_path($expected, $array, ...$args)
{
AssociativeArrayUtils::setPath($array, ...$args);
Expand All @@ -136,7 +131,7 @@ public function test_set_path($expected, $array, ...$args)
}


public function provider_merge()
public static function provider_merge(): array
{
return [
// Test how it merges arrays and sub arrays with assoc keys
Expand Down Expand Up @@ -266,9 +261,7 @@ public function provider_merge()
];
}

/**
* @dataProvider provider_merge
*/
#[DataProvider('provider_merge')]
public function test_deep_merge($expected, ...$args)
{
$this->assertSame(
Expand Down
33 changes: 15 additions & 18 deletions test/unit/Assets/StaticAssetUrlProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
namespace test\unit\Ingenerator\PHPUtils\Assets;


use InvalidArgumentException;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamDirectory;
use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\TestCase;
use Ingenerator\PHPUtils\Assets\StaticAssetUrlProvider;
use RuntimeException;

class StaticAssetUrlProviderTest extends TestCase
{
Expand All @@ -31,21 +34,19 @@ public function test_it_is_initialisable()
public function test_it_throws_in_invalid_mode()
{
$this->options['mode'] = 'some-junk';
$this->expectException(\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$this->newSubject();
}

public function test_in_local_mode_get_url_throws_if_file_does_not_exist()
{
$subject = $this->newSubject();
$this->expectException(\RuntimeException::class);
$this->expectException(RuntimeException::class);
$subject->getUrl('assets/some-file.css');
}

/**
* @testWith ["assets/my-file.css"]
* ["/assets/my-file.css"]
*/
#[TestWith(['assets/my-file.css'])]
#[TestWith(['/assets/my-file.css'])]
public function test_in_local_mode_get_url_returns_absolute_url_with_mtime_suffix($rel_path)
{
vfsStream::create(
Expand All @@ -67,17 +68,15 @@ public function test_in_remote_mode_get_url_throws_if_asset_base_url_file_does_n
{
$this->options['asset_base_url_file'] = $this->vfs->url().'/no-such-file.php';
$this->options['mode'] = StaticAssetUrlProvider::MODE_REMOTE;
$this->expectException(\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('no-such-file.php');
$this->newSubject();
}

/**
* @testWith [""]
* ["some content that is not php"]
* ["<?php $a = 1;"]
* ["<?php return '';"]
*/
#[TestWith([''])]
#[TestWith(['some content that is not php'])]
#[TestWith(['<?php $a = 1;'])]
#[TestWith(["<?php return '';"])]
public function test_in_remote_mode_get_url_throws_if_asset_base_url_file_does_not_return_string($file_content)
{
vfsStream::create(
Expand All @@ -87,15 +86,13 @@ public function test_in_remote_mode_get_url_throws_if_asset_base_url_file_does_n

$this->options['asset_base_url_file'] = $this->vfs->getChild('asset-base-url.php')->url();
$this->options['mode'] = StaticAssetUrlProvider::MODE_REMOTE;
$this->expectException(\RuntimeException::class);
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Invalid content in asset base url');
$this->newSubject();
}

/**
* @testWith ["assets/my-file.css"]
* ["/assets/my-file.css"]
*/
#[TestWith(['assets/my-file.css'])]
#[TestWith(['/assets/my-file.css'])]
public function test_it_remote_mode_get_url_returns_url_prefixed_with_base_url($rel_path)
{
vfsStream::create(
Expand Down
Loading