Skip to content

Commit cf53d30

Browse files
huangdijialimingxinleo
authored andcommitted
⚙️chore(testing) move container related methods to InteractsWithContainer trait
New TestCase 🛠️refactor(testing) remove duplicate ApplicationContext::setContainer call ⚙️chore(testing) add array access to TestResponse 🛠️refactor(testing) simplify TestResponse body implementation 🚀feat(response) add status and content methods to TestResponse class Adds Utils Remove utils Update TestResponse.php ⚙️chore(testing) refreshContainer with ApplicationInterface call 🛠️refactor(testing): fix namespace in TestCase.php 🛠️refactor(testing) update namespace for ApplicationInterface in refreshContainer method ⚙️chore(testing) ignore phpstan warning in InteractsWithContainer trait instance function 🛠️refactor(testing): make container property protected in TestCase class 🛠️refactor(response) refactor TestResponse class methods - Refactored the content method to use the getContent method for consistency. - Created a collect method to get the JSON decoded body of the response as a collection for convenience. - Removed the status method since it's redundant with the getStatusCode method. - Updated the assertContent method to use the getContent method instead of the content method. 🛠️refactor(testing) make assert methods chainable Adds Utils WIP 🚀feat(dependencies) add symfony/http-foundation\n- Added version constraints for symfony/http-foundation for compatibility with versions 5.4 and 6.0. 🛠️refactor(tests) update TestCase.php null initialization of container ⚙️chore(config) update phpstan.neon configuration file
1 parent d281f75 commit cf53d30

19 files changed

+2824
-1
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"hyperf/http-message": "~3.0.0",
3030
"hyperf/http-server": "~3.0.0",
3131
"hyperf/support": "~3.0.0",
32-
"hyperf/utils": "~3.0.0"
32+
"hyperf/utils": "~3.0.0",
33+
"symfony/http-foundation": "^5.4|^6.0"
3334
},
3435
"extra": {
3536
"branch-alias": {

src/Assert.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of Hyperf.
6+
*
7+
* @link https://www.hyperf.io
8+
* @document https://hyperf.wiki
9+
* @contact [email protected]
10+
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11+
*/
12+
namespace Hyperf\Testing;
13+
14+
use ArrayAccess;
15+
use Hyperf\Testing\Constraint\ArraySubset;
16+
use Hyperf\Testing\Exception\InvalidArgumentException;
17+
use PHPUnit\Framework\Assert as PHPUnit;
18+
19+
/**
20+
* @internal this class is not meant to be used or overwritten outside the framework itself
21+
*/
22+
abstract class Assert extends PHPUnit
23+
{
24+
/**
25+
* Asserts that an array has a specified subset.
26+
*
27+
* @param array|ArrayAccess $subset
28+
* @param array|ArrayAccess $array
29+
*/
30+
public static function assertArraySubset($subset, $array, bool $checkForIdentity = false, string $msg = ''): void
31+
{
32+
if (! (is_array($subset) || $subset instanceof ArrayAccess)) {
33+
throw InvalidArgumentException::create(1, 'array or ArrayAccess');
34+
}
35+
36+
if (! (is_array($array) || $array instanceof ArrayAccess)) {
37+
throw InvalidArgumentException::create(2, 'array or ArrayAccess');
38+
}
39+
40+
$constraint = new ArraySubset($subset, $checkForIdentity);
41+
42+
PHPUnit::assertThat($array, $constraint, $msg);
43+
}
44+
}

0 commit comments

Comments
 (0)