Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit 8329e62

Browse files
committed
Release version 1.3.0
1 parent 61a00e0 commit 8329e62

23 files changed

+122
-113
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434

3535
steps:
3636
- name: Checkout
37-
uses: actions/checkout@v2
37+
uses: actions/checkout@v3
3838

3939
- name: Setup PHP
4040
uses: shivammathur/setup-php@v2
@@ -86,13 +86,11 @@ jobs:
8686

8787
steps:
8888
- name: Checkout
89-
uses: actions/checkout@v2
89+
uses: actions/checkout@v3
9090

9191
- name: Setup node
9292
if: matrix.test-type == 'integration'
93-
uses: actions/setup-node@v2
94-
with:
95-
node-version: '16'
93+
uses: actions/setup-node@v3
9694

9795
- name: Install and run @stoplight/prism
9896
if: matrix.test-type == 'integration'
@@ -141,12 +139,10 @@ jobs:
141139

142140
steps:
143141
- name: Checkout
144-
uses: actions/checkout@v2
142+
uses: actions/checkout@v3
145143

146144
- name: Setup node
147-
uses: actions/setup-node@v2
148-
with:
149-
node-version: '16'
145+
uses: actions/setup-node@v3
150146

151147
- name: Install and run @stoplight/prism
152148
run: |

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## 1.3.0 - 2022-12-21
9+
10+
### Added
11+
- Use parameters defined outside endpoint methods.
12+
13+
### Changed
14+
- Encourage the use of `php-http/mock-client` for testing and mocking API responses.
15+
- Remove the `Tests\MockHttpClient` class, and use the `php-http/mock-client` package instead.
16+
- Make Handler and Model class names more readable.
17+
18+
### Fixed
19+
- Use correct model type for nested models.
20+
821
## 1.2.0 - 2022-11-07
922

1023
### Added

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,16 @@ composer test:integration
357357

358358
We do not recommend running integration tests against the live OpenAI API endpoints. This is because the tests will send example data to all endpoints, which can result in new data being created, or existing data being deleted.
359359

360+
### Writing Your Own Tests
361+
362+
If you are writing your own tests, you will likely need to mock the responses from the **OpenAI API**.
363+
364+
One way of doing this is to install the `php-http/mock-client` package into your project, and then use the `\Http\Mock\Client` class (instead of a real PSR-18 client) when instantiating the **Tectalic OpenAI REST API Client**.
365+
366+
This allows you to mock the responses from the **OpenAI API**, rather than performing real requests.
367+
368+
Please see the [Mock Client documentation](https://docs.php-http.org/en/latest/clients/mock-client.html#mock-client) for details.
369+
360370
## Support
361371

362372
If you have any questions or feedback, please use the [discussion board](https://github.com/tectalichq/public-openai-client-php/discussions).

composer.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"require-dev": {
4343
"league/openapi-psr7-validator": "^0.17.0",
4444
"mikey179/vfsstream": "^1.6.10",
45+
"php-http/mock-client": "^1.5",
4546
"phpstan/phpstan": "^1.4",
4647
"phpunit/phpunit": "^8.5.14 || ^9.5",
4748
"squizlabs/php_codesniffer": "^3.6",
@@ -54,7 +55,10 @@
5455
"@test:unit",
5556
"@test:integration"
5657
],
57-
"test:coverage": "XDEBUG_MODE=coverage phpunit --verbose --coverage-html=coverage",
58+
"test:coverage": [
59+
"Composer\\Config::disableProcessTimeout",
60+
"XDEBUG_MODE=coverage phpunit --verbose --coverage-html=coverage"
61+
],
5862
"test:integration": "phpunit --verbose --testsuite=integration",
5963
"test:phpcs": "phpcs -q -s",
6064
"test:phpstan": "phpstan analyse --memory-limit=1G",
@@ -67,5 +71,8 @@
6771
"test:phpstan": "Static test via phpstan.",
6872
"test:phpcs": "Style test via phpcs.",
6973
"test:unit": "Unit test via phpunit."
74+
},
75+
"suggest": {
76+
"php-http/mock-client": "Simplify testing by using a mock HTTP client"
7077
}
7178
}

manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"libraryVersion": "1.2.0",
2+
"libraryVersion": "1.3.0",
33
"apiVersion": "1.1.0",
4-
"buildVersion": "1.1.5"
4+
"buildVersion": "1.2.0"
55
}

src/Client.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace Tectalic\OpenAi;
1414

15+
use Http\Message\Authentication;
1516
use Http\Message\MultipartStream\MultipartStreamBuilder;
1617
use Nyholm\Psr7\Factory\Psr17Factory;
1718
use Psr\Http\Client\ClientExceptionInterface;
@@ -369,7 +370,7 @@ private function mergeRequestParts(
369370

370371
$request = $request->withHeader(
371372
'User-Agent',
372-
'Tectalic OpenAI REST API Client/1.2.0'
373+
'Tectalic OpenAI REST API Client/1.3.0'
373374
);
374375

375376
// Merge Headers.

src/Manager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace Tectalic\OpenAi;
1414

15+
use Http\Message\Authentication;
1516
use LogicException;
1617
use Psr\Http\Client\ClientInterface;
1718

tests/MockHttpClient.php

Lines changed: 0 additions & 47 deletions
This file was deleted.

tests/NullAuth.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/**
4+
* Copyright (c) 2022 Tectalic (https://tectalic.com)
5+
*
6+
* For copyright and license information, please view the LICENSE file that was distributed with this source code.
7+
*
8+
* Please see the README.md file for usage instructions.
9+
*/
10+
11+
declare(strict_types=1);
12+
13+
namespace Tests;
14+
15+
use Http\Message\Authentication;
16+
use Psr\Http\Message\RequestInterface;
17+
18+
final class NullAuth implements Authentication
19+
{
20+
public function authenticate(RequestInterface $request): RequestInterface
21+
{
22+
return $request;
23+
}
24+
}

tests/Unit/ClientTest.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,28 @@
1212

1313
namespace Tests\Unit;
1414

15+
use Http\Mock\Client;
1516
use LogicException;
1617
use Nyholm\Psr7\Request;
1718
use PHPUnit\Framework\TestCase;
1819
use Psr\Http\Message\RequestInterface;
1920
use ReflectionClass;
2021
use ReflectionObject;
21-
use Tectalic\OpenAi\Authentication;
22-
use Tectalic\OpenAi\Client;
22+
use Tectalic\OpenAi\Client as OpenAiClient;
2323
use Tectalic\OpenAi\ClientException;
2424
use Tectalic\OpenAi\Manager;
2525
use Tectalic\OpenAi\Models\AbstractModel;
2626
use Tectalic\OpenAi\Models\AbstractModelCollection;
2727
use Tectalic\OpenAi\Models\UnstructuredModel;
28-
use Tests\MockHttpClient;
28+
use Tests\NullAuth;
2929

3030
final class ClientTest extends TestCase
3131
{
3232
public function setUp(): void
3333
{
3434
Manager::build(
35-
new MockHttpClient(),
36-
new Authentication('token')
35+
new Client(),
36+
new NullAuth()
3737
);
3838
}
3939

@@ -48,9 +48,9 @@ public function tearDown(): void
4848

4949
public function testGlobal(): void
5050
{
51-
$client = new Client(
52-
new MockHttpClient(),
53-
new Authentication('token'),
51+
$client = new OpenAiClient(
52+
new Client(),
53+
new NullAuth(),
5454
Manager::BASE_URI
5555
);
5656
$this->assertEquals($client, Manager::access());
@@ -64,8 +64,8 @@ public function testDoubleBuild(): void
6464
$this->expectException(LogicException::class);
6565
$this->expectExceptionMessage('Client already built.');
6666
Manager::build(
67-
new MockHttpClient(),
68-
new Authentication('token')
67+
new Client(),
68+
new NullAuth()
6969
);
7070
}
7171

@@ -385,15 +385,19 @@ public function invalidResponse(): array
385385

386386
/**
387387
* @dataProvider invalidResponse
388-
* @param class-string<\Throwable> $exception
388+
* @param class-string<\Exception> $exception
389389
*/
390390
public function testInvalidResponse(string $method, string $exception, string $message): void
391391
{
392392
$this->expectException(ClientException::class);
393393
$this->expectExceptionMessage($message);
394-
$client = new Client(
395-
new MockHttpClient(new $exception()),
396-
new Authentication('token'),
394+
395+
$mockClient = new Client();
396+
$mockClient->addException(new $exception());
397+
398+
$client = new OpenAiClient(
399+
$mockClient,
400+
new NullAuth(),
397401
Manager::BASE_URI
398402
);
399403
$client->sendRequest($client->$method('/'));

0 commit comments

Comments
 (0)