Skip to content

Commit 8951b8c

Browse files
committed
Finalise fake implementation
1 parent 287a924 commit 8951b8c

File tree

7 files changed

+19
-27
lines changed

7 files changed

+19
-27
lines changed

src/SegmentServiceContract.php renamed to src/Contracts/SegmentServiceContract.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?php
22

3-
namespace SlashEquip\LaravelSegment;
3+
namespace SlashEquip\LaravelSegment\Contracts;
44

5-
use SlashEquip\LaravelSegment\Contracts\CanBeIdentifiedForSegment;
6-
use SlashEquip\LaravelSegment\Contracts\CanBeSentToSegment;
5+
use SlashEquip\LaravelSegment\PendingUserSegment;
76

87
interface SegmentServiceContract
98
{

src/Facades/Fakes/SegmentFake.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use PHPUnit\Framework\Assert as PHPUnit;
88
use SlashEquip\LaravelSegment\Contracts\CanBeIdentifiedForSegment;
99
use SlashEquip\LaravelSegment\Contracts\CanBeSentToSegment;
10+
use SlashEquip\LaravelSegment\Contracts\SegmentServiceContract;
1011
use SlashEquip\LaravelSegment\PendingUserSegment;
11-
use SlashEquip\LaravelSegment\SegmentServiceContract;
1212
use SlashEquip\LaravelSegment\SimpleSegmentEvent;
1313
use SlashEquip\LaravelSegment\SimpleSegmentIdentify;
1414

src/Facades/Segment.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
use Illuminate\Support\Facades\Facade;
66
use SlashEquip\LaravelSegment\Contracts\CanBeIdentifiedForSegment;
77
use SlashEquip\LaravelSegment\Contracts\CanBeSentToSegment;
8+
use SlashEquip\LaravelSegment\Contracts\SegmentServiceContract;
89
use SlashEquip\LaravelSegment\Facades\Fakes\SegmentFake;
910
use SlashEquip\LaravelSegment\PendingUserSegment;
10-
use SlashEquip\LaravelSegment\SegmentService;
1111

1212
/**
1313
* @method static void setGlobalUser(CanBeIdentifiedForSegment $globalUser)
@@ -17,17 +17,15 @@
1717
* @method static PendingUserSegment forUser(CanBeIdentifiedForSegment $user)
1818
* @method static void push(CanBeSentToSegment $segment)
1919
* @method static void terminate()
20-
*/
21-
22-
/**
20+
*
2321
* @see \SlashEquip\LaravelSegment\SegmentService
24-
* @see \SlashEquip\LaravelSegment\Facades\Fakes\SegmentFake
22+
* @see SegmentFake
2523
*/
2624
class Segment extends Facade
2725
{
2826
protected static function getFacadeAccessor(): string
2927
{
30-
return SegmentService::class;
28+
return SegmentServiceContract::class;
3129
}
3230

3331
public static function fake(): SegmentFake

src/LaravelSegmentServiceProvider.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@
44

55
use Illuminate\Support\Facades\Queue;
66
use Illuminate\Support\ServiceProvider;
7+
use SlashEquip\LaravelSegment\Contracts\SegmentServiceContract;
78
use SlashEquip\LaravelSegment\Facades\Segment;
89

910
class LaravelSegmentServiceProvider extends ServiceProvider
1011
{
11-
/**
12-
* Bootstrap any package services.
13-
*
14-
* @return void
15-
*/
16-
public function boot()
12+
public function boot(): void
1713
{
1814
// Setup config publishing
1915
$this->publishes([
@@ -35,12 +31,7 @@ public function boot()
3531
});
3632
}
3733

38-
/**
39-
* Register any application services.
40-
*
41-
* @return void
42-
*/
43-
public function register()
34+
public function register(): void
4435
{
4536
// Register config.
4637
$this->mergeConfigFrom(
@@ -49,7 +40,7 @@ public function register()
4940
);
5041

5142
// Register the Segment service.
52-
$this->app->singleton(SegmentService::class, function ($app) {
43+
$this->app->singleton(SegmentServiceContract::class, function ($app) {
5344
return new SegmentService($app->make('config')['segment']);
5445
});
5546
}

src/PendingUserSegment.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace SlashEquip\LaravelSegment;
44

55
use SlashEquip\LaravelSegment\Contracts\CanBeIdentifiedForSegment;
6+
use SlashEquip\LaravelSegment\Contracts\SegmentServiceContract;
67

78
class PendingUserSegment
89
{

src/SegmentService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Support\Facades\Http;
77
use SlashEquip\LaravelSegment\Contracts\CanBeIdentifiedForSegment;
88
use SlashEquip\LaravelSegment\Contracts\CanBeSentToSegment;
9+
use SlashEquip\LaravelSegment\Contracts\SegmentServiceContract;
910
use SlashEquip\LaravelSegment\Enums\SegmentPayloadType;
1011
use SlashEquip\LaravelSegment\ValueObjects\SegmentPayload;
1112
use Throwable;

tests/Unit/SegmentServiceTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
use Illuminate\Queue\Events\JobProcessed;
55
use Illuminate\Queue\Jobs\Job;
66
use Illuminate\Support\Facades\Http;
7+
use SlashEquip\LaravelSegment\Contracts\SegmentServiceContract;
78
use SlashEquip\LaravelSegment\Facades\Segment;
89
use SlashEquip\LaravelSegment\SegmentService;
910
use SlashEquip\LaravelSegment\Tests\Stubs\SegmentTestUser;
1011

1112
it('can be resolved from the container', function () {
12-
$this->assertInstanceOf(SegmentService::class, app(SegmentService::class));
13+
expect(app(SegmentServiceContract::class))
14+
->toBeInstanceOf(SegmentService::class);
1315
});
1416

1517
it('can track a user using the track method with global user and context', function () {
@@ -103,7 +105,7 @@
103105

104106
it('terminates the segment service on job processed', function () {
105107
// Given we are spying on the service
106-
$service = $this->spy(SegmentService::class);
108+
$service = test()->spy(SegmentServiceContract::class);
107109

108110
// When we fire the job processed event
109111
event(new JobProcessed('default', Mockery::mock(Job::class)));
@@ -115,10 +117,10 @@
115117

116118
it('terminates the segment service on app terminate', function () {
117119
// Given we are spying on the service
118-
$service = $this->spy(SegmentService::class);
120+
$service = test()->spy(SegmentServiceContract::class);
119121

120122
// When we terminate the app
121-
$this->app->terminate();
123+
test()->app()->terminate();
122124

123125
// Then we have called the terminate method
124126
$service->shouldHaveReceived('terminate')

0 commit comments

Comments
 (0)