Skip to content

Commit ee1f9b0

Browse files
committed
Merge branch 'develop' into release/3.9.0
2 parents a167b94 + aa2fc87 commit ee1f9b0

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/API/Google/AdsCampaign.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ public function __construct( GoogleAdsClient $client, AdsCampaignBudget $budget,
133133
* @throws ExceptionWithResponseData When an ApiException is caught.
134134
*/
135135
public function get_campaigns( bool $exclude_removed = true, bool $fetch_criterion = true, array $args = [] ): array {
136+
// No Ads account connected means no campaigns; AdsCampaignQuery::set_client() requires
137+
// a non-zero Ads ID and throws InvalidProperty otherwise, which callers don't expect
138+
// from this method (its documented @throws is ExceptionWithResponseData).
139+
if ( ! $this->options->get_ads_id() ) {
140+
return [];
141+
}
142+
136143
try {
137144
$query = ( new AdsCampaignQuery() )->set_client( $this->client, $this->options->get_ads_id() );
138145

tests/Unit/API/Google/AdsCampaignTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ public function test_get_campaigns_empty_list() {
107107
$this->assertEquals( [], $this->campaign->get_campaigns() );
108108
}
109109

110+
public function test_get_campaigns_no_ads_id_returns_empty_list_without_throwing() {
111+
$this->options = $this->createMock( OptionsInterface::class );
112+
$this->options->method( 'get_ads_id' )->willReturn( 0 );
113+
$this->campaign->set_options_object( $this->options );
114+
115+
$this->assertEquals( [], $this->campaign->get_campaigns() );
116+
}
117+
110118
public function test_get_campaigns() {
111119
$campaign_criterion_data = [
112120
[

0 commit comments

Comments
 (0)