Skip to content

Commit f8c5682

Browse files
committed
test: minor fixes to tests
1 parent c0c6afa commit f8c5682

File tree

8 files changed

+43
-39
lines changed

8 files changed

+43
-39
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,8 @@ jobs:
4646
composer install --no-progress --no-interaction
4747
4848
- name: Run tests
49+
env:
50+
GROK_API_KEY: sk-test-key
51+
GROK_BASE_URL: https://api.x.ai/v1
4952
run: |
50-
composer test
53+
composer test --testsuite Unit

phpunit.xml

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,8 @@
33
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
44
bootstrap="vendor/autoload.php"
55
colors="true"
6-
cacheDirectory=".phpunit.cache"
7-
executionOrder="random"
8-
requireCoverageMetadata="true"
9-
beStrictAboutCoverageMetadata="true"
10-
beStrictAboutOutputDuringTests="true"
11-
failOnRisky="true"
12-
failOnWarning="true">
13-
6+
cacheDirectory=".phpunit.cache">
7+
148
<testsuites>
159
<testsuite name="Unit">
1610
<directory>tests/Unit</directory>
@@ -19,29 +13,16 @@
1913
<directory>tests/Integration</directory>
2014
</testsuite>
2115
</testsuites>
22-
23-
<coverage>
16+
17+
<source>
2418
<include>
2519
<directory suffix=".php">src</directory>
2620
</include>
27-
<exclude>
28-
<directory>src/Exceptions</directory>
29-
</exclude>
30-
<report>
31-
<html outputDirectory="coverage"/>
32-
<clover outputFile="coverage.xml"/>
33-
<text/>
34-
</report>
35-
</coverage>
36-
21+
</source>
22+
3723
<php>
3824
<env name="APP_ENV" value="testing"/>
39-
<env name="GROK_API_KEY" value="test-key"/>
25+
<env name="GROK_API_KEY" value="sk-test-key"/>
26+
<env name="GROK_BASE_URL" value="https://api.x.ai/v1"/>
4027
</php>
41-
42-
<source>
43-
<include>
44-
<directory suffix=".php">src</directory>
45-
</include>
46-
</source>
4728
</phpunit>

src/Enums/Model.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,10 @@ public static function default(): self
124124
{
125125
return self::GROK_2_1212;
126126
}
127+
128+
public function __toString(): string
129+
{
130+
return $this->value;
131+
}
132+
127133
}

tests/Integration/ChatTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Tests\Integration;
66

7+
use Dotenv\Dotenv;
78
use GrokPHP\Client\GrokClient;
89
use GrokPHP\Models\ChatMessage;
910
use GrokPHP\Exceptions\GrokException;
@@ -16,7 +17,10 @@ class ChatTest extends TestCase
1617

1718
protected function setUp(): void
1819
{
19-
$this->client = new GrokClient();
20+
parent::setUp();
21+
$dotenv = Dotenv::createImmutable(__DIR__);
22+
$dotenv->load();
23+
$this->client = new GrokClient(getenv('GROK_API_KEY'));
2024
}
2125

2226
public function testBasicChatCompletion(): void

tests/Integration/CompletionsTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ class CompletionsTest extends TestCase
1616

1717
protected function setUp(): void
1818
{
19-
$this->client = new GrokClient();
19+
parent::setUp();
20+
$dotenv = Dotenv::createImmutable(__DIR__);
21+
$dotenv->load();
22+
$this->client = new GrokClient(getenv('GROK_API_KEY'));
2023
}
2124

2225
public function testBasicCompletion(): void

tests/Integration/ImagesTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ class ImagesTest extends TestCase
1818

1919
protected function setUp(): void
2020
{
21-
$this->client = new GrokClient();
21+
parent::setUp();
22+
$dotenv = Dotenv::createImmutable(__DIR__);
23+
$dotenv->load();
24+
$this->client = new GrokClient(getenv('GROK_API_KEY'));
2225
}
2326

2427
public function testBasicImageAnalysis(): void
2528
{
26-
$response = $this->client->images()->analyze(
27-
$this->testImageUrl
28-
);
29+
$response = $this->client->images()->analyze($this->testImageUrl);
2930

3031
$this->assertInstanceOf(Image::class, $response);
3132
$this->assertNotEmpty($response->getAnalysis());

tests/Unit/ClientTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class ClientTest extends TestCase
2020

2121
protected function setUp(): void
2222
{
23-
$this->client = new GrokClient($_ENV['API_KEY']);
23+
parent::setUp();
24+
$this->client = new GrokClient($this->apiKey);
2425
}
2526

2627
/**

tests/Unit/ModelsTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Tests\Unit;
66

7+
use GrokPHP\Enums\Model;
78
use GrokPHP\Exceptions\GrokException;
89
use GrokPHP\Models\ChatMessage;
910
use GrokPHP\Models\ChatCompletion;
@@ -96,10 +97,12 @@ protected function setUp(): void
9697

9798
public function testChatMessageCreation(): void
9899
{
99-
$message = new ChatMessage($this->chatMessageData);
100+
$data = $this->chatMessageData;
101+
$data['model'] = Model::GROK_2_1212->value;
102+
$message = new ChatMessage($data);
100103

101104
$this->assertEquals('msg_123', $message->getId());
102-
$this->assertEquals('grok-2-latest', $message->getModel());
105+
$this->assertEquals(Model::GROK_2_1212->value, $message->getModel());
103106
$this->assertEquals('Test response', $message->getContent());
104107
$this->assertEquals('assistant', $message->getRole());
105108
$this->assertEquals('stop', $message->getFinishReason());
@@ -109,10 +112,12 @@ public function testChatMessageCreation(): void
109112

110113
public function testChatCompletionCreation(): void
111114
{
112-
$completion = new ChatCompletion($this->chatCompletionData);
115+
$data = $this->chatMessageData;
116+
$data['model'] = Model::GROK_2_1212->value;
117+
$completion = new ChatCompletion($data);
113118

114119
$this->assertEquals('compl_123', $completion->getId());
115-
$this->assertEquals('grok-2-1212', $completion->getModel());
120+
$this->assertEquals(Model::GROK_2_1212->value, $completion->getModel());
116121
$this->assertEquals('Test completion', $completion->getText());
117122
$this->assertEquals('openrouter', $completion->getProvider());
118123
$this->assertEquals(40, $completion->getUsage()['total_tokens']);

0 commit comments

Comments
 (0)