PHP code example of cspray / database-testing-pdo

1. Go to this page and download the library: Download cspray/database-testing-pdo 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/ */

    

cspray / database-testing-pdo example snippets


 declare(strict_types=1);

namespace Cspray\DatabaseTesting\Pdo\Demo;

use Cspray\DatabaseTesting\ConnectionAdapter\ConnectionAdapterConfig;
use Cspray\DatabaseTesting\DatabaseCleanup\TransactionWithRollback;
use Cspray\DatabaseTesting\RequiresTestDatabase;
use Cspray\DatabaseTesting\Pdo\Postgres\PostgresConnectionAdapterFactory;
use PHPUnit\Framework\TestCase;

#[RequiresTestDatabase(
    new PostgresConnectionAdapterFactory(new ConnectionAdapterConfig(
        'my_database',
        '127.0.0.1',
        5432,
        'my_user',
        'my_password'
    )),
    new TransactionWithRollback()
)]
final class PostgresDemoTest extends TestCase {

}

 declare(strict_types=1);

namespace Cspray\DatabaseTesting\Pdo\Demo;

use Cspray\DatabaseTesting\ConnectionAdapter\ConnectionAdapterConfig;
use Cspray\DatabaseTesting\DatabaseCleanup\TransactionWithRollback;
use Cspray\DatabaseTesting\RequiresTestDatabase;
use Cspray\DatabaseTesting\Pdo\Postgres\PostgresConnectionAdapterFactory;
use PHPUnit\Framework\TestCase;

#[RequiresTestDatabase(
    new PostgresConnectionAdapterFactory(new ConnectionAdapterConfig(
        'my_database',
        '127.0.0.1',
        5432,
        'my_user',
        'my_password'
    )),
    new TransactionWithRollback()
)]
final class PostgresDemoTest extends TestCase {

}

 declare(strict_types=1);

namespace Cspray\DatabaseTesting\Pdo\Demo;

use Cspray\DatabaseTesting\ConnectionAdapter\ConnectionAdapterConfig;
use Cspray\DatabaseTesting\DatabaseCleanup\TransactionWithRollback;
use Cspray\DatabaseTesting\RequiresTestDatabase;
use Cspray\DatabaseTesting\Pdo\Sqlite\SqliteConnectionAdapterFactory;
use PHPUnit\Framework\TestCase;

#[RequiresTestDatabase(
    // The default file path for Sqlite is an in-memory database
    // Provide the path to the SQL file that should be loaded when
    // the database is created
    // if you're using a persisted file, provide it as the first argument
    // and remove the initial schema path
    new SqliteConnectionAdapterFactory(
        initialSchemaPath: __DIR__ . '/schemas/sqlite.sql'
    ),
    new TransactionWithRollback()
)]
final class SqliteDemoTest extends TestCase {

}