Skip to content

Commit bbf29ea

Browse files
committed
few fixes, add test command
1 parent 456caf4 commit bbf29ea

File tree

5 files changed

+88
-6
lines changed

5 files changed

+88
-6
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
<p align="center"><img width="800" src="https://github.com/bugphix/documentation/blob/master/assets/dashboard.gif" alt="Dashboard gif"></p>
1414

1515
#### Requirements
16-
- Currently tested working with Laravel 6
16+
17+
- [Check Laravel 6 requirements](https://laravel.com/docs/6.x#server-requirements)
18+
- [Check Laravel 7 requirements](https://laravel.com/docs/7.x#server-requirements)
1719

1820
## Installation
1921
$ composer require bugphix/bugphix-laravel
@@ -36,6 +38,9 @@ edit: /app/Exceptions/Handler.php
3638
parent::report($exception);
3739
}
3840

41+
### Test Command
42+
$ php artisan bugphix:test
43+
3944
### View admin dashboard
4045
http://localhost:8080/bugphix/issues
4146

src/BugphixServiceProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ private function bugphixCommands()
9494
$this->commands([
9595
Commands\InstallCommand::class,
9696
Commands\BugphixAssetsSymlink::class,
97+
Commands\BugphixTestCommand::class,
9798
]);
9899
}
99100

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace Bugphix\BugphixLaravel\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Exception;
7+
8+
class BugphixTestCommand extends Command
9+
{
10+
11+
/**
12+
* The console command name.
13+
*
14+
* @var string
15+
*/
16+
protected $signature = 'bugphix:test';
17+
18+
/**
19+
* The console command description.
20+
*
21+
* @var string
22+
*/
23+
protected $description = 'Generate test event for bugphix error';
24+
25+
/**
26+
* Execute the console command.
27+
*
28+
* @return void
29+
*/
30+
public function handle()
31+
{
32+
33+
$errorReporting = error_reporting(E_ALL | E_STRICT);
34+
35+
try {
36+
$this->info('Creating bugphix event');
37+
$app = app('bugphix');
38+
$exception = $this->generateException('test bugphix', ['bug' => 'phix']);
39+
40+
$userUnique = 'ID:'. rand(100,1000);
41+
$userMeta = array(
42+
'ID' => $userUnique,
43+
'email' => 'test-user@bugphix.com',
44+
'name' => 'Bugphix user'
45+
);
46+
47+
$app->configUser($userUnique, $userMeta)->catchError($exception);
48+
49+
$this->comment('Test error created');
50+
51+
} catch (Exception $e) {
52+
$this->error("Generating bugphix test event {$e->getMessage()}");
53+
}
54+
55+
error_reporting($errorReporting);
56+
}
57+
58+
/**
59+
* Generate a test exception to send to Sentry.
60+
*
61+
* @param $command
62+
* @param $arg
63+
*
64+
* @return \Exception
65+
*/
66+
protected function generateException($command, $arg): ?Exception
67+
{
68+
try {
69+
throw new Exception('This is a test exception sent from the command [bugphix:test]');
70+
} catch (Exception $ex) {
71+
return $ex;
72+
}
73+
}
74+
}

src/Commands/InstallCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function handle(Filesystem $filesystem)
6262
// dump autoloaded files
6363
$this->info('Dumping the autoloaded files and reloading all new files');
6464
$composer = $this->findComposer();
65-
$process = new Process($composer . ' dump-autoload');
65+
$process = new Process([$composer . ' dump-autoload']);
6666
$process->setTimeout(null);
6767
$process->setWorkingDirectory(base_path())->run();
6868

@@ -71,6 +71,8 @@ public function handle(Filesystem $filesystem)
7171

7272
$this->call('bugphix:assets-symlink');
7373
$this->comment("Bugphix successfully installed!");
74+
75+
$this->comment(PHP_EOL . 'Try bugphix error run: php artisan bugphix:test');
7476
}
7577

7678
private function registerLocalProject()

src/Traits/BugphixProcess.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected function bugphixStore()
7575
'client_browser_version' => $this->bugphixClient['browser_version'],
7676
'client_os' => $this->bugphixClient['os'],
7777
'client_ip' => $this->bugphixClient['ip'],
78-
'client_header' => $this->bugphixClient['header'],
78+
'client_header' => count($this->bugphixClient['header']) ? $this->bugphixClient['header'] : null,
7979
]);
8080
}
8181

@@ -92,21 +92,21 @@ protected function bugphixStore()
9292
*/
9393

9494
if ($event) {
95-
if ($client) {
95+
if (isset($client) && !empty($client)) {
9696
EventClient::firstOrCreate([
9797
'event_id' => $event->id,
9898
'client_id' => $client->id,
9999
]);
100100
}
101101

102-
if ($server) {
102+
if (isset($server) && !empty($server)) {
103103
EventServer::firstOrCreate([
104104
'event_id' => $event->id,
105105
'server_id' => $server->id,
106106
]);
107107
}
108108

109-
if ($user) {
109+
if (isset($user) && !empty($user)) {
110110
EventUser::firstOrCreate([
111111
'event_id' => $event->id,
112112
'user_id' => $user->id,

0 commit comments

Comments
 (0)