|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\Attributes\CoversClass; |
15 | 15 | use PHPUnit\Framework\Attributes\Small; |
| 16 | +use PHPUnit\Framework\Attributes\TestWith; |
16 | 17 | use PHPUnit\Framework\TestCase; |
17 | 18 | use Symfony\AI\Platform\Bridge\OpenAi\Whisper; |
18 | 19 | use Symfony\AI\Platform\Bridge\OpenAi\Whisper\ModelClient; |
19 | 20 | use Symfony\AI\Platform\Bridge\OpenAi\Whisper\Task; |
| 21 | +use Symfony\AI\Platform\Exception\InvalidArgumentException; |
20 | 22 | use Symfony\Component\HttpClient\MockHttpClient; |
21 | 23 | use Symfony\Component\HttpClient\Response\MockResponse; |
22 | 24 |
|
23 | 25 | #[CoversClass(ModelClient::class)] |
24 | 26 | #[Small] |
25 | 27 | final class ModelClientTest extends TestCase |
26 | 28 | { |
| 29 | + public function testItThrowsExceptionWhenApiKeyIsEmpty() |
| 30 | + { |
| 31 | + $this->expectException(InvalidArgumentException::class); |
| 32 | + $this->expectExceptionMessage('The API key must not be empty.'); |
| 33 | + |
| 34 | + new ModelClient(new MockHttpClient(), ''); |
| 35 | + } |
| 36 | + |
| 37 | + #[TestWith(['api-key-without-prefix'])] |
| 38 | + #[TestWith(['pk-api-key'])] |
| 39 | + #[TestWith(['SK-api-key'])] |
| 40 | + #[TestWith(['skapikey'])] |
| 41 | + #[TestWith(['sk api-key'])] |
| 42 | + #[TestWith(['sk'])] |
| 43 | + public function testItThrowsExceptionWhenApiKeyDoesNotStartWithSk(string $invalidApiKey) |
| 44 | + { |
| 45 | + $this->expectException(InvalidArgumentException::class); |
| 46 | + $this->expectExceptionMessage('The API key must start with "sk-".'); |
| 47 | + |
| 48 | + new ModelClient(new MockHttpClient(), $invalidApiKey); |
| 49 | + } |
| 50 | + |
| 51 | + public function testItAcceptsValidApiKey() |
| 52 | + { |
| 53 | + $modelClient = new ModelClient(new MockHttpClient(), 'sk-valid-api-key'); |
| 54 | + |
| 55 | + $this->assertInstanceOf(ModelClient::class, $modelClient); |
| 56 | + } |
| 57 | + |
27 | 58 | public function testItSupportsWhisperModel() |
28 | 59 | { |
29 | 60 | $client = new ModelClient(new MockHttpClient(), 'sk-test-key'); |
|
0 commit comments