PHP code example of metamodels / phpunit-contao-database
1. Go to this page and download the library: Download metamodels/phpunit-contao-database 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/ */
metamodels / phpunit-contao-database example snippets
class MyTest extends \PHPUnit_Framework_TestCase
{
/**
* Register the database.
*
* @return void
*/
public function setUp()
{
\MetaModels\Test\Contao\Database::register();
}
}
$objectToTest = new ClassToTest();
$database = \MetaModels\Test\Contao\Database::getNewTestInstance();
// Inject the database into the instance.
$objectToTest->setDatabase($database);
$database
->getQueryCollection()
->theQuery('SELECT * FROM test WHERE id=?')
->with(1)
->result()
->addRow(
array(
'id' => 1,
'tstamp' => 343094400,
'title' => 'test'
),
);
// This method will call the above query internally and will receive the given result.
$result = $objectToTest->testMethod();
$this->assertEquals(1, $result->getId());
$this->assertEquals(343094400, $result->getModificationTime());
$this->assertEquals('test', $result->getTitle());
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.