Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create basic tests #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
build
vendor
tests/TestSupport/temp
tests/temp
composer.lock
phpunit.xml
.env
.phpunit.cache/
.phpunit.result.cache
.phpunit.cache/test-results
.php-cs-fixer.cache
phpstan.neon
tests/Support/temp/
.idea/
12 changes: 12 additions & 0 deletions src/Enums/Requests/HTTPState.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ enum HTTPState: int
*/
case OK = 200;

/**
* HTTP client error response
* status is bad request
*/
case BAD_REQUEST = 400;

/**
* HTTP client error response
* status is unauthorized
Expand All @@ -22,4 +28,10 @@ enum HTTPState: int
*/
case PAYMENT_REQUIRED = 402;

/**
* HTTP client error response
* status is forbidden
*/
case FORBIDDEN = 403;

}
55 changes: 55 additions & 0 deletions tests/HandelResultQwenTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
namespace Qwen\Tests;


use Qwen\Enums\Requests\HTTPState;
use PHPUnit\Framework\TestCase;
use Qwen\QwenClient;

class HandelResultQwenTest extends TestCase
{
protected $apiKey;
protected $expiredApiKey;
protected function setUp():void
{
$this->apiKey = "valid-api-key";
$this->expiredApiKey = "expired-api-key";
}

public function test_ok_response()
{
$qwen = QwenClient::build($this->apiKey)
->query('Hello Qwen, how are you today?');
$response = $qwen->run();
$result = $qwen->getResult();

$this->assertNotEmpty($response);
$this->assertTrue($result->isSuccess());
$this->assertEquals(HTTPState::OK->value, $result->getStatusCode());
}

public function test_can_not_access_with_api_expired_payment()
{
$qwen = QwenClient::build($this->expiredApiKey)
->query('Hello Qwen, how are you today?');
$response = $qwen->run();
$result = $qwen->getResult();

$this->assertNotEmpty($response);
if(!$result->isSuccess())
{
$this->assertEquals(HTTPState::BAD_REQUEST->value, $result->getStatusCode());
}
}

public function test_access_with_wrong_api_key()
{
$qwen = QwenClient::build($this->apiKey."wrong-api-key")
->query('Hello Qwen, how are you today?');
$response = $qwen->run();
$result = $qwen->getResult();

$this->assertNotEmpty($response);
$this->assertEquals(HTTPState::UNAUTHORIZED->value, $result->getStatusCode());
}
}
11 changes: 11 additions & 0 deletions tests/QwenTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Qwen\Tests;

use PHPUnit\Framework\TestCase;
use Qwen\QwenClient;

class QwenTest extends TestCase
{
// Tests will come soon
}