-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: phpunit with real typesense server
BREAKING CHANGE: ClientSingletonFactory->getClient is now protected
- Loading branch information
Showing
5 changed files
with
79 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
DATABASE_URL="sqlite:///%kernel.project_dir%/typesense-test.db" | ||
APP_SECRET=460c14d1f74aeb10cffae741fcaaddac773b3260 | ||
APP_ENV=test | ||
APP_ENV=test | ||
TYPESENSE_API_KEY=xyz | ||
TYPESENSE_URL="http://127.0.0.1:8108" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Biblioverse\TypesenseBundle\Tests; | ||
|
||
use Biblioverse\TypesenseBundle\Client\ClientInterface; | ||
use Biblioverse\TypesenseBundle\Client\ClientSingletonFactory; | ||
use Http\Discovery\Psr18ClientDiscovery; | ||
use PHPUnit\Framework\TestCase; | ||
use Typesense\Exceptions\ConfigError; | ||
|
||
class RealInstanceTest extends TestCase | ||
{ | ||
/** | ||
* @throws ConfigError | ||
*/ | ||
protected function getClient(): ?ClientInterface | ||
{ | ||
$httpClient = (new Psr18ClientDiscovery())->find(); | ||
|
||
/** @var string|null $url */ | ||
$url = $_ENV['TYPESENSE_URL'] ?? null; | ||
/** @var string|null $apiKey */ | ||
$apiKey = $_ENV['TYPESENSE_API_KEY'] ?? null; | ||
|
||
if ($url === null || $apiKey === null) { | ||
return null; | ||
} | ||
|
||
$clientSingletonFactory = new ClientSingletonFactory($url, $apiKey, $httpClient); | ||
|
||
return $clientSingletonFactory->__invoke(); | ||
} | ||
|
||
/** | ||
* @throws \Exception | ||
*/ | ||
public function testCanRetrieveMetrics(): void | ||
{ | ||
$client = $this->getClient(); | ||
if (!$client instanceof ClientInterface) { | ||
$this->markTestSkipped('env TYPESENSE_URL or TYPESENSE_API_KEY not provided'); | ||
} | ||
|
||
$returnData = $client->getMetrics()->retrieve(); | ||
$this->assertArrayHasKey('system_memory_used_bytes', $returnData); | ||
} | ||
} |