PHP code example of soyhuce / dev-tools

1. Go to this page and download the library: Download soyhuce/dev-tools library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

soyhuce / dev-tools example snippets


'Debug' => \Soyhuce\DevTools\Debug\Debug::class,

php artisan make:model User -m -f



for ($i=0; $i<100; $i++) {
    if (rand(0,1) === 0) {
        \Soyhuce\DevTools\Debug\Debug::incrementCounter('zeros');
    } else {
        \Soyhuce\DevTools\Debug\Debug::incrementCounter('ones');
    }
}



function foo(array $values)
{
    \Soyhuce\DevTools\Debug\Debug::incrementCounter('foo', count($values));
}

foo([1,2,3]);
foo([4,5]);
foo([6,7,8,9]);


function foo(string $arg) 
{
    \Soyhuce\DevTools\Debug\Debug::message("foo with '${arg}'");
}

foo('bar');

class ExampleTest extends TestCase
{
    public function testBasicTest()
    {
        $this->get('/?foo=bar')->assertOk();
    }
}

class ExampleTest extends TestCase
{
    public function testBasicTest()
    {
        $this->getJson('api/users/1')->assertOk();
    }
}


\Soyhuce\DevTools\Debug\Debug::startMeasure('someOperation');
$value = someOperation();
\Soyhuce\DevTools\Debug\Debug::stopMeasure('someOperation');


$value = \Soyhuce\DevTools\Debug\Debug::measuring('someOperation', function () {
    return someOperation();
});
// Or even shorter :
$value = Debug::measuring('someOperation', fn () => someOperation());


foreach($users as $user) {
    \Soyhuce\DevTools\Debug\Debug::measuring('updateUser', fn () => $this->update($user));
}

/** @test */
public function userIsFetched()
{
    $user = factory(\App\User::class)->create();
    
    $this->putJson("api/users/{$user->id}",[
            'name' => 'John Doe'
        ])
        ->assertOk();
    
    $this->assertDatabaseHas('users',[
        'id' => $user->id,
        'name' => 'John Doe'
    ]);    
}
bash
php artisan vendor:publish --provider="Soyhuce\DevTools\ServiceProvider" --tag="config"

[2020-06-10 12:10:47] testing.DEBUG: 
=> [2020-06-10 12:10:47.391816] memory : 18.27Mo
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! memory : Memory exceeded max 16Mo allowed : 18.27Mo !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  

[2020-06-10 12:48:02] testing.DEBUG: 
=> [2020-06-10 12:48:02.295700] time : Booting -> 98.57ms
=> [2020-06-10 12:48:02.513956] time : someOperation -> 816.11μs
=> [2020-06-10 12:48:02.517676] time : Application -> 222.05ms

[2020-06-10 12:58:18] testing.DEBUG: 
=> [2020-06-10 12:58:17.157334] time : Booting -> 86.97ms
=> [2020-06-10 12:58:18.251381] time : updateUser -> 904.28ms cumulated on 12 entries (avg : 75.36ms - min : 67.8ms - max : 90ms - std : 5.4ms)
=> [2020-06-10 12:58:18.259324] time : Application -> 1.1s

[2020-06-10 12:58:18] testing.DEBUG: 
=> [2020-06-10 12:58:17.157334] time : Booting -> 86.97ms
=> [2020-06-10 12:58:18.251381] time : updateUser -> 904.28ms cumulated on 12 entries (avg : 75.36ms - min : 67.8ms - max : 90ms - std : 5.4ms)
=> [2020-06-10 12:58:18.259324] time : Application -> 1.1s
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! time : Application duration exceeded max 500ms allowed : 1.1s !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!