Skip to content

Commit

Permalink
chore: update tests for phpunit 10 and 11 (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
rancoud authored Dec 14, 2024
1 parent 1fa3778 commit bebeb80
Show file tree
Hide file tree
Showing 68 changed files with 10,488 additions and 10,332 deletions.
6 changes: 3 additions & 3 deletions tests/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ protected function getHostname(): string
*
* @return string
*/
protected function getEmailHTMLConfirmAccount(string $username): string
protected static function getEmailHTMLConfirmAccount(string $username): string
{
\ob_start();
$ds = \DIRECTORY_SEPARATOR;
Expand Down Expand Up @@ -407,7 +407,7 @@ protected function getEmailHTMLConfirmAccount(string $username): string
*
* @return string
*/
protected function getEmailTextConfirmAccount(string $username): string
protected static function getEmailTextConfirmAccount(string $username): string
{
$text = 'Welcome to this_site_name' . "\n\n";
$text .= 'We are excited to have you on board!' . "\n";
Expand Down Expand Up @@ -437,7 +437,7 @@ protected static function cleanFiles(): void
*
* @return string
*/
public function getSince(string $publishedAt): string
public static function getSince(string $publishedAt): string
{
$publishedAtObject = new DateTime($publishedAt);
$nowObject = new DateTime();
Expand Down
42 changes: 22 additions & 20 deletions tests/www/API/APIRenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace tests\www\API;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Rancoud\Application\Application;
use Rancoud\Application\ApplicationException;
Expand All @@ -32,7 +33,7 @@ public static function setUpBeforeClass(): void
static::$db->insert("INSERT INTO users_api (id_user, api_key) VALUES (1, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')");
}

public function dataCases(): array
public static function dataCases(): array
{
return [
'render - OK' => [
Expand All @@ -42,8 +43,8 @@ public function dataCases(): array
'params' => [
'blueprint' => 'begin object 1',
],
'response_code' => 200,
'response_content' => <<<HTML
'responseCode' => 200,
'responseContent' => <<<HTML
<!DOCTYPE html>
<html lang="en">
<head>
Expand Down Expand Up @@ -91,16 +92,16 @@ public function dataCases(): array
'params' => [
'blueprint' => 'begin object 1',
],
'response_code' => 401,
'response_content' => '{"error":"api_key_incorrect"}',
'responseCode' => 401,
'responseContent' => '{"error":"api_key_incorrect"}',
],
'headers empty' => [
'headers' => [],
'params' => [
'blueprint' => 'begin object 1',
],
'response_code' => 401,
'response_content' => '{"error":"api_key_empty"}',
'responseCode' => 401,
'responseContent' => '{"error":"api_key_empty"}',
],
'api key empty' => [
'headers' => [
Expand All @@ -109,8 +110,8 @@ public function dataCases(): array
'params' => [
'blueprint' => 'begin object 1',
],
'response_code' => 401,
'response_content' => '{"error":"api_key_empty"}',
'responseCode' => 401,
'responseContent' => '{"error":"api_key_empty"}',
],
'api key invalid encoding' => [
'headers' => [
Expand All @@ -119,16 +120,16 @@ public function dataCases(): array
'params' => [
'blueprint' => 'begin object 1',
],
'response_code' => 401,
'response_content' => '{"error":"api_key_incorrect"}',
'responseCode' => 401,
'responseContent' => '{"error":"api_key_incorrect"}',
],
'missing fields - no fields' => [
'headers' => [
'X-Token' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
],
'params' => [],
'response_code' => 400,
'response_content' => '{"error":"blueprint_empty"}',
'params' => [],
'responseCode' => 400,
'responseContent' => '{"error":"blueprint_empty"}',
],
'empty fields - blueprint empty' => [
'headers' => [
Expand All @@ -137,8 +138,8 @@ public function dataCases(): array
'params' => [
'blueprint' => ' ',
],
'response_code' => 400,
'response_content' => '{"error":"blueprint_empty"}',
'responseCode' => 400,
'responseContent' => '{"error":"blueprint_empty"}',
],
'invalid fields - blueprint' => [
'headers' => [
Expand All @@ -147,8 +148,8 @@ public function dataCases(): array
'params' => [
'blueprint' => 'aze',
],
'response_code' => 400,
'response_content' => '{"error":"blueprint_empty"}',
'responseCode' => 400,
'responseContent' => '{"error":"blueprint_empty"}',
],
'invalid encoding fields - blueprint' => [
'headers' => [
Expand All @@ -157,8 +158,8 @@ public function dataCases(): array
'params' => [
'blueprint' => \chr(99999999)
],
'response_code' => 400,
'response_content' => '{"error":"blueprint_empty"}',
'responseCode' => 400,
'responseContent' => '{"error":"blueprint_empty"}',
]
];
}
Expand All @@ -176,6 +177,7 @@ public function dataCases(): array
* @throws RouterException
* @throws \Rancoud\Database\DatabaseException
*/
#[DataProvider('dataCases')]
public function testRenderPOST(array $headers, array $params, int $responseCode, string $responseContent): void
{
$ds = \DIRECTORY_SEPARATOR;
Expand Down
84 changes: 43 additions & 41 deletions tests/www/API/APIUploadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace tests\www\API;

use app\helpers\Helper;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Rancoud\Application\Application;
use Rancoud\Application\ApplicationException;
Expand All @@ -34,7 +35,7 @@ public static function setUpBeforeClass(): void
static::$db->insert('INSERT INTO users_infos (id_user) VALUES (1)');
}

public function dataCases(): array
public static function dataCases(): array
{
return [
'upload - OK' => [
Expand All @@ -45,8 +46,8 @@ public function dataCases(): array
'title' => 'my title',
'blueprint' => 'begin object 1',
],
'response_code' => 200,
'response_content' => '{"key":"xxxxxxxx"}',
'responseCode' => 200,
'responseContent' => '{"key":"xxxxxxxx"}',
],
'upload with extra infos - OK' => [
'headers' => [
Expand All @@ -59,8 +60,8 @@ public function dataCases(): array
'expiration' => '3600',
'version' => '4.12',
],
'response_code' => 200,
'response_content' => '{"key":"xxxxxxxx"}',
'responseCode' => 200,
'responseContent' => '{"key":"xxxxxxxx"}',
],
'api key incorrect' => [
'headers' => [
Expand All @@ -69,16 +70,16 @@ public function dataCases(): array
'params' => [
'blueprint' => 'begin object 1',
],
'response_code' => 401,
'response_content' => '{"error":"api_key_incorrect"}',
'responseCode' => 401,
'responseContent' => '{"error":"api_key_incorrect"}',
],
'headers empty' => [
'headers' => [],
'params' => [
'blueprint' => 'begin object 1',
],
'response_code' => 401,
'response_content' => '{"error":"api_key_empty"}',
'responseCode' => 401,
'responseContent' => '{"error":"api_key_empty"}',
],
'api key empty' => [
'headers' => [
Expand All @@ -87,8 +88,8 @@ public function dataCases(): array
'params' => [
'blueprint' => 'begin object 1',
],
'response_code' => 401,
'response_content' => '{"error":"api_key_empty"}',
'responseCode' => 401,
'responseContent' => '{"error":"api_key_empty"}',
],
'api key invalid encoding' => [
'headers' => [
Expand All @@ -97,16 +98,16 @@ public function dataCases(): array
'params' => [
'blueprint' => 'begin object 1',
],
'response_code' => 401,
'response_content' => '{"error":"api_key_incorrect"}',
'responseCode' => 401,
'responseContent' => '{"error":"api_key_incorrect"}',
],
'missing fields - no fields' => [
'headers' => [
'X-Token' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
],
'params' => [],
'response_code' => 400,
'response_content' => '{"error":"required_title"}',
'responseCode' => 400,
'responseContent' => '{"error":"required_title"}',
],
'missing fields - no title' => [
'headers' => [
Expand All @@ -115,8 +116,8 @@ public function dataCases(): array
'params' => [
'blueprint' => 'begin object 1',
],
'response_code' => 400,
'response_content' => '{"error":"required_title"}',
'responseCode' => 400,
'responseContent' => '{"error":"required_title"}',
],
'missing fields - no blueprint' => [
'headers' => [
Expand All @@ -125,8 +126,8 @@ public function dataCases(): array
'params' => [
'title' => 'my title',
],
'response_code' => 400,
'response_content' => '{"error":"invalid_blueprint"}',
'responseCode' => 400,
'responseContent' => '{"error":"invalid_blueprint"}',
],
'empty fields - title empty' => [
'headers' => [
Expand All @@ -136,8 +137,8 @@ public function dataCases(): array
'title' => ' ',
'blueprint' => 'begin object 1',
],
'response_code' => 400,
'response_content' => '{"error":"required_title"}',
'responseCode' => 400,
'responseContent' => '{"error":"required_title"}',
],
'empty fields - blueprint empty' => [
'headers' => [
Expand All @@ -147,8 +148,8 @@ public function dataCases(): array
'title' => 'my title',
'blueprint' => ' ',
],
'response_code' => 400,
'response_content' => '{"error":"invalid_blueprint"}',
'responseCode' => 400,
'responseContent' => '{"error":"invalid_blueprint"}',
],
'invalid fields - blueprint' => [
'headers' => [
Expand All @@ -158,8 +159,8 @@ public function dataCases(): array
'title' => 'my title',
'blueprint' => 'aze',
],
'response_code' => 400,
'response_content' => '{"error":"invalid_blueprint"}',
'responseCode' => 400,
'responseContent' => '{"error":"invalid_blueprint"}',
],
'invalid fields - exposure' => [
'headers' => [
Expand All @@ -170,8 +171,8 @@ public function dataCases(): array
'blueprint' => 'begin object 1',
'exposure' => 'xxx',
],
'response_code' => 400,
'response_content' => '{"error":"invalid_exposure"}',
'responseCode' => 400,
'responseContent' => '{"error":"invalid_exposure"}',
],
'invalid fields - expiration' => [
'headers' => [
Expand All @@ -182,8 +183,8 @@ public function dataCases(): array
'blueprint' => 'begin object 1',
'expiration' => 'xxx'
],
'response_code' => 400,
'response_content' => '{"error":"invalid_expiration"}',
'responseCode' => 400,
'responseContent' => '{"error":"invalid_expiration"}',
],
'invalid fields - version' => [
'headers' => [
Expand All @@ -195,8 +196,8 @@ public function dataCases(): array
'version' => 'xxx',
'expiration' => '604800'
],
'response_code' => 400,
'response_content' => '{"error":"invalid_version"}',
'responseCode' => 400,
'responseContent' => '{"error":"invalid_version"}',
],
'do throw exception' => [
'headers' => [
Expand All @@ -207,8 +208,8 @@ public function dataCases(): array
'blueprint' => 'begin object 1',
'do throw exception' => 'do throw exception'
],
'response_code' => 400,
'response_content' => '{"error":"error_insert_blueprint_#200"}',
'responseCode' => 400,
'responseContent' => '{"error":"error_insert_blueprint_#200"}',
],
'invalid encoding fields - title' => [
'headers' => [
Expand All @@ -220,8 +221,8 @@ public function dataCases(): array
'version' => 'public',
'expiration' => '604800'
],
'response_code' => 400,
'response_content' => '{"error":"invalid"}',
'responseCode' => 400,
'responseContent' => '{"error":"invalid"}',
],
'invalid encoding fields - blueprint' => [
'headers' => [
Expand All @@ -233,8 +234,8 @@ public function dataCases(): array
'version' => 'public',
'expiration' => '604800'
],
'response_code' => 400,
'response_content' => '{"error":"invalid"}',
'responseCode' => 400,
'responseContent' => '{"error":"invalid"}',
],
'invalid encoding fields - version' => [
'headers' => [
Expand All @@ -246,8 +247,8 @@ public function dataCases(): array
'version' => \chr(99999999),
'expiration' => '604800'
],
'response_code' => 400,
'response_content' => '{"error":"invalid"}',
'responseCode' => 400,
'responseContent' => '{"error":"invalid"}',
],
'invalid encoding fields - expiration' => [
'headers' => [
Expand All @@ -259,8 +260,8 @@ public function dataCases(): array
'version' => 'public',
'expiration' => \chr(99999999)
],
'response_code' => 400,
'response_content' => '{"error":"invalid"}',
'responseCode' => 400,
'responseContent' => '{"error":"invalid"}',
]
];
}
Expand All @@ -279,6 +280,7 @@ public function dataCases(): array
* @throws \Rancoud\Database\DatabaseException
* @throws \Exception
*/
#[DataProvider('dataCases')]
public function testUploadPOST(array $headers, array $params, int $responseCode, string $responseContent): void
{
$ds = \DIRECTORY_SEPARATOR;
Expand Down
Loading

0 comments on commit bebeb80

Please sign in to comment.