Skip to content

Commit

Permalink
Finalize L11 (#16)
Browse files Browse the repository at this point in the history
* Tests for L11 and PHP8.3

* Fix styling

* Fix

* No PHP 8.1

* Update pest

* Update psalm

* ergh matrixes are hard…

* Latest only for tests

* wip

---------

Co-authored-by: slashequip <[email protected]>
  • Loading branch information
slashequip and slashequip authored May 20, 2024
1 parent 35cccbb commit d47264a
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 63 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.1, 8.2]
laravel: [9.*, 10.*]
php: [8.3]
laravel: [11.*]
stability: [prefer-stable]
include:
- laravel: 9.*
testbench: 7.*
- laravel: 10.*
testbench: 8.*
- laravel: 11.*
testbench: 9.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/composer.lock
/build
/.php_cs.cache
/.phpunit.cache
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
"laravel/pint": "^1.10",
"mockery/mockery": "^1.4",
"nunomaduro/larastan": "^2.0",
"orchestra/testbench": "^7.25|^8.5",
"pestphp/pest": "^1.0",
"phpunit/phpunit": "^9.3",
"vimeo/psalm": "^4.6"
"orchestra/testbench": "^7.25|^8.5|^9.0",
"pestphp/pest": "^2.0",
"vimeo/psalm": "^5.24"
},
"autoload": {
"psr-4": {
Expand Down
58 changes: 21 additions & 37 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,39 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
verbose="true"
>
<testsuites>
<testsuite name="Laravel Segment Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" executionOrder="random" failOnWarning="true" failOnRisky="true" failOnEmptyTestSuite="true" beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Laravel Segment Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
39 changes: 39 additions & 0 deletions phpunit.xml.dist.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
verbose="true"
>
<testsuites>
<testsuite name="Laravel Segment Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
</phpunit>
4 changes: 2 additions & 2 deletions src/Contracts/SegmentServiceContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public function setGlobalContext(array $globalContext): void;
/**
* @param array<string, mixed> $eventData
*/
public function track(string $event, array $eventData = null): void;
public function track(string $event, ?array $eventData = null): void;

/**
* @param array<string, mixed> $identifyData
*/
public function identify(array $identifyData = null): void;
public function identify(?array $identifyData = null): void;

public function forUser(CanBeIdentifiedForSegment $user): PendingUserSegment;

Expand Down
18 changes: 9 additions & 9 deletions src/Facades/Fakes/SegmentFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function identify(?array $identifyData = []): void
/**
* @param array<string, mixed> $eventData
*/
public function track(string $event, array $eventData = null): void
public function track(string $event, ?array $eventData = null): void
{
$this->events[] = new SimpleSegmentEvent($this->user, $event, $eventData);
}
Expand All @@ -76,7 +76,7 @@ public function terminate(): void
{
}

public function assertIdentified(Closure|int $callback = null): void
public function assertIdentified(Closure|int|null $callback = null): void
{
if (is_numeric($callback)) {
$this->assertIdentifiedTimes($callback);
Expand All @@ -100,7 +100,7 @@ public function assertIdentifiedTimes(int $times = 1): void
);
}

public function assertNotIdentified(Closure $callback = null): void
public function assertNotIdentified(?Closure $callback = null): void
{
PHPUnit::assertCount(
0, $this->identities($callback),
Expand All @@ -115,7 +115,7 @@ public function assertNothingIdentified(): void
PHPUnit::assertEmpty($identities, $identities->count().' events were found unexpectedly.');
}

public function assertTracked(Closure|int $callback = null): void
public function assertTracked(Closure|int|null $callback = null): void
{
if (is_numeric($callback)) {
$this->assertTrackedTimes($callback);
Expand All @@ -139,23 +139,23 @@ public function assertTrackedTimes(int $times = 1): void
);
}

public function assertEventTracked(string $event, Closure|int $callback = null): void
public function assertEventTracked(string $event, Closure|int|null $callback = null): void
{
PHPUnit::assertTrue(
$this->events($callback, $event)->count() > 0,
'The expected events were not called.'
);
}

public function assertNotTracked(Closure $callback = null): void
public function assertNotTracked(?Closure $callback = null): void
{
PHPUnit::assertCount(
0, $this->events($callback),
'The unexpected event was called.'
);
}

public function assertEventNotTracked(string $event, Closure|int $callback = null): void
public function assertEventNotTracked(string $event, Closure|int|null $callback = null): void
{
PHPUnit::assertCount(
0, $this->events($callback, $event),
Expand All @@ -178,7 +178,7 @@ public function getContext(): ?array
return $this->context;
}

private function identities(Closure $callback = null): Collection
private function identities(?Closure $callback = null): Collection
{
$identities = collect($this->identities);

Expand All @@ -191,7 +191,7 @@ private function identities(Closure $callback = null): Collection
return $identities->filter(fn (SimpleSegmentIdentify $identity) => $callback($identity));
}

private function events(Closure $callback = null, string $event = null): Collection
private function events(?Closure $callback = null, ?string $event = null): Collection
{
$events = collect($this->events);

Expand Down
4 changes: 2 additions & 2 deletions src/PendingUserSegment.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(SegmentServiceContract $service, CanBeIdentifiedForS
/**
* @param array<string, mixed>|null $eventData
*/
public function track(string $event, array $eventData = null): void
public function track(string $event, ?array $eventData = null): void
{
$this->service->push(
new SimpleSegmentEvent($this->user, $event, $eventData)
Expand All @@ -30,7 +30,7 @@ public function track(string $event, array $eventData = null): void
/**
* @param array<string, mixed>|null $identifyData
*/
public function identify(array $identifyData = null): void
public function identify(?array $identifyData = null): void
{
$this->service->push(
new SimpleSegmentIdentify($this->user, $identifyData)
Expand Down
4 changes: 2 additions & 2 deletions src/SegmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function setGlobalContext(array $globalContext): void
/**
* @param array<string, mixed> $eventData
*/
public function track(string $event, array $eventData = null): void
public function track(string $event, ?array $eventData = null): void
{
$this->push(
new SimpleSegmentEvent($this->globalUser, $event, $eventData)
Expand All @@ -57,7 +57,7 @@ public function track(string $event, array $eventData = null): void
/**
* @param array<string, mixed> $identifyData
*/
public function identify(array $identifyData = null): void
public function identify(?array $identifyData = null): void
{
$this->push(
new SimpleSegmentIdentify($this->globalUser, $identifyData)
Expand Down
2 changes: 1 addition & 1 deletion src/ValueObjects/SegmentPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(
public readonly SegmentPayloadType $type,
public readonly ?string $event = null,
public readonly array $data = [],
DateTime $timestamp = null
?DateTime $timestamp = null
) {
$this->timestamp = $timestamp ?: new DateTime();
$this->timestamp->setTimezone(new DateTimeZone('UTC'));
Expand Down

0 comments on commit d47264a

Please sign in to comment.