Migrate tests to Pest (#8)
Reviewed-on: #8
This commit was merged in pull request #8.
This commit is contained in:
60
tests/Integration/SQLiteIntegrationTest.php
Normal file
60
tests/Integration/SQLiteIntegrationTest.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||
* @license MIT
|
||||
* @see https://github.com/Zaid-Ajaj/ThrowawayDb The origin concept
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Test\Integration;
|
||||
|
||||
use BitBadger\PDODocument\{Configuration, Custom, Delete, DocumentException, Field};
|
||||
use BitBadger\PDODocument\Mapper\ExistsMapper;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Test\Integration\SQLite\ThrowawayDb;
|
||||
|
||||
/**
|
||||
* Integration Test Class wrapper for SQLite integration tests
|
||||
*/
|
||||
class SQLiteIntegrationTest extends TestCase
|
||||
{
|
||||
/** @var string Database name for throwaway database */
|
||||
static private string $dbName = '';
|
||||
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
self::$dbName = ThrowawayDb::create(false);
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
ThrowawayDb::loadData();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Delete::byFields(ThrowawayDb::TABLE, [ Field::exists(Configuration::$idField)]);
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
ThrowawayDb::destroy(self::$dbName);
|
||||
self::$dbName = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the given named object exist in the database?
|
||||
*
|
||||
* @param string $name The name of the object whose existence should be verified
|
||||
* @return bool True if the object exists, false if not
|
||||
* @throws DocumentException If any is encountered
|
||||
*/
|
||||
protected function dbObjectExists(string $name): bool
|
||||
{
|
||||
return Custom::scalar('SELECT EXISTS (SELECT 1 FROM sqlite_master WHERE name = :name)',
|
||||
[':name' => $name], new ExistsMapper());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user