-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2563efa
commit 3b2b54d
Showing
2 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace System\Integrate\Testing; | ||
|
||
use PHPUnit\Framework\Assert; | ||
use System\Http\Response; | ||
|
||
/** | ||
* @implements \ArrayAccess<string, mixed> | ||
*/ | ||
class ApiResponseTest extends ResponseTest implements \ArrayAccess | ||
{ | ||
/** | ||
* @var array<string, mixed> | ||
*/ | ||
private array $respone_data; | ||
|
||
/** | ||
* @param array<string, mixed> $respone_data | ||
*/ | ||
public function __construct(Response $response, $respone_data = []) | ||
{ | ||
$this->response = $response; | ||
$this->respone_data = $respone_data; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getData() | ||
{ | ||
return $this->respone_data['data']; | ||
} | ||
|
||
public function offsetExists($offset): bool | ||
{ | ||
return array_key_exists($offset, $this->respone_data); | ||
} | ||
|
||
#[\ReturnTypeWillChange] | ||
public function offsetGet($offset) | ||
{ | ||
return $this->respone_data[$offset]; | ||
} | ||
|
||
public function offsetSet($offset, $value): void | ||
{ | ||
$this->respone_data[$offset] = $value; | ||
} | ||
|
||
public function offsetUnset($offset): void | ||
{ | ||
unset($this->respone_data[$offset]); | ||
} | ||
|
||
public function assertDataEmpty(): void | ||
{ | ||
Assert::assertEmpty($this->getData()); | ||
} | ||
|
||
public function assertDataNotEmpty(): void | ||
{ | ||
Assert::assertNotEmpty($this->getData()); | ||
} | ||
|
||
/** | ||
* @param mixed $value | ||
*/ | ||
public function assertEqual(string $data_key, $value): void | ||
{ | ||
$data_get = data_get($this->respone_data, $data_key); | ||
Assert::assertEquals($data_get, $value); | ||
} | ||
|
||
public function assertTrue(string $data_key, string $message = ''): void | ||
{ | ||
$data_get = data_get($this->respone_data, $data_key); | ||
Assert::assertTrue($data_get, $message); | ||
} | ||
|
||
public function assertFalse(string $data_key, string $message = ''): void | ||
{ | ||
$data_get = data_get($this->respone_data, $data_key); | ||
Assert::assertFalse($data_get, $message); | ||
} | ||
|
||
public function assertNull(string $data_key, string $message = ''): void | ||
{ | ||
$data_get = data_get($this->respone_data, $data_key); | ||
Assert::assertNull($data_get, $message); | ||
} | ||
|
||
public function assertNotNull(string $data_key, string $message = ''): void | ||
{ | ||
$data_get = data_get($this->respone_data, $data_key); | ||
Assert::assertNotNull($data_get, $message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace System\Integrate\Testing; | ||
|
||
use PHPUnit\Framework\Assert; | ||
use System\Http\Response; | ||
|
||
class ResponseTest | ||
{ | ||
protected Response $response; | ||
|
||
public function __construct(Response $response) | ||
{ | ||
$this->response = $response; | ||
} | ||
|
||
public function getContent(): string | ||
{ | ||
return $this->response->getContent(); | ||
} | ||
|
||
public function assertSee(string $text, string $message = ''): void | ||
{ | ||
Assert::assertStringContainsString($text, $this->response->getContent(), $message); | ||
} | ||
|
||
public function assertStatusCode(int $code, string $message = ''): void | ||
{ | ||
Assert::assertSame($code, $this->response->getStatusCode(), $message); | ||
} | ||
|
||
public function assertOk(): void | ||
{ | ||
$this->assertStatusCode(Response::HTTP_OK, 'Respone code must return ok'); | ||
} | ||
|
||
public function assertNoContent(): void | ||
{ | ||
$this->assertStatusCode(Response::HTTP_NO_CONTENT, 'Respone code must return no content'); | ||
} | ||
|
||
public function assertNotFound(): void | ||
{ | ||
$this->assertStatusCode(Response::HTTP_NOT_FOUND, 'Respone code must return Not Found'); | ||
} | ||
|
||
public function assertNotAllowed(): void | ||
{ | ||
$this->assertStatusCode(Response::HTTP_METHOD_NOT_ALLOWED, 'Respone code must return Not Allowed'); | ||
} | ||
} |