Skip to content

Commit 5b996e7

Browse files
committed
fix: update tests to meet new requirements
1 parent 6d2f319 commit 5b996e7

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

test/Unit/AnalyticsTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use AlexWestergaard\PhpGa4\Facade;
77
use AlexWestergaard\PhpGa4\Event;
88
use AlexWestergaard\PhpGa4\Analytics;
9+
use AlexWestergaard\PhpGa4\Event\Login;
910
use AlexWestergaard\PhpGa4Test\TestCase;
1011

1112
final class AnalyticsTest extends TestCase
@@ -17,7 +18,6 @@ public function test_can_configure_and_export()
1718
$this->prefill['api_secret'],
1819
$debug = true
1920
)
20-
->setNonPersonalizedAds($nonPersonalisedAds = true)
2121
->setClientId($this->prefill['client_id'])
2222
->setUserId($this->prefill['user_id'])
2323
->setTimestampMicros($time = time())
@@ -27,7 +27,6 @@ public function test_can_configure_and_export()
2727
$asArray = $analytics->toArray();
2828
$this->assertIsArray($asArray);
2929

30-
$this->assertArrayHasKey('non_personalized_ads', $asArray);
3130
$this->assertArrayHasKey('timestamp_micros', $asArray);
3231
$this->assertArrayHasKey('client_id', $asArray);
3332
$this->assertArrayHasKey('user_id', $asArray);
@@ -36,7 +35,6 @@ public function test_can_configure_and_export()
3635

3736
$timeAsMicro = $time * 1_000_000;
3837

39-
$this->assertEquals($nonPersonalisedAds, $asArray['non_personalized_ads']);
4038
$this->assertEquals($timeAsMicro, $asArray['timestamp_micros']);
4139
$this->assertEquals($this->prefill['client_id'], $asArray['client_id']);
4240
$this->assertEquals($this->prefill['user_id'], $asArray['user_id']);
@@ -46,7 +44,7 @@ public function test_can_configure_and_export()
4644

4745
public function test_can_post_to_google()
4846
{
49-
$this->assertNull($this->analytics->post());
47+
$this->assertNull($this->analytics->addEvent(Login::new())->post());
5048
}
5149

5250
public function test_converts_to_full_microtime_stamp()
@@ -68,6 +66,8 @@ public function test_throws_if_microtime_older_than_three_days()
6866

6967
public function test_exports_userproperty_to_array()
7068
{
69+
$this->analytics->addEvent(Login::new());
70+
7171
$userProperty = UserProperty::new()
7272
->setName('customer_tier')
7373
->setValue('premium');
@@ -138,7 +138,7 @@ public function test_throws_on_too_large_request_package()
138138
$userProperty->setValue($overflowValue);
139139
}
140140

141-
$this->analytics->addUserProperty($userProperty)->post();
141+
$this->analytics->addEvent(Login::new())->addUserProperty($userProperty)->post();
142142
}
143143

144144
public function test_timeasmicro_throws_exceeding_max()

test/Unit/ConsentTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,25 @@
22

33
namespace AlexWestergaard\PhpGa4Test\Unit;
44

5+
use AlexWestergaard\PhpGa4\Event\Login;
56
use AlexWestergaard\PhpGa4\Helper\ConsentHelper;
67
use AlexWestergaard\PhpGa4Test\TestCase;
78

89
final class ConsentTest extends TestCase
910
{
1011
public function test_no_consent_is_empty()
1112
{
13+
$this->analytics->addEvent(Login::new());
14+
1215
$export = $this->analytics->consent()->toArray();
1316
$this->assertIsArray($export);
1417
$this->assertCount(0, $export);
1518
}
1619

1720
public function test_consent_ad_user_data_granted()
1821
{
22+
$this->analytics->addEvent(Login::new());
23+
1924
$this->analytics->consent()->setAdUserDataPermission(true);
2025

2126
$export = $this->analytics->consent()->toArray();
@@ -28,6 +33,8 @@ public function test_consent_ad_user_data_granted()
2833

2934
public function test_consent_ad_personalization_granted()
3035
{
36+
$this->analytics->addEvent(Login::new());
37+
3138
$this->analytics->consent()->setAdPersonalizationPermission(true);
3239

3340
$export = $this->analytics->consent()->toArray();
@@ -40,6 +47,8 @@ public function test_consent_ad_personalization_granted()
4047

4148
public function test_consent_granted()
4249
{
50+
$this->analytics->addEvent(Login::new());
51+
4352
$this->analytics->consent()->setAdUserDataPermission(true);
4453
$this->analytics->consent()->setAdPersonalizationPermission(true);
4554

@@ -54,6 +63,8 @@ public function test_consent_granted()
5463

5564
public function test_consent_granted_posted()
5665
{
66+
$this->analytics->addEvent(Login::new());
67+
5768
$this->analytics->consent()->setAdUserDataPermission(true);
5869
$this->analytics->consent()->setAdPersonalizationPermission(true);
5970

@@ -69,6 +80,8 @@ public function test_consent_granted_posted()
6980

7081
public function test_consent_ad_user_data_denied()
7182
{
83+
$this->analytics->addEvent(Login::new());
84+
7285
$this->analytics->consent()->setAdUserDataPermission(false);
7386

7487
$export = $this->analytics->consent()->toArray();
@@ -81,6 +94,8 @@ public function test_consent_ad_user_data_denied()
8194

8295
public function test_consent_ad_personalization_denied()
8396
{
97+
$this->analytics->addEvent(Login::new());
98+
8499
$this->analytics->consent()->setAdPersonalizationPermission(false);
85100

86101
$export = $this->analytics->consent()->toArray();
@@ -93,6 +108,8 @@ public function test_consent_ad_personalization_denied()
93108

94109
public function test_consent_denied()
95110
{
111+
$this->analytics->addEvent(Login::new());
112+
96113
$this->analytics->consent()->setAdUserDataPermission(false);
97114
$this->analytics->consent()->setAdPersonalizationPermission(false);
98115

@@ -107,6 +124,8 @@ public function test_consent_denied()
107124

108125
public function test_consent_denied_posted()
109126
{
127+
$this->analytics->addEvent(Login::new());
128+
110129
$this->analytics->consent()->setAdUserDataPermission(false);
111130
$this->analytics->consent()->setAdPersonalizationPermission(false);
112131

0 commit comments

Comments
 (0)