2019-01-08 21:41:30 +00:00
|
|
|
<?php
|
2019-01-20 03:37:07 +00:00
|
|
|
namespace ActivityPub\Test\TestConfig;
|
2019-01-08 21:41:30 +00:00
|
|
|
|
|
|
|
use ActivityPub\ActivityPub;
|
2019-01-23 23:34:25 +00:00
|
|
|
use ActivityPub\Config\ActivityPubConfig;
|
2019-02-07 03:48:00 +00:00
|
|
|
use ActivityPub\Test\TestConfig\APTestCase;
|
2019-01-08 21:41:30 +00:00
|
|
|
|
2019-02-07 03:48:00 +00:00
|
|
|
abstract class SQLiteTestCase extends APTestCase
|
2019-01-08 21:41:30 +00:00
|
|
|
{
|
2019-02-07 03:48:00 +00:00
|
|
|
use \PHPUnit_Extensions_Database_TestCase_Trait;
|
2019-01-08 21:41:30 +00:00
|
|
|
|
|
|
|
private $pdo = null;
|
|
|
|
private $conn = null;
|
|
|
|
private $dbPath = '';
|
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2019-01-08 22:23:04 +00:00
|
|
|
$dbPath = $this->getDbPath();
|
2019-01-08 21:41:30 +00:00
|
|
|
if ( file_exists( $dbPath ) ) {
|
|
|
|
unlink( $dbPath );
|
|
|
|
}
|
2019-01-23 23:34:25 +00:00
|
|
|
$config = ActivityPubConfig::createBuilder()
|
|
|
|
->setDbConnectionParams( array(
|
|
|
|
'driver' => 'pdo_sqlite',
|
|
|
|
'path' => $dbPath,
|
|
|
|
) )
|
|
|
|
->build();
|
|
|
|
$activityPub = new ActivityPub( $config );
|
2019-01-08 21:41:30 +00:00
|
|
|
$activityPub->updateSchema();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function tearDown()
|
|
|
|
{
|
|
|
|
parent::tearDown();
|
2019-01-08 22:23:04 +00:00
|
|
|
unlink( $this->getDbPath() );
|
2019-01-08 21:41:30 +00:00
|
|
|
unset( $this->conn );
|
|
|
|
unset( $this->pdo );
|
|
|
|
}
|
|
|
|
|
2019-01-08 22:23:04 +00:00
|
|
|
protected function getDbPath()
|
|
|
|
{
|
|
|
|
return dirname( __FILE__ ) . '/db.sqlite';
|
|
|
|
}
|
|
|
|
|
2019-01-08 21:41:30 +00:00
|
|
|
final public function getConnection()
|
|
|
|
{
|
|
|
|
if ( $this->conn === null ) {
|
|
|
|
if ( $this->pdo === null ) {
|
2019-01-08 22:23:04 +00:00
|
|
|
$this->dbPath = $this->getDbPath();
|
2019-01-08 21:41:30 +00:00
|
|
|
$this->pdo = new \PDO( "sqlite:{$this->dbPath}" );
|
|
|
|
}
|
|
|
|
$this->conn = $this->createDefaultDBConnection( $this->pdo, $this->dbPath );
|
|
|
|
}
|
|
|
|
return $this->conn;
|
|
|
|
}
|
|
|
|
}
|
2019-02-07 03:48:00 +00:00
|
|
|
|