diff --git a/.docker/etc/php/php-v2.ini b/.docker/etc/php/php-v2.ini new file mode 100644 index 0000000..36ec3e8 --- /dev/null +++ b/.docker/etc/php/php-v2.ini @@ -0,0 +1,2 @@ +memory_limit = 256M +max_execution_time = 600 diff --git a/.docker/images/php/.bashrc-v2 b/.docker/images/php/.bashrc-v2 new file mode 100644 index 0000000..907e4de --- /dev/null +++ b/.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' diff --git a/.docker/images/php/Dockerfile-v2 b/.docker/images/php/Dockerfile-v2 new file mode 100644 index 0000000..9edec69 --- /dev/null +++ b/.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/* diff --git a/.travis.yml b/.travis.yml index 150a16c..6c0d514 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,8 @@ language: php php: - - 7.1 - - 7.2 - 7.3 + - 7.4 services: - redis-server @@ -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 diff --git a/README.md b/README.md index 491fa67..ef72798 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 @@ -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) @@ -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 @@ -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 diff --git a/composer.json b/composer.json index b15dbc7..ba04a73 100644 --- a/composer.json +++ b/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", @@ -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", diff --git a/docker-compose.yml b/docker-compose.yml index 0ad1273..3f1b668 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/phpunit-laravel-8.xml b/phpunit-laravel-8.xml new file mode 100644 index 0000000..439768d --- /dev/null +++ b/phpunit-laravel-8.xml @@ -0,0 +1,32 @@ + + + + + ./tests/Feature + + + ./tests/Unit + + + + + ./src/ + + + + + + + + + + + + + diff --git a/tests/Feature/LaravelNullExecutionTest.php b/tests/Feature/LaravelNullExecutionTest.php index 216be4a..18a5334 100644 --- a/tests/Feature/LaravelNullExecutionTest.php +++ b/tests/Feature/LaravelNullExecutionTest.php @@ -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()); diff --git a/tests/Support/Fixtures/DummyEventB.php b/tests/Support/Fixtures/DummyEventB.php index 773fc33..10d81cd 100644 --- a/tests/Support/Fixtures/DummyEventB.php +++ b/tests/Support/Fixtures/DummyEventB.php @@ -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; @@ -42,7 +42,7 @@ class DummyEventB /** * DummyEventB constructor. - * @param User $user + * @param Model $user * @param Collection $usersA * @param array $usersB * @param array $dummyClasses @@ -50,7 +50,7 @@ class DummyEventB * @param string $dataB */ public function __construct( - User $user, + Model $user, Collection $usersA, array $usersB, array $dummyClasses, diff --git a/tests/TestCase.php b/tests/TestCase.php index 7815228..f85e9bb 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -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; @@ -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 */ diff --git a/tests/Unit/Services/ParamsServiceTest.php b/tests/Unit/Services/ParamsServiceTest.php index 64dfacd..b145ccb 100644 --- a/tests/Unit/Services/ParamsServiceTest.php +++ b/tests/Unit/Services/ParamsServiceTest.php @@ -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; @@ -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)); } diff --git a/tests/Unit/Trackers/AuthTrackerTest.php b/tests/Unit/Trackers/AuthTrackerTest.php index 7be2ec0..f109a69 100644 --- a/tests/Unit/Trackers/AuthTrackerTest.php +++ b/tests/Unit/Trackers/AuthTrackerTest.php @@ -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; @@ -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(); @@ -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); diff --git a/tests/Unit/Trackers/EventsTrackerTest.php b/tests/Unit/Trackers/EventsTrackerTest.php index cc4dd79..1cfcf1b 100644 --- a/tests/Unit/Trackers/EventsTrackerTest.php +++ b/tests/Unit/Trackers/EventsTrackerTest.php @@ -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; @@ -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'; @@ -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'; diff --git a/tests/Unit/Trackers/QueriesTrackerTest.php b/tests/Unit/Trackers/QueriesTrackerTest.php index 0675f85..68248ad 100644 --- a/tests/Unit/Trackers/QueriesTrackerTest.php +++ b/tests/Unit/Trackers/QueriesTrackerTest.php @@ -2,7 +2,6 @@ namespace JKocik\Laravel\Profiler\Tests\Unit\Trackers; -use App\User; use Exception; use Carbon\Carbon; use Illuminate\Support\Facades\DB; @@ -36,7 +35,7 @@ protected function tearDown() function has_executed_queries() { $tracker = $this->app->make(QueriesTracker::class); - factory(User::class)->create([ + $this->factoryUser()->create([ 'name' => 'Joe', 'email' => 'joe@example.com', ]); @@ -60,7 +59,7 @@ function has_committed_transactions() { $tracker = $this->app->make(QueriesTracker::class); DB::transaction(function () { - factory(User::class)->create(); + $this->factoryUser()->create(); }); $tracker->terminate(); @@ -98,7 +97,7 @@ function can_count_queries() { $tracker = $this->app->make(QueriesTracker::class); DB::select('select * from users'); - factory(User::class)->create(); + $this->factoryUser()->create(); $tracker->terminate(); @@ -111,7 +110,7 @@ function can_count_queries_without_transactions() $tracker = $this->app->make(QueriesTracker::class); DB::transaction(function () { DB::select('select * from users'); - factory(User::class)->create(); + $this->factoryUser()->create(); }); $tracker->terminate(); @@ -136,10 +135,10 @@ function has_bindings_keys_names_if_specified() function has_query_bindings_for_int_and_float_values() { $tracker = $this->app->make(QueriesTracker::class); - User::whereEmail(1)->first(); - User::whereEmail(1.1)->first(); - User::whereEmail('1')->first(); - User::whereEmail('1.1')->first(); + $this->userClass()::whereEmail(1)->first(); + $this->userClass()::whereEmail(1.1)->first(); + $this->userClass()::whereEmail('1')->first(); + $this->userClass()::whereEmail('1.1')->first(); $tracker->terminate(); $queries = $tracker->data()->get('queries'); @@ -154,8 +153,8 @@ function has_query_bindings_for_int_and_float_values() function has_query_bindings_for_null_values() { $tracker = $this->app->make(QueriesTracker::class); - User::whereNull('email')->first(); - User::whereNotNull('email')->first(); + $this->userClass()::whereNull('email')->first(); + $this->userClass()::whereNotNull('email')->first(); $tracker->terminate(); $queries = $tracker->data()->get('queries'); diff --git a/tests/Unit/Trackers/ViewsTrackerTest.php b/tests/Unit/Trackers/ViewsTrackerTest.php index e8cca11..c23ed93 100644 --- a/tests/Unit/Trackers/ViewsTrackerTest.php +++ b/tests/Unit/Trackers/ViewsTrackerTest.php @@ -2,7 +2,6 @@ namespace JKocik\Laravel\Profiler\Tests\Unit\Trackers; -use App\User; use JKocik\Laravel\Profiler\Tests\TestCase; use JKocik\Laravel\Profiler\Trackers\ViewsTracker; @@ -100,7 +99,7 @@ function has_view_params_if_data_tracking_is_disabled_in_config() $price = 5.89; $active = true; $address = null; - $related = new User(['email' => 'a@example.com']); + $related = $this->user(['email' => 'a@example.com']); $roles = collect(['publisher', 'viewer']); $tags = ['a']; $comments = []; @@ -126,7 +125,7 @@ function has_view_params_if_data_tracking_is_disabled_in_config() 'price' => 'double', 'active' => 'boolean', 'address' => 'NULL', - 'related' => 'App\User', + 'related' => $this->userClass(), 'roles' => 'Illuminate\Support\Collection: 2 item(s)', 'tags' => 'array: 1 item(s)', 'comments' => 'array: 0 item(s)',