Skip to content

Commit d6c727d

Browse files
authored
Laravel 5.5 (#42)
* Prepare package for unit tests * WIP - improve code quality * Move from elixir to mix * WIP * WIP - clean up code * WIP - do not scrutinize public directory * WIP - cleaning up code * WIP * WIP - writing tests * Update travis config * WIP * Fix unit tests * WIP - bring things to green
1 parent 93055ec commit d6c727d

25 files changed

+624
-79
lines changed

.scrutinizer.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ filter:
22
excluded_paths:
33
- "public/"
44
- "tests/"
5+
- "resources/assets/js/mixpanel.js"

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,3 @@ notifications:
2323
on_success: change # options: [always|never|change] default: always
2424
on_failure: always # options: [always|never|change] default: always
2525
on_start: never # options: [always|never|change] default: always
26-

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1111
(This is already detected in subscription update.)
1212
- Filter any incoming web-hook events that are in test mode.
1313

14+
## [WIP] - 5 Nov 2017
15+
### Added
16+
- unit and feature tests.
17+
18+
### Changed
19+
- class structure as part of refactoring.
20+
1421
## [0.7.2] - 5 Nov 2017
1522
### Fixed
1623
- inclusion of auto-track JS scripts. NPM library is broken and seems to not be maintained anymore, switched to script provided by mixpanel setup instructions.

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"require-dev": {
3131
"fzaninotto/faker": "~1.4",
3232
"laravel/laravel": "5.5.*",
33+
"laravel/browser-kit-testing": "^2.0",
3334
"mockery/mockery": "0.9.*",
3435
"phpmd/phpmd": "^2.6",
3536
"phpunit/phpunit": "5.7.*",

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@
3232
<env name="QUEUE_DRIVER" value="sync"/>
3333
<env name="DB_CONNECTION" value="sqlite"/>
3434
<env name="DB_DATABASE" value=":memory:"/>
35+
<env name="MIXPANEL_TOKEN" value="68dffdba4c272b791a2d4883b43ccfd7"/>
3536
</php>
3637
</phpunit>

src/LaravelMixpanel.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ class LaravelMixpanel extends Mixpanel
1212
private $defaults;
1313
private $request;
1414

15-
/**
16-
* @param Request $request
17-
* @param array $options
18-
*
19-
* @internal param Result $browser
20-
*/
2115
public function __construct(Request $request, array $options = [])
2216
{
2317
$this->defaults = [
@@ -33,12 +27,6 @@ public function __construct(Request $request, array $options = [])
3327
);
3428
}
3529

36-
/**
37-
* @param string $event
38-
* @param array $properties
39-
*
40-
* @internal param array $data
41-
*/
4230
public function track($event, $properties = [])
4331
{
4432
$browserInfo = new Browser();

src/Listeners/LaravelMixpanelEventHandler.php

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
<?php namespace GeneaLabs\LaravelMixpanel\Listeners;
22

3-
use GeneaLabs\LaravelMixpanel\Events\MixpanelEvent;
3+
use GeneaLabs\LaravelMixpanel\Events\MixpanelEvent as Mixpanel;
44

55
class LaravelMixpanelUserObserver
66
{
77
public function created($user)
88
{
9-
event(new MixpanelEvent($user, 'User: Registered'));
9+
event(new Mixpanel($user, 'User: Registered'));
1010
}
1111

1212
public function saving($user)
1313
{
14-
event(new MixpanelEvent($user, 'User: Updated'));
14+
event(new Mixpanel($user, 'User: Updated'));
1515
}
1616

1717
public function deleting($user)
1818
{
19-
event(new MixpanelEvent($user, 'User: Deactivated'));
19+
event(new Mixpanel($user, 'User: Deactivated'));
2020
}
2121

2222
public function restored($user)
2323
{
24-
event(new MixpanelEvent($user, 'User: Reactivated'));
24+
event(new Mixpanel($user, 'User: Reactivated'));
2525
}
2626
}

src/Listeners/Login.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php namespace GeneaLabs\LaravelMixpanel\Listeners;
2+
3+
use GeneaLabs\LaravelMixpanel\Events\MixpanelEvent as Mixpanel;
4+
use Illuminate\Auth\Events\Login as LoginEvent;
5+
6+
class Login
7+
{
8+
public function handle(LoginEvent $login)
9+
{
10+
event(new Mixpanel($login->user, 'User Logged In'));
11+
}
12+
}

src/Listeners/LoginAttempt.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php namespace GeneaLabs\LaravelMixpanel\Listeners;
2+
3+
use GeneaLabs\LaravelMixpanel\Events\MixpanelEvent as Mixpanel;
4+
use Illuminate\Auth\Events\Attempting;
5+
6+
class LoginAttempt
7+
{
8+
public function handle(Attempting $event)
9+
{
10+
$email = $event->credentials['email'] ?? $event['email'] ?? '';
11+
12+
$authModel = config('auth.providers.users.model', config('auth.model'));
13+
$user = app($authModel)
14+
->where('email', $email)
15+
->first();
16+
$eventName = 'Login Attempted';
17+
18+
event(new Mixpanel($user, $eventName));
19+
}
20+
}

0 commit comments

Comments
 (0)