PHP code example of unicorn / lumen-testbench

1. Go to this page and download the library: Download unicorn/lumen-testbench 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/ */

    

unicorn / lumen-testbench example snippets




class TestCase extends Orchestra\Testbench\TestCase
{
    //
}

protected function getPackageProviders($app)
{
    return ['Acme\AcmeServiceProvider'];
}

protected function getPackageAliases($app)
{
    return [
        'Acme' => 'Acme\Facade'
    ];
}

/**
 * Setup the test environment.
 */
protected function setUp()
{
    parent::setUp();

    // Your code here
}

/**
 * Define environment setup.
 *
 * @param  \Illuminate\Foundation\Application  $app
 * @return void
 */
protected function getEnvironmentSetUp($app)
{
    // Setup default database to use sqlite :memory:
    $app['config']->set('database.default', 'testbench');
    $app['config']->set('database.connections.testbench', [
        'driver'   => 'sqlite',
        'database' => ':memory:',
        'prefix'   => '',
    ]);
}

protected function useMySqlConnection($app) 
{
    $app->config->set('database.default', 'mysql');
}

protected function useSqliteConnection($app)
{
    $app->config->set('database.default', 'sqlite');
}

/**
 * @environment-setup useMySqlConnection
 */
public function testItCanBeConnectedWithMySql()
{
    // write your tests
}

/**
 * @environment-setup useSqliteConnection
 */
public function testItCanBeConnectedWithSqlite()
{
    // write your tests
}

/**
 * Resolve application Console Kernel implementation.
 *
 * @param  \Illuminate\Foundation\Application  $app
 * @return void
 */
protected function resolveApplicationConsoleKernel($app)
{
    $app->singleton('Illuminate\Contracts\Console\Kernel', 'Acme\Testbench\Console\Kernel');
}

/**
 * Resolve application HTTP Kernel implementation.
 *
 * @param  \Illuminate\Foundation\Application  $app
 * @return void
 */
protected function resolveApplicationHttpKernel($app)
{
    $app->singleton('Illuminate\Contracts\Http\Kernel', 'Acme\Testbench\Http\Kernel');
}

/**
 * Get application timezone.
 *
 * @param  \Illuminate\Foundation\Application  $app
 * @return string|null
 */
protected function getApplicationTimezone($app)
{
    return 'Asia/Kuala_Lumpur';
}

$this->artisan('migrate', ['--database' => 'testbench'])->run();

$this->loadLaravelMigrations();

$this->loadLaravelMigrations(['--database' => 'testbench']);

/**
 * Setup the test environment.
 */
protected function setUp()
{
    parent::setUp();

    $this->loadMigrationsFrom(__DIR__ . '/database/migrations');
    
    // and other test setup steps you need to perform
}

$this->withFactories(__DIR__.'/factories');
xml
<phpunit>

    // ...

    <php>
        <env name="DB_CONNECTION" value="testing"/>
    </php>

</phpunit>