-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Enhancement: Assert that Segment throws SegmentException without initialization * Fix: Property can be null
- Loading branch information
1 parent
2ab7c0f
commit dd47f60
Showing
2 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Segment\Test; | ||
|
||
use PHPUnit\Framework; | ||
use Segment\Segment; | ||
use Segment\SegmentException; | ||
|
||
final class SegmentTest extends Framework\TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
self::resetSegment(); | ||
} | ||
|
||
public function testAliasThrowsSegmentExceptionWhenClientHasNotBeenInitialized(): void | ||
{ | ||
$this->expectException(SegmentException::class); | ||
$this->expectExceptionMessage('Segment::init() must be called before any other tracking method.'); | ||
|
||
Segment::alias([]); | ||
} | ||
public function testFlushThrowsSegmentExceptionWhenClientHasNotBeenInitialized(): void | ||
{ | ||
$this->expectException(SegmentException::class); | ||
$this->expectExceptionMessage('Segment::init() must be called before any other tracking method.'); | ||
|
||
Segment::flush(); | ||
} | ||
public function testGroupThrowsSegmentExceptionWhenClientHasNotBeenInitialized(): void | ||
{ | ||
$this->expectException(SegmentException::class); | ||
$this->expectExceptionMessage('Segment::init() must be called before any other tracking method.'); | ||
|
||
Segment::group([]); | ||
} | ||
public function testIdentifyThrowsSegmentExceptionWhenClientHasNotBeenInitialized(): void | ||
{ | ||
$this->expectException(SegmentException::class); | ||
$this->expectExceptionMessage('Segment::init() must be called before any other tracking method.'); | ||
|
||
Segment::identify([]); | ||
} | ||
public function testPageThrowsSegmentExceptionWhenClientHasNotBeenInitialized(): void | ||
{ | ||
$this->expectException(SegmentException::class); | ||
$this->expectExceptionMessage('Segment::init() must be called before any other tracking method.'); | ||
|
||
Segment::page([]); | ||
} | ||
public function testScreenThrowsSegmentExceptionWhenClientHasNotBeenInitialized(): void | ||
{ | ||
$this->expectException(SegmentException::class); | ||
$this->expectExceptionMessage('Segment::init() must be called before any other tracking method.'); | ||
|
||
Segment::screen([]); | ||
} | ||
public function testTrackThrowsSegmentExceptionWhenClientHasNotBeenInitialized(): void | ||
{ | ||
$this->expectException(SegmentException::class); | ||
$this->expectExceptionMessage('Segment::init() must be called before any other tracking method.'); | ||
|
||
Segment::track([]); | ||
} | ||
|
||
private static function resetSegment(): void | ||
{ | ||
$property = new \ReflectionProperty( | ||
Segment::class, | ||
'client' | ||
); | ||
|
||
$property->setAccessible(true); | ||
$property->setValue(null); | ||
} | ||
} |