diff --git a/.github/workflows/emulator-system-tests-bigtable.yaml b/.github/workflows/emulator-system-tests-bigtable.yaml index f6efcf74d260..fc49ee42f6a4 100644 --- a/.github/workflows/emulator-system-tests-bigtable.yaml +++ b/.github/workflows/emulator-system-tests-bigtable.yaml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@v5 - - run: ./.github/emulator/start-emulator.sh bigtable 419.0.0-emulators + - run: ./.github/emulator/start-emulator.sh bigtable 522.0.0-emulators - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/.github/workflows/emulator-system-tests-datastore.yaml b/.github/workflows/emulator-system-tests-datastore.yaml index 2add13dce1f1..b562e9931b83 100644 --- a/.github/workflows/emulator-system-tests-datastore.yaml +++ b/.github/workflows/emulator-system-tests-datastore.yaml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@v5 - - run: ./.github/emulator/start-emulator.sh datastore 419.0.0-emulators + - run: ./.github/emulator/start-emulator.sh datastore 522.0.0-emulators - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/.github/workflows/emulator-system-tests-firestore.yaml b/.github/workflows/emulator-system-tests-firestore.yaml index 6683f958bd5d..b95a4a45c4ec 100644 --- a/.github/workflows/emulator-system-tests-firestore.yaml +++ b/.github/workflows/emulator-system-tests-firestore.yaml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@v5 - - run: ./.github/emulator/start-emulator.sh firestore 453.0.0-emulators + - run: ./.github/emulator/start-emulator.sh firestore 522.0.0-emulators - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/Firestore/src/Connection/Grpc.php b/Firestore/src/Connection/Grpc.php index 182155f9d071..ac3ea18615cc 100644 --- a/Firestore/src/Connection/Grpc.php +++ b/Firestore/src/Connection/Grpc.php @@ -51,11 +51,6 @@ class Grpc implements ConnectionInterface */ private $firestore; - /** - * @var string - */ - private $resourcePrefixHeader; - /** * @var string */ @@ -124,15 +119,8 @@ public function __construct(array $config = []) $projectId = $this->pluck('projectId', $config); $databaseId = $this->pluck('database', $config); - $this->resourcePrefixHeader = FirestoreClient::databaseRootName( - $projectId, - $databaseId - ); - $this->databaseRoutingHeader = sprintf( - 'project_id=%s&database_id=%s', - $projectId, - $databaseId - ); + $database = FirestoreClient::databaseRootName($projectId, $databaseId); + $this->databaseRoutingHeader = sprintf('database=%s', urlencode($database)); } /** @@ -315,8 +303,9 @@ private function addRequestHeaders(array $args) 'headers' => [] ]; - $args['headers']['google-cloud-resource-prefix'] = [$this->resourcePrefixHeader]; - $args['headers']['x-goog-request-params'] = [$this->databaseRoutingHeader]; + $args['headers']['x-goog-request-params'] = [ + $this->databaseRoutingHeader, + ]; // Provide authentication header for requests when emulator is enabled. if ($this->isUsingEmulator) { @@ -354,7 +343,6 @@ public function __debugInfo() return [ 'serializer' => get_class($this->serializer), 'firestore' => get_class($this->firestore), - 'resourcePrefixHeader' => $this->resourcePrefixHeader, 'databaseRoutingHeader' => $this->databaseRoutingHeader, 'isUsingEmulator' => $this->isUsingEmulator ]; diff --git a/Firestore/tests/System/ListenTest.php b/Firestore/tests/System/ListenTest.php new file mode 100644 index 000000000000..ce5bcc206e48 --- /dev/null +++ b/Firestore/tests/System/ListenTest.php @@ -0,0 +1,100 @@ +query = self::$client->collection(uniqid(self::COLLECTION_NAME)); + self::$localDeletionQueue->add($this->query); + if (!$this->projectId = getenv('GOOGLE_CLOUD_FIRESTORE_PROJECT')) { + $this->markTestSkipped('please set the GOOGLE_CLOUD_FIRESTORE_PROJECT env var'); + } + } + + public function testListen() + { + $database = sprintf(self::DATABASE, $this->projectId); + + // Create a client. + $firestoreClient = new FirestoreClient(); + + // Prepare the request message. + $request = (new ListenRequest()) + ->setDatabase($database); + + // Call the API and handle any network failures. + /** @var BidiStream $stream */ + $stream = $firestoreClient->listen([ + 'headers' => [ + 'x-goog-request-params' => [ + 'database=' . $database + ] + ] + ]); + $stream->writeAll([$request,]); + + /** @var ListenResponse $element */ + foreach ($stream->closeWriteAndReadAll() as $element) { + // TODO: Assert something + } + $this->assertTrue(true); + } + + public function testListenThrowsExceptionWithoutDatabaseHeader() + { + $this->expectException(ApiException::class); + $this->expectExceptionMessage( + 'Missing required http header (\'google-cloud-resource-prefix\' or \'x-goog-request-params\')' + . ' or query param \'database\'.' + ); + $database = sprintf(self::DATABASE, $this->projectId); + + // Create a client. + $firestoreClient = new FirestoreClient(); + + // Prepare the request message. + $request = (new ListenRequest()) + ->setDatabase($database); + + // Call the API and handle any network failures. + /** @var BidiStream $stream */ + $stream = $firestoreClient->listen(); + $stream->writeAll([$request,]); + + /** @var ListenResponse $element */ + foreach ($stream->closeWriteAndReadAll() as $element) { + // TODO: Assert something + } + } +} diff --git a/Firestore/tests/Unit/Connection/GrpcTest.php b/Firestore/tests/Unit/Connection/GrpcTest.php index 0202ec87c489..5368985f84bb 100644 --- a/Firestore/tests/Unit/Connection/GrpcTest.php +++ b/Firestore/tests/Unit/Connection/GrpcTest.php @@ -404,8 +404,9 @@ private function header() { return [ "headers" => [ - "google-cloud-resource-prefix" => ["projects/test/databases/(default)"], - "x-goog-request-params" => ["project_id=test&database_id=(default)"] + "x-goog-request-params" => [ + 'database=projects%2Ftest%2Fdatabases%2F%28default%29' + ] ] ]; }