diff --git a/.env.test b/.env.test index 4911719..9a4d7ef 100644 --- a/.env.test +++ b/.env.test @@ -1,3 +1,5 @@ DATABASE_URL="sqlite:///%kernel.project_dir%/typesense-test.db" APP_SECRET=460c14d1f74aeb10cffae741fcaaddac773b3260 -APP_ENV=test \ No newline at end of file +APP_ENV=test +TYPESENSE_API_KEY=xyz +TYPESENSE_URL="http://127.0.0.1:8108" \ No newline at end of file diff --git a/.github/workflows/coding-standards.yaml b/.github/workflows/coding-standards.yaml index 9028f9e..8845414 100644 --- a/.github/workflows/coding-standards.yaml +++ b/.github/workflows/coding-standards.yaml @@ -11,7 +11,6 @@ on: push: branches: - "main" - jobs: conventional-commits: name: "conventional-commits" @@ -36,6 +35,18 @@ jobs: php-version: "8.2" - composer-versions: "lowest" php-version: "8.4" + + services: + typesense: + image: typesense/typesense:28.0 + ports: + - 8108:8108/tcp + volumes: + - /tmp/typesense-server-data:/data + env: + TYPESENSE_DATA_DIR: /data + TYPESENSE_API_KEY: xyz + TYPESENSE_ENABLE_CORS: true steps: - name: "Checkout" uses: "actions/checkout@v4" diff --git a/docker-compose.yml b/docker-compose.yml index 7305b13..379ee31 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,18 +8,25 @@ services: tty: true environment: - PHP_IDE_CONFIG=serverName=typesensebundle + - TYPESENSE_URL=http://typesense:8108 + - TYPESENSE_API_KEY=xyz extra_hosts: - host.docker.internal:host-gateway networks: - default -# typesense: -# image: typesense/typesense:27.1 -# restart: on-failure -# ports: -# - 8983 -# - "9908:8108" -# volumes: -# - searchdata:/data -# command: '--data-dir /data --api-key=xyz --enable-cors' + typesense: + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8108/health"] + links: + - php + image: typesense/typesense:28.0 + restart: on-failure + volumes: + - typesense-server-data:/data + environment: + TYPESENSE_DATA_DIR: /data + TYPESENSE_API_KEY: xyz + TYPESENSE_ENABLE_CORS: true volumes: searchdata: + typesense-server-data: diff --git a/src/Client/ClientSingletonFactory.php b/src/Client/ClientSingletonFactory.php index 70ed929..628dc63 100644 --- a/src/Client/ClientSingletonFactory.php +++ b/src/Client/ClientSingletonFactory.php @@ -63,7 +63,7 @@ private function getConfiguration(): array return array_merge($this->defaultConfig, $config); } - public function getClient(): HttpClient + protected function getClient(): HttpClient { $client = $this->httpClient ?? (new Psr18ClientDiscovery())->find(); diff --git a/tests/RealInstanceTest.php b/tests/RealInstanceTest.php new file mode 100644 index 0000000..e2c7350 --- /dev/null +++ b/tests/RealInstanceTest.php @@ -0,0 +1,47 @@ +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); + } +}