fix negated predicate decorated callable

This commit is contained in:
Kacper Donat 2026-10-27 22:59:06 +01:00
parent 61f934ffd7
commit 978a49091f
3 changed files with 41 additions and 7 deletions

View File

@ -108,12 +108,6 @@ parameters:
count: 2 count: 2
path: src/Predicate/ConstantPredicate.php path: src/Predicate/ConstantPredicate.php
-
message: '#^Expression "\$this\-\>negated" on a separate line does not do anything\.$#'
identifier: expr.resultUnused
count: 1
path: src/Predicate/NegatedPredicate.php
- -
message: '#^Method Kadet\\Functional\\Predicate\\NegatedPredicate\:\:__invoke\(\) has parameter \$args with no type specified\.$#' message: '#^Method Kadet\\Functional\\Predicate\\NegatedPredicate\:\:__invoke\(\) has parameter \$args with no type specified\.$#'
identifier: missingType.parameter identifier: missingType.parameter

View File

@ -39,6 +39,6 @@ class NegatedPredicate extends AbstractPredicate implements Decorator
public function getDecorated() public function getDecorated()
{ {
$this->negated; return $this->negated;
} }
} }

View File

@ -0,0 +1,40 @@
<?php
/**
* Copyright 2026 Kacper Donat
*
* @author Kacper "Kadet" Donat <kacper@kadet.net>
*
* Full license available in separate LICENSE file
*/
use Kadet\Functional as f;
use Kadet\Functional\Collections as c;
use Kadet\Functional\Predicates as p;
/**
* The library's own callables (predicates, pipes, decorators) used as collection callbacks.
*/
class LibraryCallablesTest extends \PHPUnit\Framework\TestCase
{
// negated predicates
public function testFilterWithNegatedInternalFunction()
{
$this->assertSame([1 => 'x'], c\filter(f\not(is_numeric(...)))(['1', 'x']));
}
public function testFilterWithNegatedClosure()
{
$this->assertSame([1], c\filter(f\not(fn ($x) => $x > 1))([1, 2]));
}
public function testFilterWithNegatedPredicateMethod()
{
$this->assertSame([1], c\filter(p\gt(1)->not())([1, 2]));
}
public function testRejectWithNegatedPredicate()
{
$this->assertSame([1 => 2], c\reject(p\gt(1)->not())([1, 2]));
}
}