upgrade to php 8.2 and phpunit 11

This commit is contained in:
Kacper Donat 2026-10-27 22:04:21 +01:00
parent 12918eb3cb
commit 8e824ef93c
13 changed files with 961 additions and 1054 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@
/node_modules/ /node_modules/
test.*.php test.*.php
.phpunit.cache

View File

@ -1,8 +0,0 @@
#!/usr/bin/env php
<?php
require_once __DIR__.'/../vendor/autoload.php';
use Kadet\Functional as f;
use Kadet\Functional\Predicates as p;
eval(\Psy\sh());

View File

@ -10,11 +10,12 @@
} }
], ],
"require": { "require": {
"php": ">=7.1" "php": ">=8.2"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^7.0", "phpunit/phpunit": "^11.5",
"psy/psysh": "@stable" "php-ds/php-ds": "^2.0",
"phpstan/phpstan": "^2.1"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
@ -24,5 +25,8 @@
"./src/functions.php", "./src/functions.php",
"./src/Predicates/index.php" "./src/Predicates/index.php"
] ]
},
"suggest": {
"php-ds/php-ds": "^2.0 (or ext-ds) for Seq/Map/Set results"
} }
} }

1870
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,13 @@
<phpunit bootstrap="tests/bootstrap.php"> <?xml version="1.0"?>
<phpunit bootstrap="tests/bootstrap.php" cacheDirectory=".phpunit.cache">
<testsuites> <testsuites>
<testsuite name="all"> <testsuite name="all">
<directory>tests</directory> <directory>tests</directory>
</testsuite> </testsuite>
</testsuites><filter> </testsuites>
<whitelist processUncoveredFilesFromWhitelist="true"> <source>
<directory suffix=".php">src</directory> <include>
</whitelist> <directory suffix=".php">src</directory>
</filter> </include>
</source>
</phpunit> </phpunit>

View File

@ -21,9 +21,7 @@ class ConstantPredicateTest extends PHPUnit\Framework\TestCase
}; };
} }
/** #[\PHPUnit\Framework\Attributes\DataProvider('randomDataProvider')]
* @dataProvider randomDataProvider
*/
public function testNeverAndPredicate(...$args) public function testNeverAndPredicate(...$args)
{ {
$predicate = ConstantPredicate::never()->and($this->getTestPredicate()); $predicate = ConstantPredicate::never()->and($this->getTestPredicate());
@ -31,9 +29,7 @@ class ConstantPredicateTest extends PHPUnit\Framework\TestCase
$this->assertFalse($predicate(...$args)); $this->assertFalse($predicate(...$args));
} }
/** #[\PHPUnit\Framework\Attributes\DataProvider('randomDataProvider')]
* @dataProvider randomDataProvider
*/
public function testNeverOrPredicate(...$args) public function testNeverOrPredicate(...$args)
{ {
$predicate = predicate($this->getTestPredicate()); $predicate = predicate($this->getTestPredicate());
@ -42,9 +38,7 @@ class ConstantPredicateTest extends PHPUnit\Framework\TestCase
$this->assertSame($predicate(...$args), $tested(...$args)); $this->assertSame($predicate(...$args), $tested(...$args));
} }
/** #[\PHPUnit\Framework\Attributes\DataProvider('randomDataProvider')]
* @dataProvider randomDataProvider
*/
public function testAlwaysOrPredicate(...$args) public function testAlwaysOrPredicate(...$args)
{ {
$predicate = ConstantPredicate::always()->or($this->getTestPredicate()); $predicate = ConstantPredicate::always()->or($this->getTestPredicate());
@ -52,9 +46,7 @@ class ConstantPredicateTest extends PHPUnit\Framework\TestCase
$this->assertTrue($predicate(...$args)); $this->assertTrue($predicate(...$args));
} }
/** #[\PHPUnit\Framework\Attributes\DataProvider('randomDataProvider')]
* @dataProvider randomDataProvider
*/
public function testAlwaysAndPredicate(...$args) public function testAlwaysAndPredicate(...$args)
{ {
$predicate = predicate($this->getTestPredicate()); $predicate = predicate($this->getTestPredicate());
@ -63,9 +55,7 @@ class ConstantPredicateTest extends PHPUnit\Framework\TestCase
$this->assertSame($predicate(...$args), $tested(...$args)); $this->assertSame($predicate(...$args), $tested(...$args));
} }
/** #[\PHPUnit\Framework\Attributes\DataProvider('randomDataProvider')]
* @dataProvider randomDataProvider
*/
public function testNever(...$args) public function testNever(...$args)
{ {
$tested = ConstantPredicate::never(); $tested = ConstantPredicate::never();
@ -73,9 +63,7 @@ class ConstantPredicateTest extends PHPUnit\Framework\TestCase
$this->assertFalse($tested(...$args)); $this->assertFalse($tested(...$args));
} }
/** #[\PHPUnit\Framework\Attributes\DataProvider('randomDataProvider')]
* @dataProvider randomDataProvider
*/
public function testNotAlways(...$args) public function testNotAlways(...$args)
{ {
$tested = ConstantPredicate::always()->not(); $tested = ConstantPredicate::always()->not();
@ -83,9 +71,7 @@ class ConstantPredicateTest extends PHPUnit\Framework\TestCase
$this->assertFalse($tested(...$args)); $this->assertFalse($tested(...$args));
} }
/** #[\PHPUnit\Framework\Attributes\DataProvider('randomDataProvider')]
* @dataProvider randomDataProvider
*/
public function testNotNever(...$args) public function testNotNever(...$args)
{ {
$tested = ConstantPredicate::never()->not(); $tested = ConstantPredicate::never()->not();
@ -93,9 +79,7 @@ class ConstantPredicateTest extends PHPUnit\Framework\TestCase
$this->assertTrue($tested(...$args)); $this->assertTrue($tested(...$args));
} }
/** #[\PHPUnit\Framework\Attributes\DataProvider('randomDataProvider')]
* @dataProvider randomDataProvider
*/
public function testAlways(...$args) public function testAlways(...$args)
{ {
$tested = ConstantPredicate::always(); $tested = ConstantPredicate::always();

View File

@ -19,7 +19,7 @@ class CurriedFunctionTest extends \PHPUnit\Framework\TestCase
private $variadic; private $variadic;
private $optional; private $optional;
protected function setUp() protected function setUp(): void
{ {
$this->function = function ($a, $b, $c, $d) { $this->function = function ($a, $b, $c, $d) {
return $a . $b . $c . $d; return $a . $b . $c . $d;

View File

@ -14,12 +14,9 @@ class FunctionPipelineTest extends \PHPUnit\Framework\TestCase
/** @var \PHPUnit\Framework\MockObject\MockObject */ /** @var \PHPUnit\Framework\MockObject\MockObject */
private $mock; private $mock;
protected function setUp()/* The :void return type declaration that should be here would cause a BC issue */ protected function setUp(): void
{ {
$this->mock = $this $this->mock = $this->createMock(PipelineSteps::class);
->getMockBuilder('stdClass')
->setMethods(['a', 'b', 'c'])
->getMock();
} }
public function testPipelineCalling() public function testPipelineCalling()
@ -93,3 +90,10 @@ class FunctionPipelineTest extends \PHPUnit\Framework\TestCase
$this->assertSame('d', $second('a')); $this->assertSame('d', $second('a'));
} }
} }
class PipelineSteps
{
public function a() {}
public function b() {}
public function c() {}
}

View File

@ -14,12 +14,9 @@ class MemoizedFunctionTest extends \PHPUnit\Framework\TestCase
/** @var \PHPUnit\Framework\MockObject\MockObject */ /** @var \PHPUnit\Framework\MockObject\MockObject */
private $mock; private $mock;
protected function setUp()/* The :void return type declaration that should be here would cause a BC issue */ protected function setUp(): void
{ {
$this->mock = $this $this->mock = $this->createMock(MemoizedTarget::class);
->getMockBuilder('stdClass')
->setMethods(['memoized'])
->getMock();
} }
public function testCalledOnlyOnce() public function testCalledOnlyOnce()
@ -37,14 +34,23 @@ class MemoizedFunctionTest extends \PHPUnit\Framework\TestCase
{ {
$memoized = f\memoize([$this->mock, 'memoized']); $memoized = f\memoize([$this->mock, 'memoized']);
$this->mock->expects($this->exactly(2))->method('memoized')->withConsecutive( $calls = [];
[ 'a' ], $this->mock->expects($this->exactly(2))->method('memoized')->willReturnCallback(
[ [] ] function (...$args) use (&$calls) {
$calls[] = $args;
}
); );
for ($i = 0; $i < 10; $i++) { for ($i = 0; $i < 10; $i++) {
$memoized('a'); $memoized('a');
$memoized([]); $memoized([]);
} }
$this->assertSame([['a'], [[]]], $calls);
} }
} }
class MemoizedTarget
{
public function memoized() {}
}

View File

@ -39,9 +39,7 @@ class ObjectTransformsTest extends \PHPUnit\Framework\TestCase
{ {
use RandomDataTrait; use RandomDataTrait;
/** #[\PHPUnit\Framework\Attributes\DataProvider('randomDataProvider')]
* @dataProvider randomDataProvider
*/
public function testFieldTransform($data = null) public function testFieldTransform($data = null)
{ {
$object = new PropertiesObject($data, null, []); $object = new PropertiesObject($data, null, []);
@ -50,9 +48,7 @@ class ObjectTransformsTest extends \PHPUnit\Framework\TestCase
$this->assertSame($transform($object), $data); $this->assertSame($transform($object), $data);
} }
/** #[\PHPUnit\Framework\Attributes\DataProvider('randomDataProvider')]
* @dataProvider randomDataProvider
*/
public function testFieldTransformMagic($data = null) public function testFieldTransformMagic($data = null)
{ {
$object = new PropertiesObject(false, false, ['magic' => $data]); $object = new PropertiesObject(false, false, ['magic' => $data]);
@ -61,9 +57,7 @@ class ObjectTransformsTest extends \PHPUnit\Framework\TestCase
$this->assertSame($transform($object), $data); $this->assertSame($transform($object), $data);
} }
/** #[\PHPUnit\Framework\Attributes\DataProvider('randomDataProvider')]
* @dataProvider randomDataProvider
*/
public function testPropertyTransformGetter($data = null) public function testPropertyTransformGetter($data = null)
{ {
$object = new PropertiesObject(false, $data, []); $object = new PropertiesObject(false, $data, []);
@ -72,9 +66,7 @@ class ObjectTransformsTest extends \PHPUnit\Framework\TestCase
$this->assertSame($transform($object), $data); $this->assertSame($transform($object), $data);
} }
/** #[\PHPUnit\Framework\Attributes\DataProvider('randomDataProvider')]
* @dataProvider randomDataProvider
*/
public function testGetterTransform($data = null) public function testGetterTransform($data = null)
{ {
$object = new PropertiesObject(false, $data, []); $object = new PropertiesObject(false, $data, []);
@ -83,9 +75,7 @@ class ObjectTransformsTest extends \PHPUnit\Framework\TestCase
$this->assertSame($transform($object), $data); $this->assertSame($transform($object), $data);
} }
/** #[\PHPUnit\Framework\Attributes\DataProvider('randomDataProvider')]
* @dataProvider randomDataProvider
*/
public function testPropertyTransformField($data = null) public function testPropertyTransformField($data = null)
{ {
$object = new PropertiesObject($data, false, []); $object = new PropertiesObject($data, false, []);
@ -94,9 +84,7 @@ class ObjectTransformsTest extends \PHPUnit\Framework\TestCase
$this->assertSame($transform($object), $data); $this->assertSame($transform($object), $data);
} }
/** #[\PHPUnit\Framework\Attributes\DataProvider('randomDataProvider')]
* @dataProvider randomDataProvider
*/
public function testPropertyTransformMagic($data = null) public function testPropertyTransformMagic($data = null)
{ {
$object = new PropertiesObject(false, false, ['magic' => $data]); $object = new PropertiesObject(false, false, ['magic' => $data]);
@ -105,9 +93,7 @@ class ObjectTransformsTest extends \PHPUnit\Framework\TestCase
$this->assertSame($transform($object), $data); $this->assertSame($transform($object), $data);
} }
/** #[\PHPUnit\Framework\Attributes\DataProvider('randomDataProvider')]
* @dataProvider randomDataProvider
*/
public function testMethodTransform($data = null) public function testMethodTransform($data = null)
{ {
$object = new PropertiesObject(false, false); $object = new PropertiesObject(false, false);

View File

@ -9,7 +9,7 @@
trait RandomDataTrait trait RandomDataTrait
{ {
public function randomDataProvider() public static function randomDataProvider()
{ {
return [ return [
['x'], ['x'],

View File

@ -53,11 +53,9 @@ class ReferencingTest extends \PHPUnit\Framework\TestCase
$this->assertSame('foo', $reference()); $this->assertSame('foo', $reference());
} }
/**
* @expectedException \Kadet\Functional\Exception\NoAccessException
*/
public function testReferencingPrivateFunctionsFromOutsideOfObject() public function testReferencingPrivateFunctionsFromOutsideOfObject()
{ {
$this->expectException(\Kadet\Functional\Exception\NoAccessException::class);
$object = new TestObject(); $object = new TestObject();
ref([$object, 'priv']); ref([$object, 'priv']);

View File

@ -20,7 +20,7 @@ class ReflectionPartialAppliedFunctionTest extends \PHPUnit\Framework\TestCase
*/ */
private $function; private $function;
protected function setUp() protected function setUp(): void
{ {
$this->function = f\partial(function (array $a, array $b, array $c, array $d = ['d']) { $this->function = f\partial(function (array $a, array $b, array $c, array $d = ['d']) {
return array_merge($a, $b, $c, $d); return array_merge($a, $b, $c, $d);