Browse Source
- Test files now consist entirely of traits: - General setup trait mocking User class and cleaning up - Driver trait to set up the database connection - Series trait containing tests for the series, independent of driver usedmicrosub
J. King
7 years ago
6 changed files with 94 additions and 63 deletions
@ -0,0 +1,9 @@ |
|||||
|
<?php |
||||
|
declare(strict_types=1); |
||||
|
namespace JKingWeb\Arsse; |
||||
|
|
||||
|
class TestDatabaseFolderSQLite3 extends \PHPUnit\Framework\TestCase { |
||||
|
use Test\Tools, Test\Database\Setup; |
||||
|
use Test\Database\DriverSQLite3; |
||||
|
use Test\Database\SeriesFolder; |
||||
|
} |
@ -0,0 +1,9 @@ |
|||||
|
<?php |
||||
|
declare(strict_types=1); |
||||
|
namespace JKingWeb\Arsse; |
||||
|
|
||||
|
class TestDatabaseUserSQLite3 extends \PHPUnit\Framework\TestCase { |
||||
|
use Test\Tools, Test\Database\Setup; |
||||
|
use Test\Database\DriverSQLite3; |
||||
|
use Test\Database\SeriesUser; |
||||
|
} |
@ -0,0 +1,12 @@ |
|||||
|
<?php |
||||
|
declare(strict_types=1); |
||||
|
namespace JKingWeb\Arsse\Test\Database; |
||||
|
use JKingWeb\Arsse\Data; |
||||
|
use JKingWeb\Arsse\Db\SQLite3\Driver; |
||||
|
|
||||
|
trait DriverSQLite3 { |
||||
|
function setUpDriver() { |
||||
|
Data::$conf->dbSQLite3File = ":memory:"; |
||||
|
$this->drv = new Driver(true); |
||||
|
} |
||||
|
} |
@ -1,11 +1,56 @@ |
|||||
<?php |
<?php |
||||
declare(strict_types=1); |
declare(strict_types=1); |
||||
namespace JKingWeb\Arsse\Test\Db; |
namespace JKingWeb\Arsse\Test\Database; |
||||
|
use JKingWeb\Arsse\User\Driver as UserDriver; |
||||
|
use JKingWeb\Arsse\Data; |
||||
|
use JKingWeb\Arsse\Conf; |
||||
|
use JKingWeb\Arsse\User; |
||||
|
use JKingWeb\Arsse\Database; |
||||
|
use Phake; |
||||
|
|
||||
trait Tools { |
trait Setup { |
||||
protected $drv; |
protected $drv; |
||||
|
protected $data = [ |
||||
|
'arsse_users' => [ |
||||
|
'columns' => [ |
||||
|
'id' => 'str', |
||||
|
'password' => 'str', |
||||
|
'name' => 'str', |
||||
|
'rights' => 'int', |
||||
|
], |
||||
|
'rows' => [ |
||||
|
["admin@example.net", '$2y$10$PbcG2ZR3Z8TuPzM7aHTF8.v61dtCjzjK78gdZJcp4UePE8T9jEgBW', "Hard Lip Herbert", UserDriver::RIGHTS_GLOBAL_ADMIN], // password is hash of "secret" |
||||
|
["jane.doe@example.com", "", "Jane Doe", UserDriver::RIGHTS_NONE], |
||||
|
["john.doe@example.com", "", "John Doe", UserDriver::RIGHTS_NONE], |
||||
|
], |
||||
|
], |
||||
|
]; |
||||
|
|
||||
|
function setUp() { |
||||
|
// establish a clean baseline |
||||
|
$this->clearData(); |
||||
|
// create a default configuration |
||||
|
Data::$conf = new Conf(); |
||||
|
// configure and create the relevant database driver |
||||
|
$this->setUpDriver(); |
||||
|
// create the database interface with the suitable driver |
||||
|
Data::$db = new Database($this->drv); |
||||
|
Data::$db->schemaUpdate(); |
||||
|
// create a mock user manager |
||||
|
Data::$user = Phake::mock(User::class); |
||||
|
Phake::when(Data::$user)->authorize->thenReturn(true); |
||||
|
// call the additional setup method if it exists |
||||
|
if(method_exists($this, "setUpSeries")) $this->setUpSeries(); |
||||
|
} |
||||
|
|
||||
|
function tearDown() { |
||||
|
// call the additional teardiwn method if it exists |
||||
|
if(method_exists($this, "tearDownSeries")) $this->tearDownSeries(); |
||||
|
// clean up |
||||
|
$this->drv = null; |
||||
|
$this->clearData(); |
||||
|
} |
||||
|
|
||||
function primeDatabase(array $data): bool { |
function primeDatabase(array $data): bool { |
||||
$this->drv->begin(); |
$this->drv->begin(); |
||||
foreach($data as $table => $info) { |
foreach($data as $table => $info) { |
Loading…
Reference in new issue