Skip to content

Commit 7860d05

Browse files
authored
Improve tests and coverage (#38)
- Adds more tests for better coverage - Gets rid of legacy tests of analytics - Removes composer from dependabot checks - Minor fixes of models found from new tests
2 parents 1d1479b + 70e16f3 commit 7860d05

22 files changed

+507
-509
lines changed

.github/dependabot.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,3 @@ updates:
99
day: "monday"
1010
assignees:
1111
- "octocat"
12-
13-
# Maintain dependencies for Composer
14-
- package-ecosystem: "composer"
15-
directory: "/"
16-
schedule:
17-
interval: "monthly"
18-
day: "monday"
19-
assignees:
20-
- "octocat"

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Contribute
22

3-
Thank you for being interesting in this package and wanting to contribute to it.
3+
Thank you for being interested in this package and wanting to contribute to it.
44

55
## Coding
66

77
New code should be introduced to the codebase through issues that specify what you are trying to accomplish.
88
I understand that sometimes you need to add/update/delete code otherwhere in the codebase to achieve this goal.
99
This is why my test always merges master in to ensure that your code stays functional/executable during development.
1010

11-
Please adhere these pointers:
11+
**Please adhere these pointers:**
1212
* Support selected PHP Versions | Ref: [Master/Composer.json](https://github.com/AlexWestergaard/php-ga4/blob/master/composer.json)
1313
* Pass current tests without modification; unless clearly explaining why the change is necessary/required | `> vendor/bin/phpunit`
1414
* PHPUnit tests should confidently ensure that code doesn't fail/error in unwated ways (eg. E_WARNINGS or missing paranthesis)

phpunit.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
</include>
1818
<exclude>
1919
<directory suffix=".php">./src/Facade</directory>
20+
<file>./src/GA4Exception.php</file>
2021
</exclude>
2122
<report>
22-
<text outputFile="./.phpunit/coverage.txt" showUncoveredFiles="true"
23-
showOnlySummary="false" />
23+
<text outputFile="./.phpunit/coverage.txt" showUncoveredFiles="true" showOnlySummary="false" />
2424
</report>
2525
</coverage>
2626
<php>

src/Analytics.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ public function setTimestampMicros(int|float $microOrUnix)
7676
$secondInMicro = 1_000_000;
7777
$offsetLimit = (strtotime('-3 days') + 90) * $secondInMicro;
7878

79-
if (!is_numeric($microOrUnix)) {
80-
throw Ga4Exception::throwMicrotimeInvalidFormat();
81-
}
82-
8379
$formattedTime = floor($microOrUnix * $secondInMicro);
8480
if ($formattedTime < $offsetLimit) {
8581
throw Ga4Exception::throwMicrotimeExpired();
@@ -162,10 +158,10 @@ public function post(): void
162158
}
163159
}
164160
}
161+
}
165162

166-
if (Ga4Exception::hasThrowStack()) {
167-
throw Ga4Exception::getThrowStack();
168-
}
163+
if (Ga4Exception::hasThrowStack()) {
164+
throw Ga4Exception::getThrowStack();
169165
}
170166
}
171167

src/Exception/Ga4Exception.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ public static function throwMissingApiSecret()
4242
return new static("Timestamp must be numeric", static::REQUEST_MISSING_API_SECRET);
4343
}
4444

45-
public static function throwMicrotimeInvalidFormat()
46-
{
47-
return new static("Timestamp must be numeric", static::MICROTIME_INVALID_FORMAT);
48-
}
49-
5045
public static function throwMicrotimeExpired()
5146
{
5247
return new static("Timestamp is too old, max 3 days", static::MICROTIME_EXPIRED);

src/Exception/Ga4ItemException.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/Exception/Ga4UserPropertyException.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ public static function throwNameTooLong($name)
1313
{
1414
return new static("Name is too long, max is 24: $name", static::PARAM_TOO_LONG);
1515
}
16+
17+
public static function throwNameMissing()
18+
{
19+
return new static("Name is missing", static::PARAM_MISSING);
20+
}
1621
}

src/Facade/Type/Ga4Exception.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ interface Ga4Exception
1010
const PARAM_MISSING_REQUIRED = 102001;
1111
const PARAM_RESERVED = 102002;
1212
const PARAM_TOO_LONG = 102003;
13+
const PARAM_MISSING = 102004;
1314

1415
const EVENT_NAME_RESERVED = 103001;
1516
const EVENT_NAME_MISSING = 103002;

src/GA4Exception.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
namespace AlexWestergaard\PhpGa4;
44

5+
use AlexWestergaard\PhpGa4\Exception\Ga4Exception as ExceptionGa4Exception;
6+
57
/** @deprecated 1.1.1 */
68
class GA4Exception extends \Exception
79
{
10+
public function __construct(string $message = "", int $code = 0, \Throwable|null $previous = null)
11+
{
12+
$new = new ExceptionGa4Exception($message, $code);
13+
parent::__construct("This exception is deprecated, check previous for your exception", 0, $new);
14+
}
815
}

src/Helper/AbstractUserProperty.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,20 @@ public function toArray(): array
2828
{
2929
$return = [];
3030

31-
$return[$this->name] = $this->value;
31+
if (!isset($this->name)) {
32+
throw Ga4UserPropertyException::throwNameMissing();
33+
}
3234

33-
if (!is_array($this->value)) {
34-
$return[$this->name] = ['value' => $this->value];
35+
$value = isset($this->value) ? $this->value : null;
36+
if (!is_array($value)) {
37+
$value = ['value' => $value];
3538
}
3639

40+
$return[$this->name] = $value;
41+
3742
return $return;
3843
}
39-
44+
4045
public static function new(): static
4146
{
4247
return new static();

0 commit comments

Comments
 (0)