PHP code example of srlabs / laravel-testing-utilities

1. Go to this page and download the library: Download srlabs/laravel-testing-utilities 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/ */

    

srlabs / laravel-testing-utilities example snippets


'providers' => [
    // ...
    'SRLabs\Utilities\UtilitiesServiceProvider'
    // ...
],


use SRLabs\Utilities\Traits\TestingDatabaseTrait;

class FooTest extends TestCase {

    use TestingDatabaseTrait;

    public function setUp()
    {
      parent::setUp();

      $this->prepareDatabase('staging', 'testing');
    }

    public function testSomethingIsTrue()
    {
        $this->assertTrue(true);
    }

}



define('ARTISAN_PATH', realpath(__DIR__ . '/../artisan'));

/*
|--------------------------------------------------------------------------
| Check for new migrations and reseed if necessary
|--------------------------------------------------------------------------
|
*/

passthru('(php '.ARTISAN_PATH.' migrate:status --database='.(getenv('DB_CONNECTION') ?: 'testing').' | grep -q "| N    |") && php '.ARTISAN_PATH.' utility:testdb');

/*
|--------------------------------------------------------------------------
| Include Standard Autoload File
|--------------------------------------------------------------------------
|
*/

app/config/app.php
config/database.php
bash
$ php artisan utility:testdb
bash
$ php artisan utility:testdb sqlite_testing
bash
$ php artisan utility:testdb sqlite_testing --class="SentinelDatabaseSeeder"
xml
<phpunit ...
         bootstrap="bootstrap/testing.php"
         ...
>
...
    <php>
        ...
        <!-- Change this to your connection name (if customized) -->
        <env name="DB_CONNECTION" value="testing"/>
    </php>
</phpunit>