Skip to content

Commit 7976d56

Browse files
Leftover
1 parent 11a853e commit 7976d56

File tree

6 files changed

+168
-3
lines changed

6 files changed

+168
-3
lines changed

ChangeLog-11.5.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ All notable changes of the PHPUnit 11.5 release series are documented in this fi
99
* [#5948](https://github.com/sebastianbergmann/phpunit/pull/5948): Support for Property Hooks in Test Doubles
1010
* [#5954](https://github.com/sebastianbergmann/phpunit/issues/5954): Provide a way to stop execution at a particular deprecation
1111
* Method `assertContainsNotOnlyInstancesOf()` in the `PHPUnit\Framework\Assert` class as the inverse of the `assertContainsOnlyInstancesOf()` method
12-
* Methods `assertContainsOnlyArray()`, `assertContainsOnlyBool()`, `assertContainsOnlyCallable()`, `assertContainsOnlyFloat()`, `assertContainsOnlyInt()`, `assertContainsOnlyIterable()`, `assertContainsOnlyNumeric()`, `assertContainsOnlyObject()`, `assertContainsOnlyResource()`, `assertContainsOnlyClosedResource()`, `assertContainsOnlyScalar()`, and `assertContainsOnlyString()` in the `PHPUnit\Framework\Assert` class as specialized alternatives for the generic `assertContainsOnly()` method
13-
* Methods `assertContainsNotOnlyArray()`, `assertContainsNotOnlyBool()`, `assertContainsNotOnlyCallable()`, `assertContainsNotOnlyFloat()`, `assertContainsNotOnlyInt()`, `assertContainsNotOnlyIterable()`, `assertContainsNotOnlyNumeric()`, `assertContainsNotOnlyObject()`, `assertContainsNotOnlyResource()`, `assertContainsNotOnlyClosedResource()`, `assertContainsNotOnlyScalar()`, and `assertContainsNotOnlyString()` in the `PHPUnit\Framework\Assert` class as specialized alternatives for the generic `assertNotContainsOnly()` method
14-
* Methods `containsOnlyArray()`, `containsOnlyBool()`, `containsOnlyCallable()`, `containsOnlyFloat()`, `containsOnlyInt()`, `containsOnlyIterable()`, `containsOnlyNumeric()`, `containsOnlyObject()`, `containsOnlyResource()`, `containsOnlyClosedResource()`, `containsOnlyScalar()`, and `containsOnlyString()` in the `PHPUnit\Framework\Assert` class as specialized alternatives for the generic `containsOnly()` method
12+
* Methods `assertContainsOnlyArray()`, `assertContainsOnlyBool()`, `assertContainsOnlyCallable()`, `assertContainsOnlyFloat()`, `assertContainsOnlyInt()`, `assertContainsOnlyIterable()`, `assertContainsOnlyNull()`, `assertContainsOnlyNumeric()`, `assertContainsOnlyObject()`, `assertContainsOnlyResource()`, `assertContainsOnlyClosedResource()`, `assertContainsOnlyScalar()`, and `assertContainsOnlyString()` in the `PHPUnit\Framework\Assert` class as specialized alternatives for the generic `assertContainsOnly()` method
13+
* Methods `assertContainsNotOnlyArray()`, `assertContainsNotOnlyBool()`, `assertContainsNotOnlyCallable()`, `assertContainsNotOnlyFloat()`, `assertContainsNotOnlyInt()`, `assertContainsNotOnlyIterable()`, `assertContainsNotOnlyNull()`, `assertContainsNotOnlyNumeric()`, `assertContainsNotOnlyObject()`, `assertContainsNotOnlyResource()`, `assertContainsNotOnlyClosedResource()`, `assertContainsNotOnlyScalar()`, and `assertContainsNotOnlyString()` in the `PHPUnit\Framework\Assert` class as specialized alternatives for the generic `assertNotContainsOnly()` method
14+
* Methods `containsOnlyArray()`, `containsOnlyBool()`, `containsOnlyCallable()`, `containsOnlyFloat()`, `containsOnlyInt()`, `containsOnlyIterable()`, `containsOnlyNull()`, `containsOnlyNumeric()`, `containsOnlyObject()`, `containsOnlyResource()`, `containsOnlyClosedResource()`, `containsOnlyScalar()`, and `containsOnlyString()` in the `PHPUnit\Framework\Assert` class as specialized alternatives for the generic `containsOnly()` method
1515
* Methods `isArray()`, `isBool()`, `isCallable()`, `isFloat()`, `isInt()`, `isIterable()`, `isNumeric()`, `isObject()`, `isResource()`, `isClosedResource()`, `isScalar()`, `isString()` in the `PHPUnit\Framework\Assert` class as specialized alternatives for the generic `isType()` method
1616
* `TestRunner\ChildProcessStarted` and `TestRunner\ChildProcessFinished` events
1717

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
"tests/unit/Framework/Assert/assertContainsOnlyInstancesOfTest.php",
8888
"tests/unit/Framework/Assert/assertContainsOnlyIntTest.php",
8989
"tests/unit/Framework/Assert/assertContainsOnlyIterableTest.php",
90+
"tests/unit/Framework/Assert/assertContainsOnlyNullTest.php",
9091
"tests/unit/Framework/Assert/assertContainsOnlyNumericTest.php",
9192
"tests/unit/Framework/Assert/assertContainsOnlyObjectTest.php",
9293
"tests/unit/Framework/Assert/assertContainsOnlyResourceTest.php",

src/Framework/Assert.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,24 @@ final public static function assertContainsOnlyIterable(iterable $haystack, stri
399399
);
400400
}
401401

402+
/**
403+
* Asserts that a haystack contains only values of type null.
404+
*
405+
* @param iterable<mixed> $haystack
406+
*
407+
* @throws ExpectationFailedException
408+
*/
409+
final public static function assertContainsOnlyNull(iterable $haystack, string $message = ''): void
410+
{
411+
self::assertThat(
412+
$haystack,
413+
new TraversableContainsOnly(
414+
NativeType::Null->value,
415+
),
416+
$message,
417+
);
418+
}
419+
402420
/**
403421
* Asserts that a haystack contains only values of type numeric.
404422
*
@@ -677,6 +695,26 @@ final public static function assertContainsNotOnlyIterable(iterable $haystack, s
677695
);
678696
}
679697

698+
/**
699+
* Asserts that a haystack does not contain only values of type null.
700+
*
701+
* @param iterable<mixed> $haystack
702+
*
703+
* @throws ExpectationFailedException
704+
*/
705+
final public static function assertContainsNotOnlyNull(iterable $haystack, string $message = ''): void
706+
{
707+
self::assertThat(
708+
$haystack,
709+
new LogicalNot(
710+
new TraversableContainsOnly(
711+
NativeType::Null->value,
712+
),
713+
),
714+
$message,
715+
);
716+
}
717+
680718
/**
681719
* Asserts that a haystack does not contain only values of type numeric.
682720
*

src/Framework/Assert/Functions.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,24 @@ function assertContainsOnlyIterable(iterable $haystack, string $message = ''): v
407407
}
408408
}
409409

410+
if (!function_exists('PHPUnit\Framework\assertContainsOnlyNull')) {
411+
/**
412+
* Asserts that a haystack contains only values of type null.
413+
*
414+
* @param iterable<mixed> $haystack
415+
*
416+
* @throws ExpectationFailedException
417+
*
418+
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
419+
*
420+
* @see Assert::assertContainsOnlyNull
421+
*/
422+
function assertContainsOnlyNull(iterable $haystack, string $message = ''): void
423+
{
424+
Assert::assertContainsOnlyNull(...func_get_args());
425+
}
426+
}
427+
410428
if (!function_exists('PHPUnit\Framework\assertContainsOnlyNumeric')) {
411429
/**
412430
* Asserts that a haystack contains only values of type numeric.
@@ -665,6 +683,24 @@ function assertContainsNotOnlyIterable(iterable $haystack, string $message = '')
665683
}
666684
}
667685

686+
if (!function_exists('PHPUnit\Framework\assertContainsNotOnlyNull')) {
687+
/**
688+
* Asserts that a haystack does not contain only values of type null.
689+
*
690+
* @param iterable<mixed> $haystack
691+
*
692+
* @throws ExpectationFailedException
693+
*
694+
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
695+
*
696+
* @see Assert::assertContainsNotOnlyNull
697+
*/
698+
function assertContainsNotOnlyNull(iterable $haystack, string $message = ''): void
699+
{
700+
Assert::assertContainsNotOnlyNull(...func_get_args());
701+
}
702+
}
703+
668704
if (!function_exists('PHPUnit\Framework\assertContainsNotOnlyNumeric')) {
669705
/**
670706
* Asserts that a haystack does not contain only values of type numeric.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\Framework;
11+
12+
use PHPUnit\Framework\Attributes\CoversMethod;
13+
use PHPUnit\Framework\Attributes\DataProviderExternal;
14+
use PHPUnit\Framework\Attributes\Small;
15+
use PHPUnit\Framework\Attributes\TestDox;
16+
17+
#[CoversMethod(Assert::class, 'assertContainsNotOnlyNull')]
18+
#[TestDox('assertContainsNotOnlyNull()')]
19+
#[Small]
20+
final class assertContainsNotOnlyNullTest extends TestCase
21+
{
22+
#[DataProviderExternal(assertContainsOnlyNullTest::class, 'failureProvider')]
23+
public function testSucceedsWhenConstraintEvaluatesToTrue(iterable $haystack): void
24+
{
25+
$this->assertContainsNotOnlyNull($haystack);
26+
}
27+
28+
#[DataProviderExternal(assertContainsOnlyNullTest::class, 'successProvider')]
29+
public function testFailsWhenConstraintEvaluatesToFalse(iterable $haystack): void
30+
{
31+
$this->expectException(AssertionFailedError::class);
32+
33+
$this->assertContainsNotOnlyNull($haystack);
34+
}
35+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\Framework;
11+
12+
use PHPUnit\Framework\Attributes\CoversMethod;
13+
use PHPUnit\Framework\Attributes\DataProvider;
14+
use PHPUnit\Framework\Attributes\Small;
15+
use PHPUnit\Framework\Attributes\TestDox;
16+
17+
#[CoversMethod(Assert::class, 'assertContainsOnlyNull')]
18+
#[TestDox('assertContainsOnlyNull()')]
19+
#[Small]
20+
final class assertContainsOnlyNullTest extends TestCase
21+
{
22+
/**
23+
* @return non-empty-list<array{0: iterable}>
24+
*/
25+
public static function successProvider(): array
26+
{
27+
return [
28+
[[null]],
29+
];
30+
}
31+
32+
/**
33+
* @return non-empty-list<array{0: iterable}>
34+
*/
35+
public static function failureProvider(): array
36+
{
37+
return [
38+
[[true]],
39+
];
40+
}
41+
42+
#[DataProvider('successProvider')]
43+
public function testSucceedsWhenConstraintEvaluatesToTrue(iterable $haystack): void
44+
{
45+
$this->assertContainsOnlyNull($haystack);
46+
}
47+
48+
#[DataProvider('failureProvider')]
49+
public function testFailsWhenConstraintEvaluatesToFalse(iterable $haystack): void
50+
{
51+
$this->expectException(AssertionFailedError::class);
52+
53+
$this->assertContainsOnlyNull($haystack);
54+
}
55+
}

0 commit comments

Comments
 (0)