Skip to content

Commit

Permalink
Add integration with Laravel 8.x
Browse files Browse the repository at this point in the history
  • Loading branch information
jkocik committed Sep 14, 2020
1 parent dc5a102 commit cfe8190
Show file tree
Hide file tree
Showing 16 changed files with 144 additions and 69 deletions.
2 changes: 2 additions & 0 deletions .docker/etc/php/php-v2.ini
@@ -0,0 +1,2 @@
memory_limit = 256M
max_execution_time = 600
6 changes: 6 additions & 0 deletions .docker/images/php/.bashrc-v2
@@ -0,0 +1,6 @@
alias la6='vendor/bin/phpunit --stop-on-failure -c phpunit-laravel-6.xml'
alias la7='vendor/bin/phpunit --stop-on-failure -c phpunit-laravel-7.xml'
alias la8='vendor/bin/phpunit --stop-on-failure -c phpunit-laravel-8.xml'

alias la-all='la8 && la7 && la6'
alias la-c='la8 --coverage-html coverage'
22 changes: 22 additions & 0 deletions .docker/images/php/Dockerfile-v2
@@ -0,0 +1,22 @@
FROM php:7.4.10-fpm

COPY ./.bashrc-v2 /root/.bashrc

RUN apt-get update > /dev/null && apt-get install -y \
acl \
unzip \
libzip-dev \
zlib1g-dev \
libpng-dev \
libjpeg-dev \
nodejs \
redis-server

RUN docker-php-ext-install zip pdo_mysql bcmath gd > /dev/null

RUN pecl install xdebug > /dev/null \
&& docker-php-ext-enable xdebug > /dev/null

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer > /dev/null

RUN rm -rf /var/lib/apt/lists/*
15 changes: 4 additions & 11 deletions .travis.yml
@@ -1,9 +1,8 @@
language: php

php:
- 7.1
- 7.2
- 7.3
- 7.4

services:
- redis-server
Expand All @@ -12,15 +11,9 @@ before_script:
- composer install --no-interaction

script:
- vendor/bin/phpunit -c phpunit-laravel-52.xml
- vendor/bin/phpunit -c phpunit-laravel-53.xml
- vendor/bin/phpunit -c phpunit-laravel-54.xml
- vendor/bin/phpunit -c phpunit-laravel-55.xml
- vendor/bin/phpunit -c phpunit-laravel-56.xml
- vendor/bin/phpunit -c phpunit-laravel-57.xml
- vendor/bin/phpunit -c phpunit-laravel-58.xml
- if [[ ${TRAVIS_PHP_VERSION:0:3} != "7.1" ]]; then vendor/bin/phpunit -c phpunit-laravel-6.xml --coverage-clover build/logs/clover.xml; fi
- if [[ ${TRAVIS_PHP_VERSION:0:3} != "7.1" ]]; then vendor/bin/phpunit -c phpunit-laravel-7.xml; fi
- vendor/bin/phpunit -c phpunit-laravel-6.xml --coverage-clover build/logs/clover.xml
- vendor/bin/phpunit -c phpunit-laravel-7.xml
- vendor/bin/phpunit -c phpunit-laravel-8.xml

after_success:
- travis_retry php vendor/bin/php-coveralls -v
28 changes: 5 additions & 23 deletions README.md
Expand Up @@ -4,7 +4,7 @@
[![Coverage Status](https://coveralls.io/repos/github/jkocik/laravel-profiler/badge.svg?branch=master)](https://coveralls.io/github/jkocik/laravel-profiler?branch=master)

The aim of this project is to track console and web Laravel framework execution and give developers
better understanding what is going on under the hood. Laravel Profiler is designed for Laravel 5.2+.
better understanding what is going on under the hood. Laravel Profiler is designed for Laravel Framework.

![Laravel Profiler](https://drive.google.com/uc?export=view&id=12TSAEW1butnLfmFxO3Pw4GhF96B8PUSk)

Expand Down Expand Up @@ -42,6 +42,7 @@ Profiler Server passes data to Profiler Client using WebSockets.

Data tracked, collected and delivered to Profiler Client are:
- auth
- redis
- route
- views
- events
Expand All @@ -50,7 +51,6 @@ Data tracked, collected and delivered to Profiler Client are:
- server status
- database queries
- performance metrics
- redis (from Laravel 5.7)
- request (web) / input (console)
- response (web) / output (console)
- application (Laravel status, config, loaded service providers, container bindings, framework paths)
Expand All @@ -63,32 +63,14 @@ as possible.

### Step 1: Install Profiler Package

Requirements: PHP 7.1+ and Laravel 5.2+
Requirements: PHP 7.2+

It is recommended to install Profiler Package only for development

```shell
composer require jkocik/laravel-profiler:1.* --dev
composer require jkocik/laravel-profiler --dev
```

For Laravel 5.5+ you are fine and you can go to Step 2 of this installation process.

For Laravel 5.4 or lower add Service Provider to your application.
Do not add it in config/app.php because that will add Profiler
for all your environments. Instead of that open AppServiceProvider class
and add Profiler Service Provider in register method:

```php
// app/Providers/AppServiceProvider.php

public function register()
{
if (! $this->app->environment('production')) {
$this->app->register(\JKocik\Laravel\Profiler\ServiceProvider::class);
}
}
```

### Step 2: Publish configuration file

Run command
Expand Down Expand Up @@ -127,7 +109,7 @@ php artisan profiler:client

After that your browser should have new tab opened with Profiler Client connected to Profiler Server.

b) for Vagrant or any other machine different than local
b) for Docker, Vagrant or any other machine different from local

```shell
php artisan profiler:client -m
Expand Down
7 changes: 3 additions & 4 deletions composer.json
@@ -1,6 +1,6 @@
{
"name": "jkocik/laravel-profiler",
"description": "Profiler for Laravel framework 5.2+",
"description": "Profiler for Laravel Framework",
"keywords": ["laravel", "profiler", "debugbar"],
"homepage": "https://github.com/jkocik/laravel-profiler",
"license": "MIT",
Expand All @@ -11,11 +11,10 @@
}
],
"require": {
"php": ">=7.1.0",
"guzzlehttp/guzzle": "^5.0 || ^6.0"
"php": ">=7.2",
"guzzlehttp/guzzle": "^5.0 || ^6.0 || ^7.0"
},
"require-dev": {
"laravel/homestead": "^7.3",
"phpunit/phpunit": "^6.5",
"mockery/mockery": "^1.0",
"php-mock/php-mock": "^2.0",
Expand Down
12 changes: 12 additions & 0 deletions docker-compose.yml
Expand Up @@ -12,3 +12,15 @@ services:
- ./.docker/etc/php/entrypoint.sh:/bin/entrypoint.sh:ro
- ./.docker/etc/php/php-v1.ini:/usr/local/etc/php/php.ini
- .:/var/www/html

profiler_v2:
build:
dockerfile: Dockerfile-v2
context: ./.docker/images/php
container_name: profiler_v2
hostname: profiler_v2
entrypoint: sh /bin/entrypoint.sh php-fpm
volumes:
- ./.docker/etc/php/entrypoint.sh:/bin/entrypoint.sh:ro
- ./.docker/etc/php/php-v2.ini:/usr/local/etc/php/php.ini
- .:/var/www/html
32 changes: 32 additions & 0 deletions phpunit-laravel-8.xml
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./tests/bootstrap/phpunit.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false"
>
<testsuites>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
<listeners>
<listener class="\JKocik\Laravel\Profiler\Tests\Support\TestListener">
</listener>
</listeners>
<php>
<const name="TESTS_FRAMEWORK_VERSION" value="8"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
<env name="REDIS_CLIENT" value="predis"/>
</php>
</phpunit>
2 changes: 1 addition & 1 deletion tests/Feature/LaravelNullExecutionTest.php
Expand Up @@ -44,7 +44,7 @@ function null_request_has_only_type()
{
$request = $this->executionData->request();

$this->assertArrayHasKey('type', $request->meta());
$this->assertTrue($request->meta()->has('type'));
$this->assertNull($request->meta()->get('type'));
$this->assertCount(1, $request->meta());
$this->assertCount(0, $request->data());
Expand Down
8 changes: 4 additions & 4 deletions tests/Support/Fixtures/DummyEventB.php
Expand Up @@ -2,16 +2,16 @@

namespace JKocik\Laravel\Profiler\Tests\Support\Fixtures;

use App\User;
use Illuminate\Support\Collection;
use Illuminate\Queue\SerializesModels;
use Illuminate\Database\Eloquent\Model;

class DummyEventB
{
use SerializesModels;

/**
* @var User
* @var Model
*/
public $user;

Expand Down Expand Up @@ -42,15 +42,15 @@ class DummyEventB

/**
* DummyEventB constructor.
* @param User $user
* @param Model $user
* @param Collection $usersA
* @param array $usersB
* @param array $dummyClasses
* @param array $dataA
* @param string $dataB
*/
public function __construct(
User $user,
Model $user,
Collection $usersA,
array $usersB,
array $dummyClasses,
Expand Down
32 changes: 32 additions & 0 deletions tests/TestCase.php
Expand Up @@ -4,6 +4,7 @@

use Closure;
use Illuminate\Foundation\Application;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Console\Kernel;
use phpmock\environment\MockEnvironment;
use JKocik\Laravel\Profiler\ServiceProvider;
Expand Down Expand Up @@ -109,6 +110,37 @@ protected function appWith(Closure $beforeServiceProvider): Application
return $app;
}

/**
* @return string
*/
protected function userClass(): string
{
return $this->app->make('config')->get('auth.providers.users.model');
}

/**
* @return object
*/
protected function factoryUser(): object
{
if (function_exists('factory')) {
return factory($this->userClass());
}

return $this->userClass()::factory();
}

/**
* @param array $attributes
* @return Model
*/
protected function user(array $attributes = []): Model
{
$userClass = $this->app->make('config')->get('auth.providers.users.model');

return new $userClass($attributes);
}

/**
* @return void
*/
Expand Down
3 changes: 1 addition & 2 deletions tests/Unit/Services/ParamsServiceTest.php
Expand Up @@ -2,7 +2,6 @@

namespace JKocik\Laravel\Profiler\Tests\Unit\Services;

use App\User;
use JKocik\Laravel\Profiler\Tests\TestCase;
use JKocik\Laravel\Profiler\Services\ParamsService;
use JKocik\Laravel\Profiler\Tests\Support\Fixtures\DummyClassA;
Expand All @@ -26,7 +25,7 @@ function returns_value_of_primitive_param_type()
function returns_array_of_object_param_if_is_available()
{
$paramsService = $this->app->make(ParamsService::class);
$user = new User(['email' => 'a@example.com']);
$user = $this->user(['email' => 'a@example.com']);

$this->assertEquals($user->toArray(), $paramsService->resolve($user));
}
Expand Down
5 changes: 2 additions & 3 deletions tests/Unit/Trackers/AuthTrackerTest.php
Expand Up @@ -2,7 +2,6 @@

namespace JKocik\Laravel\Profiler\Tests\Unit\Trackers;

use App\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Artisan;
use JKocik\Laravel\Profiler\Tests\TestCase;
Expand Down Expand Up @@ -35,7 +34,7 @@ function has_auth_user()
{
$tracker = $this->app->make(AuthTracker::class);

$user = factory(User::class)->create(['email' => 'user@example.com']);
$user = $this->factoryUser()->create(['email' => 'user@example.com']);
Auth::login($user);

$tracker->terminate();
Expand All @@ -49,7 +48,7 @@ function has_auth_user_even_user_is_logging_out()
{
$tracker = $this->app->make(AuthTracker::class);

$user = factory(User::class)->create([
$user = $this->factoryUser()->create([
'email' => 'login.me@example.com',
]);
Auth::login($user);
Expand Down
13 changes: 6 additions & 7 deletions tests/Unit/Trackers/EventsTrackerTest.php
Expand Up @@ -2,7 +2,6 @@

namespace JKocik\Laravel\Profiler\Tests\Unit\Trackers;

use App\User;
use Exception;
use Illuminate\Events\Dispatcher;
use JKocik\Laravel\Profiler\Tests\TestCase;
Expand Down Expand Up @@ -51,9 +50,9 @@ function has_data_of_fired_events()

$tracker = $this->app->make(EventsTracker::class);

$user = new User(['email' => 'a@example.com']);
$usersA = collect([new User(['email' => 'b@example.com']), new User(['email' => 'c@example.com'])]);
$usersB = [new User(['email' => 'd@example.com']), new User(['email' => collect(['email' => 'e@example.com'])])];
$user = $this->user(['email' => 'a@example.com']);
$usersA = collect([$this->user(['email' => 'b@example.com']), $this->user(['email' => 'c@example.com'])]);
$usersB = [$this->user(['email' => 'd@example.com']), $this->user(['email' => collect(['email' => 'e@example.com'])])];
$dummyClasses = [new DummyClassA(), new DummyClassB()];
$dataA = ['a' => 1, 'c' => 2];
$dataB = 'c';
Expand Down Expand Up @@ -85,9 +84,9 @@ function has_not_data_of_fired_events_if_data_tracking_is_disabled_in_config()

$tracker = $this->app->make(EventsTracker::class);

$user = new User(['email' => 'a@example.com']);
$usersA = collect([new User(['email' => 'b@example.com']), new User(['email' => 'c@example.com'])]);
$usersB = [new User(['email' => 'd@example.com']), new User(['email' => 'e@example.com'])];
$user = $this->user(['email' => 'a@example.com']);
$usersA = collect([$this->user(['email' => 'b@example.com']), $this->user(['email' => 'c@example.com'])]);
$usersB = [$this->user(['email' => 'd@example.com']), $this->user(['email' => 'e@example.com'])];
$dummyClasses = [new DummyClassA(), new DummyClassB()];
$dataA = ['a' => 1, 'c' => 2];
$dataB = 'c';
Expand Down

0 comments on commit cfe8190

Please sign in to comment.