From e4fbe56bf96dfbe7d69ffd3b34f0a13d9f6c01f4 Mon Sep 17 00:00:00 2001 From: omaralalwi Date: Sat, 1 Feb 2025 03:18:46 +0300 Subject: [PATCH 1/5] feat / test cases --- composer.json | 3 ++- tests/DeepseekTest.php | 9 --------- tests/Helpers/TestCase.php | 23 +++++++++++++++++++++++ tests/Integration/ApiIntegrationTest.php | 21 +++++++++++++++++++++ tests/Pest.php | 5 +++++ tests/Unit/DeepSeekClientTest.php | 24 ++++++++++++++++++++++++ 6 files changed, 75 insertions(+), 10 deletions(-) delete mode 100644 tests/DeepseekTest.php create mode 100644 tests/Helpers/TestCase.php create mode 100644 tests/Integration/ApiIntegrationTest.php create mode 100644 tests/Pest.php create mode 100644 tests/Unit/DeepSeekClientTest.php diff --git a/composer.json b/composer.json index 7e39749..864db28 100644 --- a/composer.json +++ b/composer.json @@ -61,7 +61,7 @@ "laravel/pint": "^1.18.1", "mockery/mockery": "^1.6.12", "nunomaduro/collision": "^7.11.0|^8.5.0", - "pestphp/pest": "^2.36.0|^3.5.0", + "pestphp/pest": "^3.7", "pestphp/pest-plugin-arch": "^2.7|^3.0", "pestphp/pest-plugin-type-coverage": "^2.8.7|^3.1.0", "phpstan/phpstan": "^1.12.7", @@ -96,6 +96,7 @@ "config": { "sort-packages": true, "preferred-install": "dist", + "optimize-autoloader": true, "allow-plugins": { "pestphp/pest-plugin": true, "php-http/discovery": true diff --git a/tests/DeepseekTest.php b/tests/DeepseekTest.php deleted file mode 100644 index a8a7141..0000000 --- a/tests/DeepseekTest.php +++ /dev/null @@ -1,9 +0,0 @@ - $handlerStack]); + } + + protected function createDeepSeekClient($apiKey, $httpClient = null) + { + return new DeepSeekClient($apiKey, $httpClient); + } +} diff --git a/tests/Integration/ApiIntegrationTest.php b/tests/Integration/ApiIntegrationTest.php new file mode 100644 index 0000000..02f980f --- /dev/null +++ b/tests/Integration/ApiIntegrationTest.php @@ -0,0 +1,21 @@ +client = new DeepSeekClient(getenv('DEEPSEEK_API_KEY')); +}); + +it('fetches data from the API', function () { + $response = $this->client->get('/some-endpoint'); + expect($response)->toBeArray(); + expect($response)->toHaveKey('data'); +}); diff --git a/tests/Pest.php b/tests/Pest.php new file mode 100644 index 0000000..a04204d --- /dev/null +++ b/tests/Pest.php @@ -0,0 +1,5 @@ +in('Unit', 'Integration'); diff --git a/tests/Unit/DeepSeekClientTest.php b/tests/Unit/DeepSeekClientTest.php new file mode 100644 index 0000000..8f2476c --- /dev/null +++ b/tests/Unit/DeepSeekClientTest.php @@ -0,0 +1,24 @@ +mockHandler = new MockHandler(); + $this->httpClient = new HttpClient(['handler' => HandlerStack::create($this->mockHandler)]); + $this->client = new DeepSeekClient('test-api-key', $this->httpClient); +}); + +it('can set API key', function () { + expect($this->client->getApiKey())->toBe('test-api-key'); +}); + +it('makes a GET request successfully', function () { + $this->mockHandler->append(new \GuzzleHttp\Psr7\Response(200, [], '{"data": "success"}')); + + $response = $this->client->get('/endpoint'); + expect($response)->toBeArray(); + expect($response['data'])->toBe('success'); +}); From 00745a8d7c69d5018cd4c92e986060dccc77a6f2 Mon Sep 17 00:00:00 2001 From: omaralalwi Date: Sun, 2 Feb 2025 00:53:15 +0300 Subject: [PATCH 2/5] fix xml file --- README.md | 3 +++ composer.json | 4 ++-- tests/Feature/ExampleTest.php | 5 +++++ tests/TestCase.php | 10 ++++++++++ tests/Unit/DeepSeekClientTest.php | 23 +++-------------------- tests/Unit/ExampleTest.php | 5 +++++ 6 files changed, 28 insertions(+), 22 deletions(-) create mode 100644 tests/Feature/ExampleTest.php create mode 100644 tests/TestCase.php create mode 100644 tests/Unit/ExampleTest.php diff --git a/README.md b/README.md index a1bdab9..b2201ec 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,9 @@ Detailed release notes available in [CHANGELOG.md](CHANGELOG.md) ```bash composer test + +./vendor/bin/pest + ``` Test coverage coming in v2.1. diff --git a/composer.json b/composer.json index 864db28..fd9edea 100644 --- a/composer.json +++ b/composer.json @@ -61,7 +61,7 @@ "laravel/pint": "^1.18.1", "mockery/mockery": "^1.6.12", "nunomaduro/collision": "^7.11.0|^8.5.0", - "pestphp/pest": "^3.7", + "pestphp/pest": "^2.36", "pestphp/pest-plugin-arch": "^2.7|^3.0", "pestphp/pest-plugin-type-coverage": "^2.8.7|^3.1.0", "phpstan/phpstan": "^1.12.7", @@ -75,7 +75,7 @@ }, "autoload-dev": { "psr-4": { - "DeepSeek\\Tests\\": "tests/" + "Tests\\": "tests/" } }, "minimum-stability": "dev", diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php new file mode 100644 index 0000000..61cd84c --- /dev/null +++ b/tests/Feature/ExampleTest.php @@ -0,0 +1,5 @@ +toBeTrue(); +}); diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..cfb05b6 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,10 @@ +mockHandler = new MockHandler(); - $this->httpClient = new HttpClient(['handler' => HandlerStack::create($this->mockHandler)]); - $this->client = new DeepSeekClient('test-api-key', $this->httpClient); -}); - -it('can set API key', function () { - expect($this->client->getApiKey())->toBe('test-api-key'); -}); - -it('makes a GET request successfully', function () { - $this->mockHandler->append(new \GuzzleHttp\Psr7\Response(200, [], '{"data": "success"}')); - - $response = $this->client->get('/endpoint'); - expect($response)->toBeArray(); - expect($response['data'])->toBe('success'); + expect($result)->toBe(3); }); diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php new file mode 100644 index 0000000..61cd84c --- /dev/null +++ b/tests/Unit/ExampleTest.php @@ -0,0 +1,5 @@ +toBeTrue(); +}); From 879ef902a31e21a5830c0481ce579f4eeceae812 Mon Sep 17 00:00:00 2001 From: omaralalwi Date: Sun, 2 Feb 2025 00:56:16 +0300 Subject: [PATCH 3/5] fix xml file --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index b2201ec..b63d2e0 100644 --- a/README.md +++ b/README.md @@ -117,9 +117,8 @@ Detailed release notes available in [CHANGELOG.md](CHANGELOG.md) ```bash composer test - +OR ./vendor/bin/pest - ``` Test coverage coming in v2.1. From 1358ad607257276549ad64e6eb17d78e0ef55015 Mon Sep 17 00:00:00 2001 From: omaralalwi Date: Sun, 2 Feb 2025 01:03:26 +0300 Subject: [PATCH 4/5] update --- tests/Helpers/TestCase.php | 23 ----------------------- tests/Integration/ApiIntegrationTest.php | 21 --------------------- tests/Unit/DeepSeekClientTest.php | 7 ------- tests/Unit/ExampleTest.php | 5 ----- 4 files changed, 56 deletions(-) delete mode 100644 tests/Helpers/TestCase.php delete mode 100644 tests/Integration/ApiIntegrationTest.php delete mode 100644 tests/Unit/DeepSeekClientTest.php delete mode 100644 tests/Unit/ExampleTest.php diff --git a/tests/Helpers/TestCase.php b/tests/Helpers/TestCase.php deleted file mode 100644 index 785915f..0000000 --- a/tests/Helpers/TestCase.php +++ /dev/null @@ -1,23 +0,0 @@ - $handlerStack]); - } - - protected function createDeepSeekClient($apiKey, $httpClient = null) - { - return new DeepSeekClient($apiKey, $httpClient); - } -} diff --git a/tests/Integration/ApiIntegrationTest.php b/tests/Integration/ApiIntegrationTest.php deleted file mode 100644 index 02f980f..0000000 --- a/tests/Integration/ApiIntegrationTest.php +++ /dev/null @@ -1,21 +0,0 @@ -client = new DeepSeekClient(getenv('DEEPSEEK_API_KEY')); -}); - -it('fetches data from the API', function () { - $response = $this->client->get('/some-endpoint'); - expect($response)->toBeArray(); - expect($response)->toHaveKey('data'); -}); diff --git a/tests/Unit/DeepSeekClientTest.php b/tests/Unit/DeepSeekClientTest.php deleted file mode 100644 index 11bae6e..0000000 --- a/tests/Unit/DeepSeekClientTest.php +++ /dev/null @@ -1,7 +0,0 @@ -toBe(3); -}); diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php deleted file mode 100644 index 61cd84c..0000000 --- a/tests/Unit/ExampleTest.php +++ /dev/null @@ -1,5 +0,0 @@ -toBeTrue(); -}); From 6e9e5f98f3196bab6626845a139990dfa223533e Mon Sep 17 00:00:00 2001 From: omaralalwi Date: Sun, 2 Feb 2025 01:34:47 +0300 Subject: [PATCH 5/5] clean up --- tests/{ => Feature}/HandelResultDeepseekTest.php | 6 +++--- tests/Pest.php | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) rename tests/{ => Feature}/HandelResultDeepseekTest.php (97%) diff --git a/tests/HandelResultDeepseekTest.php b/tests/Feature/HandelResultDeepseekTest.php similarity index 97% rename from tests/HandelResultDeepseekTest.php rename to tests/Feature/HandelResultDeepseekTest.php index 18a9007..9b2ab44 100644 --- a/tests/HandelResultDeepseekTest.php +++ b/tests/Feature/HandelResultDeepseekTest.php @@ -1,10 +1,10 @@ setTemperature(1.5); $response = $deepseek->run(); $result = $deepseek->getResult(); - + $this->assertNotEmpty($response); $this->assertEquals(HTTPState::UNAUTHORIZED->value, $result->getStatusCode()); } diff --git a/tests/Pest.php b/tests/Pest.php index a04204d..7ea77fb 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -1,5 +1,3 @@ in('Unit', 'Integration'); + //