From 00c6db0a876eabe2cff6bcb89342d200314362ff Mon Sep 17 00:00:00 2001 From: Aalap Shastri Date: Thu, 16 Apr 2026 20:03:03 +0000 Subject: [PATCH 1/3] add support for Ads Assistant header via middleware Change-Id: Ia8e2cbea26aba8942303c760939d3f1074bd3b2c --- .../Lib/V20/AdsAssistantHeaderMiddleware.php | 52 +++++++++++++++++++ .../Lib/V20/GoogleAdsGapicClientTrait.php | 21 ++++---- .../Lib/V21/AdsAssistantHeaderMiddleware.php | 52 +++++++++++++++++++ .../Lib/V21/GoogleAdsGapicClientTrait.php | 17 +++--- .../Lib/V22/AdsAssistantHeaderMiddleware.php | 52 +++++++++++++++++++ .../Lib/V22/GoogleAdsGapicClientTrait.php | 17 +++--- .../Lib/V23/AdsAssistantHeaderMiddleware.php | 52 +++++++++++++++++++ .../Lib/V23/GoogleAdsGapicClientTrait.php | 18 ++++--- 8 files changed, 251 insertions(+), 30 deletions(-) create mode 100644 src/Google/Ads/GoogleAds/Lib/V20/AdsAssistantHeaderMiddleware.php create mode 100644 src/Google/Ads/GoogleAds/Lib/V21/AdsAssistantHeaderMiddleware.php create mode 100644 src/Google/Ads/GoogleAds/Lib/V22/AdsAssistantHeaderMiddleware.php create mode 100644 src/Google/Ads/GoogleAds/Lib/V23/AdsAssistantHeaderMiddleware.php diff --git a/src/Google/Ads/GoogleAds/Lib/V20/AdsAssistantHeaderMiddleware.php b/src/Google/Ads/GoogleAds/Lib/V20/AdsAssistantHeaderMiddleware.php new file mode 100644 index 0000000000..60c490e161 --- /dev/null +++ b/src/Google/Ads/GoogleAds/Lib/V20/AdsAssistantHeaderMiddleware.php @@ -0,0 +1,52 @@ +nextHandler = $nextHandler; + $this->adsAssistant = $adsAssistant; + } + + public function __invoke(Call $call, array $options) + { + // Check if the agent header exists to avoid errors + if (isset($options['headers'][AgentHeader::AGENT_HEADER_KEY][0])) { + $options['headers'][AgentHeader::AGENT_HEADER_KEY][0] .= sprintf( + ' gaada/%s', + $this->adsAssistant + ); + } + + $next = $this->nextHandler; + return $next($call, $options); + } +} \ No newline at end of file diff --git a/src/Google/Ads/GoogleAds/Lib/V20/GoogleAdsGapicClientTrait.php b/src/Google/Ads/GoogleAds/Lib/V20/GoogleAdsGapicClientTrait.php index 54b21e5a6f..61367e71b9 100644 --- a/src/Google/Ads/GoogleAds/Lib/V20/GoogleAdsGapicClientTrait.php +++ b/src/Google/Ads/GoogleAds/Lib/V20/GoogleAdsGapicClientTrait.php @@ -37,8 +37,7 @@ trait GoogleAdsGapicClientTrait private static $LINKED_CUSTOMER_ID = 'linked-customer-id'; private static $UNARY_MIDDLEWARES = 'unary-middlewares'; private static $STREAMING_MIDDLEWARES = 'streaming-middlewares'; - private static $ADS_ASSISTANT_HEADER_NAME = 'google-ads-api-assistant'; - + private $developerToken = null; private $loginCustomerId = null; private $linkedCustomerId = null; @@ -79,9 +78,6 @@ protected function modifyClientOptions(array &$options) /** * Adds a FixedHeaderMiddleware to a callable. - * - * @param callable $callable the callable to add to - * @return callable the modified callable */ private function addFixedHeaderMiddleware(callable &$callable) { @@ -94,10 +90,7 @@ private function addFixedHeaderMiddleware(callable &$callable) if (!is_null($this->linkedCustomerId)) { $headers[self::$LINKED_CUSTOMER_ID] = [$this->linkedCustomerId]; } - if (!is_null($this->adsAssistant)) { - $headers[self::$ADS_ASSISTANT_HEADER_NAME] = [$this->adsAssistant]; - } - + $callable = new FixedHeaderMiddleware($callable, $headers); } return $callable; @@ -115,6 +108,11 @@ protected function modifyUnaryCallable(callable &$callable) /** @var GoogleAdsMiddlewareAbstract $unaryMiddleware */ $callable = $unaryMiddleware->withNextHandler($callable); } + + // Prepend the AdsAssistantHeaderMiddleware + if (!is_null($this->adsAssistant)) { + $callable = new AdsAssistantHeaderMiddleware($callable, $this->adsAssistant); + } } /** @@ -129,6 +127,11 @@ protected function modifyStreamingCallable(callable &$callable) /** @var GoogleAdsMiddlewareAbstract $streamingMiddleware */ $callable = $streamingMiddleware->withNextHandler($callable); } + + // Prepend the AdsAssistantHeaderMiddleware + if (!is_null($this->adsAssistant)) { + $callable = new AdsAssistantHeaderMiddleware($callable, $this->adsAssistant); + } } public function getResponseMetadata(): ?GoogleAdsResponseMetadata diff --git a/src/Google/Ads/GoogleAds/Lib/V21/AdsAssistantHeaderMiddleware.php b/src/Google/Ads/GoogleAds/Lib/V21/AdsAssistantHeaderMiddleware.php new file mode 100644 index 0000000000..764446c785 --- /dev/null +++ b/src/Google/Ads/GoogleAds/Lib/V21/AdsAssistantHeaderMiddleware.php @@ -0,0 +1,52 @@ +nextHandler = $nextHandler; + $this->adsAssistant = $adsAssistant; + } + + public function __invoke(Call $call, array $options) + { + // Check if the agent header exists to avoid errors + if (isset($options['headers'][AgentHeader::AGENT_HEADER_KEY][0])) { + $options['headers'][AgentHeader::AGENT_HEADER_KEY][0] .= sprintf( + ' gaada/%s', + $this->adsAssistant + ); + } + + $next = $this->nextHandler; + return $next($call, $options); + } +} \ No newline at end of file diff --git a/src/Google/Ads/GoogleAds/Lib/V21/GoogleAdsGapicClientTrait.php b/src/Google/Ads/GoogleAds/Lib/V21/GoogleAdsGapicClientTrait.php index 6252ac90a7..4d8d47d686 100644 --- a/src/Google/Ads/GoogleAds/Lib/V21/GoogleAdsGapicClientTrait.php +++ b/src/Google/Ads/GoogleAds/Lib/V21/GoogleAdsGapicClientTrait.php @@ -37,7 +37,6 @@ trait GoogleAdsGapicClientTrait private static $LINKED_CUSTOMER_ID = 'linked-customer-id'; private static $UNARY_MIDDLEWARES = 'unary-middlewares'; private static $STREAMING_MIDDLEWARES = 'streaming-middlewares'; - private static $ADS_ASSISTANT_HEADER_NAME = 'google-ads-api-assistant'; private $developerToken = null; private $loginCustomerId = null; @@ -79,9 +78,6 @@ protected function modifyClientOptions(array &$options) /** * Adds a FixedHeaderMiddleware to a callable. - * - * @param callable $callable the callable to add to - * @return callable the modified callable */ private function addFixedHeaderMiddleware(callable &$callable) { @@ -94,9 +90,6 @@ private function addFixedHeaderMiddleware(callable &$callable) if (!is_null($this->linkedCustomerId)) { $headers[self::$LINKED_CUSTOMER_ID] = [$this->linkedCustomerId]; } - if (!is_null($this->adsAssistant)) { - $headers[self::$ADS_ASSISTANT_HEADER_NAME] = [$this->adsAssistant]; - } $callable = new FixedHeaderMiddleware($callable, $headers); } @@ -115,6 +108,11 @@ protected function modifyUnaryCallable(callable &$callable) /** @var GoogleAdsMiddlewareAbstract $unaryMiddleware */ $callable = $unaryMiddleware->withNextHandler($callable); } + + // Prepend the AdsAssistantHeaderMiddleware + if (!is_null($this->adsAssistant)) { + $callable = new AdsAssistantHeaderMiddleware($callable, $this->adsAssistant); + } } /** @@ -129,6 +127,11 @@ protected function modifyStreamingCallable(callable &$callable) /** @var GoogleAdsMiddlewareAbstract $streamingMiddleware */ $callable = $streamingMiddleware->withNextHandler($callable); } + + // Prepend the AdsAssistantHeaderMiddleware + if (!is_null($this->adsAssistant)) { + $callable = new AdsAssistantHeaderMiddleware($callable, $this->adsAssistant); + } } public function getResponseMetadata(): ?GoogleAdsResponseMetadata diff --git a/src/Google/Ads/GoogleAds/Lib/V22/AdsAssistantHeaderMiddleware.php b/src/Google/Ads/GoogleAds/Lib/V22/AdsAssistantHeaderMiddleware.php new file mode 100644 index 0000000000..2caefad2c0 --- /dev/null +++ b/src/Google/Ads/GoogleAds/Lib/V22/AdsAssistantHeaderMiddleware.php @@ -0,0 +1,52 @@ +nextHandler = $nextHandler; + $this->adsAssistant = $adsAssistant; + } + + public function __invoke(Call $call, array $options) + { + // Check if the agent header exists to avoid errors + if (isset($options['headers'][AgentHeader::AGENT_HEADER_KEY][0])) { + $options['headers'][AgentHeader::AGENT_HEADER_KEY][0] .= sprintf( + ' gaada/%s', + $this->adsAssistant + ); + } + + $next = $this->nextHandler; + return $next($call, $options); + } +} \ No newline at end of file diff --git a/src/Google/Ads/GoogleAds/Lib/V22/GoogleAdsGapicClientTrait.php b/src/Google/Ads/GoogleAds/Lib/V22/GoogleAdsGapicClientTrait.php index a32f4dce01..774f023085 100644 --- a/src/Google/Ads/GoogleAds/Lib/V22/GoogleAdsGapicClientTrait.php +++ b/src/Google/Ads/GoogleAds/Lib/V22/GoogleAdsGapicClientTrait.php @@ -38,7 +38,6 @@ trait GoogleAdsGapicClientTrait private static $UNARY_MIDDLEWARES = 'unary-middlewares'; private static $STREAMING_MIDDLEWARES = 'streaming-middlewares'; private static $USE_CLOUD_ORG_FOR_API_ACCESS_KEY = 'use-cloud-org-for-api-access'; - private static $ADS_ASSISTANT_HEADER_NAME = 'google-ads-api-assistant'; private $developerToken = null; private $loginCustomerId = null; @@ -82,9 +81,6 @@ protected function modifyClientOptions(array &$options) /** * Adds a FixedHeaderMiddleware to a callable. - * - * @param callable $callable the callable to add to - * @return callable the modified callable */ private function addFixedHeaderMiddleware(callable &$callable) { @@ -100,9 +96,6 @@ private function addFixedHeaderMiddleware(callable &$callable) if (!is_null($this->linkedCustomerId)) { $headers[self::$LINKED_CUSTOMER_ID] = [$this->linkedCustomerId]; } - if (!is_null($this->adsAssistant)) { - $headers[self::$ADS_ASSISTANT_HEADER_NAME] = [$this->adsAssistant]; - } $callable = new FixedHeaderMiddleware($callable, $headers); } @@ -121,6 +114,11 @@ protected function modifyUnaryCallable(callable &$callable) /** @var GoogleAdsMiddlewareAbstract $unaryMiddleware */ $callable = $unaryMiddleware->withNextHandler($callable); } + + // Prepend the AdsAssistantHeaderMiddleware + if (!is_null($this->adsAssistant)) { + $callable = new AdsAssistantHeaderMiddleware($callable, $this->adsAssistant); + } } /** @@ -135,6 +133,11 @@ protected function modifyStreamingCallable(callable &$callable) /** @var GoogleAdsMiddlewareAbstract $streamingMiddleware */ $callable = $streamingMiddleware->withNextHandler($callable); } + + // Prepend the AdsAssistantHeaderMiddleware + if (!is_null($this->adsAssistant)) { + $callable = new AdsAssistantHeaderMiddleware($callable, $this->adsAssistant); + } } public function getResponseMetadata(): ?GoogleAdsResponseMetadata diff --git a/src/Google/Ads/GoogleAds/Lib/V23/AdsAssistantHeaderMiddleware.php b/src/Google/Ads/GoogleAds/Lib/V23/AdsAssistantHeaderMiddleware.php new file mode 100644 index 0000000000..b19302b9ce --- /dev/null +++ b/src/Google/Ads/GoogleAds/Lib/V23/AdsAssistantHeaderMiddleware.php @@ -0,0 +1,52 @@ +nextHandler = $nextHandler; + $this->adsAssistant = $adsAssistant; + } + + public function __invoke(Call $call, array $options) + { + // Check if the agent header exists to avoid errors + if (isset($options['headers'][AgentHeader::AGENT_HEADER_KEY][0])) { + $options['headers'][AgentHeader::AGENT_HEADER_KEY][0] .= sprintf( + ' gaada/%s', + $this->adsAssistant + ); + } + + $next = $this->nextHandler; + return $next($call, $options); + } +} \ No newline at end of file diff --git a/src/Google/Ads/GoogleAds/Lib/V23/GoogleAdsGapicClientTrait.php b/src/Google/Ads/GoogleAds/Lib/V23/GoogleAdsGapicClientTrait.php index 666cc71511..c4f0ce6e49 100644 --- a/src/Google/Ads/GoogleAds/Lib/V23/GoogleAdsGapicClientTrait.php +++ b/src/Google/Ads/GoogleAds/Lib/V23/GoogleAdsGapicClientTrait.php @@ -38,7 +38,6 @@ trait GoogleAdsGapicClientTrait private static $UNARY_MIDDLEWARES = 'unary-middlewares'; private static $STREAMING_MIDDLEWARES = 'streaming-middlewares'; private static $USE_CLOUD_ORG_FOR_API_ACCESS_KEY = 'use-cloud-org-for-api-access'; - private static $ADS_ASSISTANT_HEADER_NAME = 'google-ads-api-assistant'; private $developerToken = null; private $loginCustomerId = null; @@ -82,9 +81,6 @@ protected function modifyClientOptions(array &$options) /** * Adds a FixedHeaderMiddleware to a callable. - * - * @param callable $callable the callable to add to - * @return callable the modified callable */ private function addFixedHeaderMiddleware(callable &$callable) { @@ -100,9 +96,7 @@ private function addFixedHeaderMiddleware(callable &$callable) if (!is_null($this->linkedCustomerId)) { $headers[self::$LINKED_CUSTOMER_ID] = [$this->linkedCustomerId]; } - if (!is_null($this->adsAssistant)) { - $headers[self::$ADS_ASSISTANT_HEADER_NAME] = [$this->adsAssistant]; - } + $callable = new FixedHeaderMiddleware($callable, $headers); } return $callable; @@ -120,6 +114,11 @@ protected function modifyUnaryCallable(callable &$callable) /** @var GoogleAdsMiddlewareAbstract $unaryMiddleware */ $callable = $unaryMiddleware->withNextHandler($callable); } + + // Prepend the AdsAssistantHeaderMiddleware + if (!is_null($this->adsAssistant)) { + $callable = new AdsAssistantHeaderMiddleware($callable, $this->adsAssistant); + } } /** @@ -134,6 +133,11 @@ protected function modifyStreamingCallable(callable &$callable) /** @var GoogleAdsMiddlewareAbstract $streamingMiddleware */ $callable = $streamingMiddleware->withNextHandler($callable); } + + // Prepend the AdsAssistantHeaderMiddleware + if (!is_null($this->adsAssistant)) { + $callable = new AdsAssistantHeaderMiddleware($callable, $this->adsAssistant); + } } public function getResponseMetadata(): ?GoogleAdsResponseMetadata From 798296196c3ae86bccd2d8cc6e4b1641b6dab834 Mon Sep 17 00:00:00 2001 From: Aalap Shastri Date: Mon, 20 Apr 2026 18:41:57 +0000 Subject: [PATCH 2/3] add tests and older header logic Change-Id: I8a732385a29484892b982d914219e9080c040947 --- .../Lib/V20/AdsAssistantHeaderMiddleware.php | 2 +- .../Lib/V20/GoogleAdsGapicClientTrait.php | 5 +- .../Lib/V21/AdsAssistantHeaderMiddleware.php | 2 +- .../Lib/V21/GoogleAdsGapicClientTrait.php | 3 ++ .../Lib/V22/AdsAssistantHeaderMiddleware.php | 2 +- .../Lib/V22/GoogleAdsGapicClientTrait.php | 3 ++ .../Lib/V23/AdsAssistantHeaderMiddleware.php | 2 +- .../Lib/V23/GoogleAdsGapicClientTrait.php | 3 ++ .../V20/AdsAssistantHeaderMiddlewareTest.php | 48 +++++++++++++++++++ .../Lib/V20/GoogleAdsClientBuilderTest.php | 15 ++++++ .../V21/AdsAssistantHeaderMiddlewareTest.php | 48 +++++++++++++++++++ .../Lib/V21/GoogleAdsClientBuilderTest.php | 15 ++++++ .../V22/AdsAssistantHeaderMiddlewareTest.php | 48 +++++++++++++++++++ .../Lib/V22/GoogleAdsClientBuilderTest.php | 15 ++++++ .../V23/AdsAssistantHeaderMiddlewareTest.php | 48 +++++++++++++++++++ .../Lib/V23/GoogleAdsClientBuilderTest.php | 15 ++++++ 16 files changed, 269 insertions(+), 5 deletions(-) create mode 100644 tests/Google/Ads/GoogleAds/Lib/V20/AdsAssistantHeaderMiddlewareTest.php create mode 100644 tests/Google/Ads/GoogleAds/Lib/V21/AdsAssistantHeaderMiddlewareTest.php create mode 100644 tests/Google/Ads/GoogleAds/Lib/V22/AdsAssistantHeaderMiddlewareTest.php create mode 100644 tests/Google/Ads/GoogleAds/Lib/V23/AdsAssistantHeaderMiddlewareTest.php diff --git a/src/Google/Ads/GoogleAds/Lib/V20/AdsAssistantHeaderMiddleware.php b/src/Google/Ads/GoogleAds/Lib/V20/AdsAssistantHeaderMiddleware.php index 60c490e161..5b3b426003 100644 --- a/src/Google/Ads/GoogleAds/Lib/V20/AdsAssistantHeaderMiddleware.php +++ b/src/Google/Ads/GoogleAds/Lib/V20/AdsAssistantHeaderMiddleware.php @@ -1,7 +1,7 @@ linkedCustomerId)) { $headers[self::$LINKED_CUSTOMER_ID] = [$this->linkedCustomerId]; } - + if (!is_null($this->adsAssistant)) { + $headers[self::$ADS_ASSISTANT_HEADER_NAME] = [$this->adsAssistant]; + } + $callable = new FixedHeaderMiddleware($callable, $headers); } return $callable; diff --git a/src/Google/Ads/GoogleAds/Lib/V21/AdsAssistantHeaderMiddleware.php b/src/Google/Ads/GoogleAds/Lib/V21/AdsAssistantHeaderMiddleware.php index 764446c785..3a00c685d4 100644 --- a/src/Google/Ads/GoogleAds/Lib/V21/AdsAssistantHeaderMiddleware.php +++ b/src/Google/Ads/GoogleAds/Lib/V21/AdsAssistantHeaderMiddleware.php @@ -1,7 +1,7 @@ linkedCustomerId)) { $headers[self::$LINKED_CUSTOMER_ID] = [$this->linkedCustomerId]; } + if (!is_null($this->adsAssistant)) { + $headers[self::$ADS_ASSISTANT_HEADER_NAME] = [$this->adsAssistant]; + } $callable = new FixedHeaderMiddleware($callable, $headers); } diff --git a/src/Google/Ads/GoogleAds/Lib/V22/AdsAssistantHeaderMiddleware.php b/src/Google/Ads/GoogleAds/Lib/V22/AdsAssistantHeaderMiddleware.php index 2caefad2c0..ff9f3bdc7b 100644 --- a/src/Google/Ads/GoogleAds/Lib/V22/AdsAssistantHeaderMiddleware.php +++ b/src/Google/Ads/GoogleAds/Lib/V22/AdsAssistantHeaderMiddleware.php @@ -1,7 +1,7 @@ linkedCustomerId)) { $headers[self::$LINKED_CUSTOMER_ID] = [$this->linkedCustomerId]; } + if (!is_null($this->adsAssistant)) { + $headers[self::$ADS_ASSISTANT_HEADER_NAME] = [$this->adsAssistant]; + } $callable = new FixedHeaderMiddleware($callable, $headers); } diff --git a/src/Google/Ads/GoogleAds/Lib/V23/AdsAssistantHeaderMiddleware.php b/src/Google/Ads/GoogleAds/Lib/V23/AdsAssistantHeaderMiddleware.php index b19302b9ce..e16b4affac 100644 --- a/src/Google/Ads/GoogleAds/Lib/V23/AdsAssistantHeaderMiddleware.php +++ b/src/Google/Ads/GoogleAds/Lib/V23/AdsAssistantHeaderMiddleware.php @@ -1,7 +1,7 @@ linkedCustomerId)) { $headers[self::$LINKED_CUSTOMER_ID] = [$this->linkedCustomerId]; } + if (!is_null($this->adsAssistant)) { + $headers[self::$ADS_ASSISTANT_HEADER_NAME] = [$this->adsAssistant]; + } $callable = new FixedHeaderMiddleware($callable, $headers); } diff --git a/tests/Google/Ads/GoogleAds/Lib/V20/AdsAssistantHeaderMiddlewareTest.php b/tests/Google/Ads/GoogleAds/Lib/V20/AdsAssistantHeaderMiddlewareTest.php new file mode 100644 index 0000000000..f176d59424 --- /dev/null +++ b/tests/Google/Ads/GoogleAds/Lib/V20/AdsAssistantHeaderMiddlewareTest.php @@ -0,0 +1,48 @@ +createMock(Call::class); + $options = [ + 'headers' => [ + AgentHeader::AGENT_HEADER_KEY => [$initialHeader] + ] + ]; + + // 4. Run it + $result = $middleware($call, $options); + + // 5. Assertions + $this->assertTrue($nextHandlerCalled, 'The next handler was not called.'); + $this->assertEquals("final-result", $result); + + $actualHeader = $capturedOptions['headers'][AgentHeader::AGENT_HEADER_KEY][0]; + $this->assertEquals($expectedHeader, $actualHeader); + $this->assertStringContainsString('gaada/test-assistant-123', $actualHeader); + } +} \ No newline at end of file diff --git a/tests/Google/Ads/GoogleAds/Lib/V20/GoogleAdsClientBuilderTest.php b/tests/Google/Ads/GoogleAds/Lib/V20/GoogleAdsClientBuilderTest.php index 95dedde7ff..c42004d1dc 100644 --- a/tests/Google/Ads/GoogleAds/Lib/V20/GoogleAdsClientBuilderTest.php +++ b/tests/Google/Ads/GoogleAds/Lib/V20/GoogleAdsClientBuilderTest.php @@ -674,4 +674,19 @@ public function testBuildWithAdsAssistant() $googleAdsClient->getAdsAssistant() ); } + + public function testBuildWithAdsAssistantSetsOption() + { + $adsAssistant = 'my-assistant'; + $builder = new GoogleAdsClientBuilder(); + + // Set minimal requirements to build + $builder->withDeveloperToken('token') + ->withAdsAssistant($adsAssistant); + + // We can't easily test the private trait properties, but we can verify + // that the builder's configuration includes the key. + $config = $builder->buildConfiguration(); + $this->assertEquals($adsAssistant, $config['ads_assistant']); + } } diff --git a/tests/Google/Ads/GoogleAds/Lib/V21/AdsAssistantHeaderMiddlewareTest.php b/tests/Google/Ads/GoogleAds/Lib/V21/AdsAssistantHeaderMiddlewareTest.php new file mode 100644 index 0000000000..f176d59424 --- /dev/null +++ b/tests/Google/Ads/GoogleAds/Lib/V21/AdsAssistantHeaderMiddlewareTest.php @@ -0,0 +1,48 @@ +createMock(Call::class); + $options = [ + 'headers' => [ + AgentHeader::AGENT_HEADER_KEY => [$initialHeader] + ] + ]; + + // 4. Run it + $result = $middleware($call, $options); + + // 5. Assertions + $this->assertTrue($nextHandlerCalled, 'The next handler was not called.'); + $this->assertEquals("final-result", $result); + + $actualHeader = $capturedOptions['headers'][AgentHeader::AGENT_HEADER_KEY][0]; + $this->assertEquals($expectedHeader, $actualHeader); + $this->assertStringContainsString('gaada/test-assistant-123', $actualHeader); + } +} \ No newline at end of file diff --git a/tests/Google/Ads/GoogleAds/Lib/V21/GoogleAdsClientBuilderTest.php b/tests/Google/Ads/GoogleAds/Lib/V21/GoogleAdsClientBuilderTest.php index 1c6fa74bbd..2c9e59c1ee 100644 --- a/tests/Google/Ads/GoogleAds/Lib/V21/GoogleAdsClientBuilderTest.php +++ b/tests/Google/Ads/GoogleAds/Lib/V21/GoogleAdsClientBuilderTest.php @@ -674,4 +674,19 @@ public function testBuildWithAdsAssistant() $googleAdsClient->getAdsAssistant() ); } + + public function testBuildWithAdsAssistantSetsOption() + { + $adsAssistant = 'my-assistant'; + $builder = new GoogleAdsClientBuilder(); + + // Set minimal requirements to build + $builder->withDeveloperToken('token') + ->withAdsAssistant($adsAssistant); + + // We can't easily test the private trait properties, but we can verify + // that the builder's configuration includes the key. + $config = $builder->buildConfiguration(); + $this->assertEquals($adsAssistant, $config['ads_assistant']); + } } diff --git a/tests/Google/Ads/GoogleAds/Lib/V22/AdsAssistantHeaderMiddlewareTest.php b/tests/Google/Ads/GoogleAds/Lib/V22/AdsAssistantHeaderMiddlewareTest.php new file mode 100644 index 0000000000..f176d59424 --- /dev/null +++ b/tests/Google/Ads/GoogleAds/Lib/V22/AdsAssistantHeaderMiddlewareTest.php @@ -0,0 +1,48 @@ +createMock(Call::class); + $options = [ + 'headers' => [ + AgentHeader::AGENT_HEADER_KEY => [$initialHeader] + ] + ]; + + // 4. Run it + $result = $middleware($call, $options); + + // 5. Assertions + $this->assertTrue($nextHandlerCalled, 'The next handler was not called.'); + $this->assertEquals("final-result", $result); + + $actualHeader = $capturedOptions['headers'][AgentHeader::AGENT_HEADER_KEY][0]; + $this->assertEquals($expectedHeader, $actualHeader); + $this->assertStringContainsString('gaada/test-assistant-123', $actualHeader); + } +} \ No newline at end of file diff --git a/tests/Google/Ads/GoogleAds/Lib/V22/GoogleAdsClientBuilderTest.php b/tests/Google/Ads/GoogleAds/Lib/V22/GoogleAdsClientBuilderTest.php index bec2ca6451..2a1579e6f4 100644 --- a/tests/Google/Ads/GoogleAds/Lib/V22/GoogleAdsClientBuilderTest.php +++ b/tests/Google/Ads/GoogleAds/Lib/V22/GoogleAdsClientBuilderTest.php @@ -674,4 +674,19 @@ public function testBuildWithAdsAssistant() $googleAdsClient->getAdsAssistant() ); } + + public function testBuildWithAdsAssistantSetsOption() + { + $adsAssistant = 'my-assistant'; + $builder = new GoogleAdsClientBuilder(); + + // Set minimal requirements to build + $builder->withDeveloperToken('token') + ->withAdsAssistant($adsAssistant); + + // We can't easily test the private trait properties, but we can verify + // that the builder's configuration includes the key. + $config = $builder->buildConfiguration(); + $this->assertEquals($adsAssistant, $config['ads_assistant']); + } } diff --git a/tests/Google/Ads/GoogleAds/Lib/V23/AdsAssistantHeaderMiddlewareTest.php b/tests/Google/Ads/GoogleAds/Lib/V23/AdsAssistantHeaderMiddlewareTest.php new file mode 100644 index 0000000000..f176d59424 --- /dev/null +++ b/tests/Google/Ads/GoogleAds/Lib/V23/AdsAssistantHeaderMiddlewareTest.php @@ -0,0 +1,48 @@ +createMock(Call::class); + $options = [ + 'headers' => [ + AgentHeader::AGENT_HEADER_KEY => [$initialHeader] + ] + ]; + + // 4. Run it + $result = $middleware($call, $options); + + // 5. Assertions + $this->assertTrue($nextHandlerCalled, 'The next handler was not called.'); + $this->assertEquals("final-result", $result); + + $actualHeader = $capturedOptions['headers'][AgentHeader::AGENT_HEADER_KEY][0]; + $this->assertEquals($expectedHeader, $actualHeader); + $this->assertStringContainsString('gaada/test-assistant-123', $actualHeader); + } +} \ No newline at end of file diff --git a/tests/Google/Ads/GoogleAds/Lib/V23/GoogleAdsClientBuilderTest.php b/tests/Google/Ads/GoogleAds/Lib/V23/GoogleAdsClientBuilderTest.php index 7fd8b85758..3527307b7d 100644 --- a/tests/Google/Ads/GoogleAds/Lib/V23/GoogleAdsClientBuilderTest.php +++ b/tests/Google/Ads/GoogleAds/Lib/V23/GoogleAdsClientBuilderTest.php @@ -674,4 +674,19 @@ public function testBuildWithAdsAssistant() $googleAdsClient->getAdsAssistant() ); } + + public function testBuildWithAdsAssistantSetsOption() + { + $adsAssistant = 'my-assistant'; + $builder = new GoogleAdsClientBuilder(); + + // Set minimal requirements to build + $builder->withDeveloperToken('token') + ->withAdsAssistant($adsAssistant); + + // We can't easily test the private trait properties, but we can verify + // that the builder's configuration includes the key. + $config = $builder->buildConfiguration(); + $this->assertEquals($adsAssistant, $config['ads_assistant']); + } } From bb2b0f39fc84846a0827163429a4656eab56a165 Mon Sep 17 00:00:00 2001 From: Aalap Shastri Date: Thu, 14 May 2026 20:12:11 +0000 Subject: [PATCH 3/3] add property back in Change-Id: I4953801db515a20ca681cf08be23f5234a121eff --- .../Lib/V20/GoogleAdsGapicClientTrait.php | 1 + .../Lib/V21/GoogleAdsGapicClientTrait.php | 1 + .../Lib/V22/GoogleAdsGapicClientTrait.php | 1 + .../Lib/V23/GoogleAdsGapicClientTrait.php | 1 + .../Lib/V20/GoogleAdsClientBuilderTest.php | 15 --------------- .../Lib/V21/GoogleAdsClientBuilderTest.php | 15 --------------- .../Lib/V22/GoogleAdsClientBuilderTest.php | 15 --------------- .../Lib/V23/GoogleAdsClientBuilderTest.php | 15 --------------- 8 files changed, 4 insertions(+), 60 deletions(-) diff --git a/src/Google/Ads/GoogleAds/Lib/V20/GoogleAdsGapicClientTrait.php b/src/Google/Ads/GoogleAds/Lib/V20/GoogleAdsGapicClientTrait.php index 6f370cbd75..f1d2ea0a08 100644 --- a/src/Google/Ads/GoogleAds/Lib/V20/GoogleAdsGapicClientTrait.php +++ b/src/Google/Ads/GoogleAds/Lib/V20/GoogleAdsGapicClientTrait.php @@ -37,6 +37,7 @@ trait GoogleAdsGapicClientTrait private static $LINKED_CUSTOMER_ID = 'linked-customer-id'; private static $UNARY_MIDDLEWARES = 'unary-middlewares'; private static $STREAMING_MIDDLEWARES = 'streaming-middlewares'; + private static $ADS_ASSISTANT_HEADER_NAME = 'google-ads-api-assistant'; private $developerToken = null; private $loginCustomerId = null; diff --git a/src/Google/Ads/GoogleAds/Lib/V21/GoogleAdsGapicClientTrait.php b/src/Google/Ads/GoogleAds/Lib/V21/GoogleAdsGapicClientTrait.php index a1f1e37a91..53e27faf17 100644 --- a/src/Google/Ads/GoogleAds/Lib/V21/GoogleAdsGapicClientTrait.php +++ b/src/Google/Ads/GoogleAds/Lib/V21/GoogleAdsGapicClientTrait.php @@ -37,6 +37,7 @@ trait GoogleAdsGapicClientTrait private static $LINKED_CUSTOMER_ID = 'linked-customer-id'; private static $UNARY_MIDDLEWARES = 'unary-middlewares'; private static $STREAMING_MIDDLEWARES = 'streaming-middlewares'; + private static $ADS_ASSISTANT_HEADER_NAME = 'google-ads-api-assistant'; private $developerToken = null; private $loginCustomerId = null; diff --git a/src/Google/Ads/GoogleAds/Lib/V22/GoogleAdsGapicClientTrait.php b/src/Google/Ads/GoogleAds/Lib/V22/GoogleAdsGapicClientTrait.php index dd204a1b98..439f5e20c6 100644 --- a/src/Google/Ads/GoogleAds/Lib/V22/GoogleAdsGapicClientTrait.php +++ b/src/Google/Ads/GoogleAds/Lib/V22/GoogleAdsGapicClientTrait.php @@ -38,6 +38,7 @@ trait GoogleAdsGapicClientTrait private static $UNARY_MIDDLEWARES = 'unary-middlewares'; private static $STREAMING_MIDDLEWARES = 'streaming-middlewares'; private static $USE_CLOUD_ORG_FOR_API_ACCESS_KEY = 'use-cloud-org-for-api-access'; + private static $ADS_ASSISTANT_HEADER_NAME = 'google-ads-api-assistant'; private $developerToken = null; private $loginCustomerId = null; diff --git a/src/Google/Ads/GoogleAds/Lib/V23/GoogleAdsGapicClientTrait.php b/src/Google/Ads/GoogleAds/Lib/V23/GoogleAdsGapicClientTrait.php index 3dee7b36f9..cdfbcd11eb 100644 --- a/src/Google/Ads/GoogleAds/Lib/V23/GoogleAdsGapicClientTrait.php +++ b/src/Google/Ads/GoogleAds/Lib/V23/GoogleAdsGapicClientTrait.php @@ -38,6 +38,7 @@ trait GoogleAdsGapicClientTrait private static $UNARY_MIDDLEWARES = 'unary-middlewares'; private static $STREAMING_MIDDLEWARES = 'streaming-middlewares'; private static $USE_CLOUD_ORG_FOR_API_ACCESS_KEY = 'use-cloud-org-for-api-access'; + private static $ADS_ASSISTANT_HEADER_NAME = 'google-ads-api-assistant'; private $developerToken = null; private $loginCustomerId = null; diff --git a/tests/Google/Ads/GoogleAds/Lib/V20/GoogleAdsClientBuilderTest.php b/tests/Google/Ads/GoogleAds/Lib/V20/GoogleAdsClientBuilderTest.php index c42004d1dc..95dedde7ff 100644 --- a/tests/Google/Ads/GoogleAds/Lib/V20/GoogleAdsClientBuilderTest.php +++ b/tests/Google/Ads/GoogleAds/Lib/V20/GoogleAdsClientBuilderTest.php @@ -674,19 +674,4 @@ public function testBuildWithAdsAssistant() $googleAdsClient->getAdsAssistant() ); } - - public function testBuildWithAdsAssistantSetsOption() - { - $adsAssistant = 'my-assistant'; - $builder = new GoogleAdsClientBuilder(); - - // Set minimal requirements to build - $builder->withDeveloperToken('token') - ->withAdsAssistant($adsAssistant); - - // We can't easily test the private trait properties, but we can verify - // that the builder's configuration includes the key. - $config = $builder->buildConfiguration(); - $this->assertEquals($adsAssistant, $config['ads_assistant']); - } } diff --git a/tests/Google/Ads/GoogleAds/Lib/V21/GoogleAdsClientBuilderTest.php b/tests/Google/Ads/GoogleAds/Lib/V21/GoogleAdsClientBuilderTest.php index 2c9e59c1ee..1c6fa74bbd 100644 --- a/tests/Google/Ads/GoogleAds/Lib/V21/GoogleAdsClientBuilderTest.php +++ b/tests/Google/Ads/GoogleAds/Lib/V21/GoogleAdsClientBuilderTest.php @@ -674,19 +674,4 @@ public function testBuildWithAdsAssistant() $googleAdsClient->getAdsAssistant() ); } - - public function testBuildWithAdsAssistantSetsOption() - { - $adsAssistant = 'my-assistant'; - $builder = new GoogleAdsClientBuilder(); - - // Set minimal requirements to build - $builder->withDeveloperToken('token') - ->withAdsAssistant($adsAssistant); - - // We can't easily test the private trait properties, but we can verify - // that the builder's configuration includes the key. - $config = $builder->buildConfiguration(); - $this->assertEquals($adsAssistant, $config['ads_assistant']); - } } diff --git a/tests/Google/Ads/GoogleAds/Lib/V22/GoogleAdsClientBuilderTest.php b/tests/Google/Ads/GoogleAds/Lib/V22/GoogleAdsClientBuilderTest.php index 2a1579e6f4..bec2ca6451 100644 --- a/tests/Google/Ads/GoogleAds/Lib/V22/GoogleAdsClientBuilderTest.php +++ b/tests/Google/Ads/GoogleAds/Lib/V22/GoogleAdsClientBuilderTest.php @@ -674,19 +674,4 @@ public function testBuildWithAdsAssistant() $googleAdsClient->getAdsAssistant() ); } - - public function testBuildWithAdsAssistantSetsOption() - { - $adsAssistant = 'my-assistant'; - $builder = new GoogleAdsClientBuilder(); - - // Set minimal requirements to build - $builder->withDeveloperToken('token') - ->withAdsAssistant($adsAssistant); - - // We can't easily test the private trait properties, but we can verify - // that the builder's configuration includes the key. - $config = $builder->buildConfiguration(); - $this->assertEquals($adsAssistant, $config['ads_assistant']); - } } diff --git a/tests/Google/Ads/GoogleAds/Lib/V23/GoogleAdsClientBuilderTest.php b/tests/Google/Ads/GoogleAds/Lib/V23/GoogleAdsClientBuilderTest.php index 3527307b7d..7fd8b85758 100644 --- a/tests/Google/Ads/GoogleAds/Lib/V23/GoogleAdsClientBuilderTest.php +++ b/tests/Google/Ads/GoogleAds/Lib/V23/GoogleAdsClientBuilderTest.php @@ -674,19 +674,4 @@ public function testBuildWithAdsAssistant() $googleAdsClient->getAdsAssistant() ); } - - public function testBuildWithAdsAssistantSetsOption() - { - $adsAssistant = 'my-assistant'; - $builder = new GoogleAdsClientBuilder(); - - // Set minimal requirements to build - $builder->withDeveloperToken('token') - ->withAdsAssistant($adsAssistant); - - // We can't easily test the private trait properties, but we can verify - // that the builder's configuration includes the key. - $config = $builder->buildConfiguration(); - $this->assertEquals($adsAssistant, $config['ads_assistant']); - } }