Skip to content

Commit 14cdf0e

Browse files
committed
test(generators): Add BitoGeneratorTest
- Add tests/Unit/Generators/BitoGeneratorTest.php - Test that app(GeneratorManager::class)->driver('bito') throws ProcessFailedException
1 parent effe495 commit 14cdf0e

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

app/GeneratorManager.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
namespace App;
1414

1515
use App\Exceptions\InvalidArgumentException;
16-
use App\Generators\BitoGenerator;
1716
use App\Generators\OpenAIChatGenerator;
1817
use App\Generators\OpenAIGenerator;
1918
use Illuminate\Support\Manager;
@@ -68,9 +67,4 @@ private function createOpenAIChatDriver(array $config): OpenAIChatGenerator
6867
{
6968
return new OpenAIChatGenerator($config);
7069
}
71-
72-
private function createBitoDriver(array $config): BitoGenerator
73-
{
74-
return new BitoGenerator($config);
75-
}
7670
}

tests/TestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ protected function setUp(): void
4444

4545
$configManager = ConfigManager::createFrom($this->app->configPath('ai-commit.php'));
4646
$configManager->set('generators.openai.api_key', 'sk-...');
47+
$configManager->set('generators.bito.path', 'bito-path...');
4748

4849
config()->set('ai-commit', $configManager);
4950
}

tests/Unit/GeneratorManagerTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
use App\GeneratorManager;
14+
use App\Generators\BitoGenerator;
1415
use App\Generators\OpenAIChatGenerator;
1516
use App\Generators\OpenAIGenerator;
1617

@@ -35,6 +36,11 @@
3536
->driver('openaichat')->toBeInstanceOf(OpenAIChatGenerator::class);
3637
})->group(__DIR__, __FILE__);
3738

39+
it('can create Bito driver', function (): void {
40+
expect($this->app->get(GeneratorManager::class))
41+
->driver('bito')->toBeInstanceOf(BitoGenerator::class);
42+
})->group(__DIR__, __FILE__);
43+
3844
it('will throw InvalidArgumentException when run driver', function (): void {
3945
$this->app->get(GeneratorManager::class)->driver('foo');
4046
})->group(__DIR__, __FILE__)->throws(InvalidArgumentException::class, 'Driver [foo] not supported.');
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of the guanguans/ai-commit.
7+
*
8+
* (c) guanguans <ityaozm@gmail.com>
9+
*
10+
* This source file is subject to the MIT license that is bundled.
11+
*/
12+
13+
use App\GeneratorManager;
14+
use Symfony\Component\Process\Exception\ProcessFailedException;
15+
16+
beforeEach(function (): void {
17+
});
18+
19+
it('throws `ProcessFailedException`', function (): void {
20+
expect(app(GeneratorManager::class)->driver('bito'))->generate('error');
21+
})->group(__DIR__, __FILE__)->throws(ProcessFailedException::class);

tests/Unit/Generators/OpenAIChatGeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
expect(app(GeneratorManager::class)->driver('openaichat'))
2222
->generate('OK')->toBeString()->not->toBeEmpty();
2323
Http::assertSentCount(1);
24-
});
24+
})->group(__DIR__, __FILE__);

0 commit comments

Comments
 (0)