1. Go to this page and download the library: Download hi-media/pdo-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/ */
public function testSimple ()
{
// Load SQL dump file, possibly gzipped (.gz):
$this->loadSqlDumpFile('/path/to/dump.sql');
// calls to tested program…
// Asserts that SQL query result is equal to CSV file content:
$this->assertQueryResultEqualsCsv('SELECT … FROM A', '/path/to/expected.csv');
// Asserts that SQL query doesn't return any rows:
$this->assertQueryReturnsNoRows('SELECT * FROM B');
// Optional clean up:
$this->loadSqlDumpFile('/path/to/clean_up.sql');
}
public function testWithMockDb ()
{
/* @var $oMockPDO \Himedia\DW\Tests\Mocks\PDO|\PHPUnit_Framework_MockObject_MockObject */
$oMockPDO = $this->getMock('Himedia\PDOTools\Mocks\PDO', array('query'));
$that = $this;
$oMockPDO->expects($this->any())->method('query')->will(
$this->returnCallback(
function ($sQuery) use ($that, $sResourcePath) {
return $that->getPdoStmtMock(
$sQuery,
array(
'SELECT … FROM A' => '/path/to/fixture.csv',
'SELECT … FROM B' => function () {
static $i = 0;
return ++$i > 10 ? false : array('id' => $i, 'name' => md5(rand()));
}
)
);
}
)
);
// injection of $oMockPDO, to mock third-party database…
// calls to tested program…
// assertions…
}