{"id":21992389,"url":"https://github.com/soyhuce/dev-tools","last_synced_at":"2026-02-28T08:32:40.943Z","repository":{"id":43100017,"uuid":"263075145","full_name":"Soyhuce/dev-tools","owner":"Soyhuce","description":"Propose a lot of tools for laravel development","archived":false,"fork":false,"pushed_at":"2024-03-08T15:51:29.000Z","size":164,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-11-24T20:50:10.595Z","etag":null,"topics":["debug","development","hacktoberfest","laravel"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Soyhuce.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-05-11T15:01:30.000Z","updated_at":"2023-11-27T12:21:06.000Z","dependencies_parsed_at":"2024-03-08T15:46:03.563Z","dependency_job_id":"d7610d0d-b724-4e85-a670-ea7b4f747be1","html_url":"https://github.com/Soyhuce/dev-tools","commit_stats":{"total_commits":71,"total_committers":5,"mean_commits":14.2,"dds":"0.11267605633802813","last_synced_commit":"e30abcc05fb70ffa023c7bd0e44f7530f0e3d96e"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soyhuce%2Fdev-tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soyhuce%2Fdev-tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soyhuce%2Fdev-tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soyhuce%2Fdev-tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Soyhuce","download_url":"https://codeload.github.com/Soyhuce/dev-tools/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227206322,"owners_count":17747734,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["debug","development","hacktoberfest","laravel"],"created_at":"2024-11-29T20:13:39.132Z","updated_at":"2026-02-28T08:32:40.910Z","avatar_url":"https://github.com/Soyhuce.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dev Tools\n\nTools for Laravel development\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/soyhuce/dev-tools.svg?style=flat-square)](https://packagist.org/packages/soyhuce/dev-tools)\n[![Total Downloads](https://img.shields.io/packagist/dt/soyhuce/dev-tools.svg?style=flat-square)](https://packagist.org/packages/soyhuce/dev-tools)\n\n- [Installation](#installation)\n- [Available tools](#available-tools)\n    - [Debug](#debug)\n    - [Bottleneck Middleware](#bottleneckmiddleware)\n    - [Image Faker](#image-faker)\n\n## Installation\n\nYou can install the package via composer:\n\n``` bash\n$ composer require soyhuce/dev-tools --dev\n```\n\nLaravel will discover the service provider `Soyhuce\\DevTools\\ServiceProvider`.\n\nAfter installing Dev Tools, publish its assets using:\n\n```bash\nphp artisan vendor:publish --provider=\"Soyhuce\\DevTools\\ServiceProvider\" --tag=\"config\"\n```\n\nYou can also add the facade to your alias in `config\\app.php` :\n```php\n'Debug' =\u003e \\Soyhuce\\DevTools\\Debug\\Debug::class,\n```\n\n## Available tools\n\n - [Debug](#debug) : Debugging tools\n    - [Artisan](#artisan)\n    - [Counter](#counter)\n    - [Database](#database)\n    - [Memory](#memory)\n    - [Message](#message)\n    - [Model](#model)\n    - [Request](#request)\n    - [Response](#response)\n    - [Time](#time)\n    - [Special case of http testing](#special-use-case-of-http-testing)\n - [BottleneckMiddleware](#bottleneckmiddleware) : Middleware simulating a bottleneck\n - [Image faker](#image-faker) : Generates random images locally\n\n### Debug\n\nWhen activated, it allows logging some information on request execution: HTTP request, HTTP response, database requests, timings or even used memory.\n\nAll collected information timestamped and sent in your default log channel, with debug level.\n\nEvery module can be activated or deactivated separately thanks to the config file. You can configure the timestamp format as you wish.\n\n### Artisan\n\nInformation are collected when running artisan commands. Artisan collector will collect the command name, argument and options when collection comes from an artisan command.\n\n```php\nphp artisan make:model User -m -f\n```\n```\n[2020-06-11 08:26:38] local.DEBUG: \n=\u003e [2020-06-11 08:26:38.574492] artisan : 'make:model' User -m -f\n\n```\n\n#### Counter\n\nThe counter can help to count stuffs. The counter does not need to exist before incrementing it. As it is initialized with 0. \n\n```php\n\u003c?php\n\nfor ($i=0; $i\u003c100; $i++) {\n    if (rand(0,1) === 0) {\n        \\Soyhuce\\DevTools\\Debug\\Debug::incrementCounter('zeros');\n    } else {\n        \\Soyhuce\\DevTools\\Debug\\Debug::incrementCounter('ones');\n    }\n}\n```\n```\n[2020-06-10 11:41:08] testing.DEBUG: \n=\u003e [2020-06-10 11:41:08.819242] counter : zeros -\u003e 56\n=\u003e [2020-06-10 11:41:08.819243] counter : ones -\u003e 44\n```\n\nCounters can be incremented by more than one.\n```php\n\u003c?php\n\nfunction foo(array $values)\n{\n    \\Soyhuce\\DevTools\\Debug\\Debug::incrementCounter('foo', count($values));\n}\n\nfoo([1,2,3]);\nfoo([4,5]);\nfoo([6,7,8,9]);\n```\n```\n[2020-06-10 11:47:18] testing.DEBUG: \n=\u003e [2020-06-10 11:47:18.252515] counter : foo -\u003e 9\n```\n\n#### Database\n\nEvery executed database query is collected with its bindings and duration. The total number of executed queries is also logged.\n\n```\n[2020-06-10 11:56:17] testing.DEBUG: \n=\u003e [2020-06-10 11:56:17.897045] database : select * from \"users\" -\u003e 290μs\n=\u003e [2020-06-10 11:56:17.898037] database : select \"id\", \"name\" from \"users\" where \"email\" like '%@foo.com' -\u003e 120μs\n=\u003e [2020-06-10 11:56:17.901442] database : query executed : 2\n```\n\nYou can define a threshold and raise a warning if the number of executed queries is above this threshold.\n```\n[2020-06-10 12:05:47] testing.DEBUG: \n=\u003e [2020-06-10 12:05:47.119866] database : select * from \"users\" -\u003e 280μs\n=\u003e [2020-06-10 12:05:47.120715] database : select \"id\", \"name\" from \"users\" where \"email\" like '%@foo.com' -\u003e 80μs\n=\u003e [2020-06-10 12:05:47.124023] database : query executed : 2\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! database : Number of queries exceeded max 1 allowed : 2 !!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n```\n\n#### Memory\n\nThe Memory collector will collect the memory peak usage and add it to the log.\n\n```\n[2020-06-10 12:09:16] local.DEBUG: \n=\u003e [2020-06-10 12:09:16.593738] memory : 16.22Mo\n```\n\nYou can define a threshold and raise a warning if the memory peak usage id above this threshold.\n```\n[2020-06-10 12:10:47] testing.DEBUG: \n=\u003e [2020-06-10 12:10:47.391816] memory : 18.27Mo\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! memory : Memory exceeded max 16Mo allowed : 18.27Mo !!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  \n```\n\n#### Message\n\nYou can send messages in the debugger flow calling `Debug::message`\n\n```php\n\u003c?php\nfunction foo(string $arg) \n{\n    \\Soyhuce\\DevTools\\Debug\\Debug::message(\"foo with '${arg}'\");\n}\n\nfoo('bar');\n```\n```\n[2020-06-10 12:20:15] testing.DEBUG: \n=\u003e [2020-06-10 12:20:15.944849] message : foo with 'bar'\n```\n\n#### Model\n\nWhen enabled, the collector allows you to count the number of models retrieved from the database during the queries.\n\n```\n[2020-06-10 12:36:12] testing.DEBUG: \n=\u003e [2020-06-10 12:36:12.155134] model : App\\User -\u003e 8\n=\u003e [2020-06-10 12:36:12.156016] model : App\\Post -\u003e 13\n```\n\n#### Request\n\nRequest data can be collected. We store HTTP verb, url and parameters.\n\n```php\nclass ExampleTest extends TestCase\n{\n    public function testBasicTest()\n    {\n        $this-\u003eget('/?foo=bar')-\u003eassertOk();\n    }\n}\n```\n```\n[2020-06-10 12:25:28] testing.DEBUG: \n=\u003e [2020-06-10 12:25:28.130223] request : GET http://localhost\n{\n    \"foo\": \"bar\"\n}\n```\n\n#### Response\n\nResponse can also be collecter with its status code and body.\n\n```php\nclass ExampleTest extends TestCase\n{\n    public function testBasicTest()\n    {\n        $this-\u003egetJson('api/users/1')-\u003eassertOk();\n    }\n}\n```\n```\n[2020-06-10 12:27:21] testing.DEBUG: \n=\u003e [2020-06-10 12:27:21.440427] response : 200 -\u003e \n{\"id\":1,\"name\":\"Melyssa Kautzer\",\"email\":\"junius.steuber@example.net\",\"email_verified_at\":\"2020-06-09T13:06:39.000000Z\",\"created_at\":\"2020-06-09T13:06:39.000000Z\",\"updated_at\":\"2020-06-09T13:06:39.000000Z\"}\n```\n\n#### Time\n\nTime collector will automatically measure booting time (laravel) and application time (your application).\n \nIt is possible to time performance portions via the facade :\n```php\n\u003c?php\n\\Soyhuce\\DevTools\\Debug\\Debug::startMeasure('someOperation');\n$value = someOperation();\n\\Soyhuce\\DevTools\\Debug\\Debug::stopMeasure('someOperation');\n```\n```\n[2020-06-10 12:48:02] testing.DEBUG: \n=\u003e [2020-06-10 12:48:02.295700] time : Booting -\u003e 98.57ms\n=\u003e [2020-06-10 12:48:02.513956] time : someOperation -\u003e 816.11μs\n=\u003e [2020-06-10 12:48:02.517676] time : Application -\u003e 222.05ms\n```\n\n`startMeasure` and `stopMeasure` calls do not have to be in the part of code, but a measure cannot be stopped if not started (nor started if already running).\n  \nAbove example can be simplified using `Debug::measuring` method :\n```php\n\u003c?php\n$value = \\Soyhuce\\DevTools\\Debug\\Debug::measuring('someOperation', function () {\n    return someOperation();\n});\n// Or even shorter :\n$value = Debug::measuring('someOperation', fn () =\u003e someOperation());\n```\n  \nAll running measurements are stopped before logging.\n\nYou can also measure multiple times with the same key. All measures are stored together, and the log will provide you some statistics.\n\n```php\n\u003c?php\nforeach($users as $user) {\n    \\Soyhuce\\DevTools\\Debug\\Debug::measuring('updateUser', fn () =\u003e $this-\u003eupdate($user));\n}\n```\n```\n[2020-06-10 12:58:18] testing.DEBUG: \n=\u003e [2020-06-10 12:58:17.157334] time : Booting -\u003e 86.97ms\n=\u003e [2020-06-10 12:58:18.251381] time : updateUser -\u003e 904.28ms cumulated on 12 entries (avg : 75.36ms - min : 67.8ms - max : 90ms - std : 5.4ms)\n=\u003e [2020-06-10 12:58:18.259324] time : Application -\u003e 1.1s\n```\n\nFinally, you can define a threshold and raise a warning if the application duration is above this threshold.\n```\n[2020-06-10 12:58:18] testing.DEBUG: \n=\u003e [2020-06-10 12:58:17.157334] time : Booting -\u003e 86.97ms\n=\u003e [2020-06-10 12:58:18.251381] time : updateUser -\u003e 904.28ms cumulated on 12 entries (avg : 75.36ms - min : 67.8ms - max : 90ms - std : 5.4ms)\n=\u003e [2020-06-10 12:58:18.259324] time : Application -\u003e 1.1s\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! time : Application duration exceeded max 500ms allowed : 1.1s !!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n```\n\n#### Special use case of HTTP testing\n\nWhen doing http testing, it is common to bootstrap database or execute some operation we do not want to add to our debug log.\n\nFor example:\n```php\n/** @test */\npublic function userIsFetched()\n{\n    $user = factory(\\App\\User::class)-\u003ecreate();\n    \n    $this-\u003eputJson(\"api/users/{$user-\u003eid}\",[\n            'name' =\u003e 'John Doe'\n        ])\n        -\u003eassertOk();\n    \n    $this-\u003eassertDatabaseHas('users',[\n        'id' =\u003e $user-\u003eid,\n        'name' =\u003e 'John Doe'\n    ]);    \n}\n```\n\nWe are actually not interested in (for example) database queries of `factory(\\App\\User::class)-\u003ecreate()` nor `assertDatabaseHas`.\n\nThis package will take care of drop any collected information during bootstrap and return only interesting ones i.e. what occurred in `$this-\u003eputJson(\"api/users/{$user-\u003eid}\",['name' =\u003e 'John Doe'])`.\nYou just have to ensure that you are using `testing` environment during your tests (which should already be your case as it is Laravel default).\n```\n[2020-06-10 13:47:11] testing.DEBUG: \n=\u003e [2020-06-10 13:47:11.522116] time : Booting -\u003e 522.11ms\n=\u003e [2020-06-10 13:47:11.522194] request : GET http://localhost/user/25\n=\u003e [2020-06-10 13:47:11.528122] database : select * from \"users\" where \"id\" = '25' limit 1 -\u003e 160μs\n=\u003e [2020-06-10 13:47:11.528266] model : App\\User -\u003e 1\n=\u003e [2020-06-10 13:47:11.532207] response : 200 -\u003e \n{\"id\":25,\"name\":\"Daisha Schuppe\",\"email\":\"sauer.jarrell@example.com\",\"email_verified_at\":\"2020-06-10T13:47:11.000000Z\",\"created_at\":\"2020-06-10T13:47:11.000000Z\",\"updated_at\":\"2020-06-10T13:47:11.000000Z\"}\n=\u003e [2020-06-10 13:47:11.532334] memory : 20Mo\n=\u003e [2020-06-10 13:47:11.532339] database : query executed : 1\n=\u003e [2020-06-10 13:47:11.532344] time : Application -\u003e 10.23ms\n``` \n\n\n### BottleneckMiddleware\n\nThis middleware adds some latency to your requests, server side. It can be useful to check how your application behaves when the user does not have a good network connection.\n\n`Soyhuce\\DevTools\\Middlewares\\BottleneckMiddleware` can be used as a classic middleware.\nTo use it, just add the middleware in your `App/Http/Kernel.php` or in your route file(s).\n\nYou can modify bottleneck duration in `config/dev-tools.php` file.\n\nYou also may want to apply it for only ajax requests. If so, adjust the `only_ajax` value. Please ensure that the ajax requests are sent with the `X-Requested-With` header set to `XMLHttpRequest`.\n\n### Image Faker\n\nSometimes you want to generate images locally for testing, placeholders, ...\n\nYou can then use `Soyhuce\\DevTools\\Faker\\Image` to do so. For this, you have to install `intervention/image`.\n\n```\nImage::generate(int $width = 640, int $height = 640, ?string $text = null, string $encoding = 'jpg'): \\Intervention\\Image\\Image\n```\n\nIt will generate an image with random color and with the given text (or \"width x height\"). For example :\n\n`Image::generate(200, 150)`\n\n![](assets/doc/fake_image_200x150.jpg)\n\n`Image::generate(300, 100, 'The colors are not that good', 'png')`\n\n![](assets/doc/fake_image_text.png)\n\nSee [intervention/image documentation](http://image.intervention.io/) to know how to use returned image.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoyhuce%2Fdev-tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoyhuce%2Fdev-tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoyhuce%2Fdev-tools/lists"}