diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml
index 29c95cc..2ceb3de 100644
--- a/.github/workflows/continuous-integration.yml
+++ b/.github/workflows/continuous-integration.yml
@@ -44,10 +44,37 @@ jobs:
matrix:
php: ['8.1', '8.2', '8.3', '8.4']
dependencies: ['lowest', 'highest']
+ testsuite: ['unit', 'mysql', 'sqlite']
name: Tests
+ services:
+ mysql:
+ # only setup service in mysql testsuite
+ image: ${{ matrix.testsuite == 'mysql' && 'mysql:8.0.31' || '' }}
+ ports:
+ - '3306:3306'
+ env:
+ MYSQL_ROOT_PASSWORD: mysql
+ MYSQL_DATABASE: access_test_db
+ MYSQL_ROOT_HOST: '%'
+ options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
+
steps:
+ - name: Setup MySQL `sql_mode`
+ if: ${{ matrix.testsuite == 'mysql' }}
+ # default sql mode minus ONLY_FULL_GROUP_BY
+ run: mysql -h 127.0.0.1 --port 3306 -u root -pmysql -e "SET GLOBAL sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'"
+
+ - name: Setup MySQL credentials
+ if: ${{ matrix.testsuite == 'mysql' }}
+ run: |
+ echo "MYSQL_DATABASE_HOST=127.0.0.1" >> $GITHUB_ENV
+ echo "MYSQL_DATABASE_PORT=3306" >> $GITHUB_ENV
+ echo "MYSQL_DATABASE_USER=root" >> $GITHUB_ENV
+ echo "MYSQL_DATABASE_PASSWORD=mysql" >> $GITHUB_ENV
+ echo "MYSQL_DATABASE_NAME=access_test_db" >> $GITHUB_ENV
+
- uses: actions/checkout@v4
- name: Install PHP
@@ -64,7 +91,7 @@ jobs:
dependency-versions: ${{ matrix.dependencies }}
- name: Run test suite
- run: composer run-script test -- --display-deprecations --display-notices --display-warnings
+ run: composer run-script test -- --display-deprecations --display-notices --display-warnings --testsuite ${{ matrix.testsuite }}
- name: Upload code coverage
env:
diff --git a/composer.json b/composer.json
index 4d7c3e3..f0c4e96 100644
--- a/composer.json
+++ b/composer.json
@@ -25,7 +25,11 @@
"autoload-dev": {
"psr-4": {
"Benchmarks\\": "benchmarks",
- "Tests\\": "tests"
+ "Tests\\Base\\": "tests/base",
+ "Tests\\Fixtures\\": "tests/fixtures",
+ "Tests\\Mysql\\": "tests/mysql",
+ "Tests\\Sqlite\\": "tests/sqlite",
+ "Tests\\Unit\\": "tests/unit"
}
},
"scripts": {
diff --git a/data/.keep b/data/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/docker-compose.yaml b/docker-compose.yaml
new file mode 100644
index 0000000..1435e11
--- /dev/null
+++ b/docker-compose.yaml
@@ -0,0 +1,11 @@
+services:
+ db:
+ image: mysql:8.0.31
+ volumes:
+ - ./data/db:/var/lib/mysql:cached
+ ports:
+ - '3306:3306'
+ # default sql mode minus ONLY_FULL_GROUP_BY
+ command: --sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
+ environment:
+ MYSQL_ROOT_PASSWORD: mysql
diff --git a/phpunit.xml b/phpunit.xml
index 64e0e1b..b6a4f16 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -13,11 +13,28 @@
-
- tests/
+
+ tests/mysql
+
+
+
+ tests/sqlite
+
+
+
+ tests/unit
+
+
+
+
+
+
+
+
+
setMessage('Something happened!');
@@ -39,7 +39,7 @@ public function testClockRoundtrip(): void
{
$now = new DateTimeImmutable('2023-05-23 00:00:00');
$clock = new MockClock($now);
- $db = self::createDatabaseWithMockClock($clock);
+ $db = static::createDatabaseWithMockClock($clock);
$user = new User();
$user->setName('Dave');
@@ -53,7 +53,7 @@ public function testClockUpdate(): void
{
$now = new DateTimeImmutable('2023-05-23 00:00:00');
$clock = new MockClock($now);
- $db = self::createDatabaseWithMockClock($clock);
+ $db = static::createDatabaseWithMockClock($clock);
$user = new User();
$user->setName('Dave');
@@ -78,7 +78,7 @@ public function testClockSoftDelete(): void
{
$now = new DateTimeImmutable('2023-05-23 00:00:00');
$clock = new MockClock($now);
- $db = self::createDatabaseWithMockClock($clock);
+ $db = static::createDatabaseWithMockClock($clock);
$user = new User();
$user->setName('Dave');
diff --git a/tests/CollectionTest.php b/tests/base/BaseCollectionTest.php
similarity index 90%
rename from tests/CollectionTest.php
rename to tests/base/BaseCollectionTest.php
index 569748d..7694c46 100644
--- a/tests/CollectionTest.php
+++ b/tests/base/BaseCollectionTest.php
@@ -11,25 +11,25 @@
declare(strict_types=1);
-namespace Tests;
+namespace Tests\Base;
use Access\Batch;
use Access\Collection;
use Access\Exception;
use Access\Clause;
use Access\Query\Select;
+use PHPUnit\Framework\TestCase;
-use Tests\AbstractBaseTestCase;
use Tests\Fixtures\Entity\Project;
use Tests\Fixtures\Entity\User;
use Tests\Fixtures\Repository\ProjectRepository;
use Tests\Fixtures\Repository\UserRepository;
-class CollectionTest extends AbstractBaseTestCase
+abstract class BaseCollectionTest extends TestCase implements DatabaseBuilderInterface
{
public function testBatch(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -63,7 +63,7 @@ public function testBatch(): void
public function testCollection(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -93,7 +93,7 @@ public function testCollection(): void
public function testEmptyCollection(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -112,7 +112,7 @@ public function testEmptyCollection(): void
public function testMergeCollection(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -127,7 +127,7 @@ public function testMergeCollection(): void
public function testGroupByCollection(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -161,7 +161,7 @@ public function testGroupByCollection(): void
public function testSortCollection(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -180,7 +180,7 @@ public function testSortCollection(): void
public function testMapCollection(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -195,7 +195,7 @@ public function testMapCollection(): void
public function testReduceCollection(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -210,7 +210,7 @@ public function testReduceCollection(): void
public function testFromIterableCollection(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -228,7 +228,7 @@ public function testFromIterableCollection(): void
public function testCollectionNoSet(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -242,7 +242,7 @@ public function testCollectionNoSet(): void
public function testCollectionNoUnset(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -258,7 +258,7 @@ public function testCollectionNoUnset(): void
public function testGroupedCollectionNoSet(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -276,7 +276,7 @@ public function testGroupedCollectionNoSet(): void
public function testGroupedCollectionNoUnset(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -298,7 +298,7 @@ public function testGroupedCollectionNoUnset(): void
public function testInversedRefs(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var UserRepository $userRepo */
$userRepo = $db->getRepository(User::class);
@@ -313,7 +313,7 @@ public function testInversedRefs(): void
public function testInversedRefsEmpty(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var UserRepository $userRepo */
$userRepo = $db->getRepository(User::class);
@@ -328,7 +328,7 @@ public function testInversedRefsEmpty(): void
public function testInversedRefsInvalidFieldName(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var UserRepository $userRepo */
$userRepo = $db->getRepository(User::class);
@@ -344,7 +344,7 @@ public function testInversedRefsInvalidFieldName(): void
public function testSelectQueryWithCollection(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var UserRepository $userRepo */
$userRepo = $db->getRepository(User::class);
@@ -361,7 +361,7 @@ public function testSelectQueryWithCollection(): void
public function testCollectionFirst(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -389,7 +389,7 @@ public function testCollectionFirst(): void
public function testCollectionContains(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var User $user */
$user = $db->findOne(User::class, 1);
@@ -410,7 +410,7 @@ public function testCollectionContains(): void
public function testCollectionHasEntityWith(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -425,7 +425,7 @@ public function testCollectionHasEntityWith(): void
public function testCollectionEmptyFirst(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -440,7 +440,7 @@ public function testCollectionEmptyFirst(): void
public function testSimpleOrderClause(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -457,7 +457,7 @@ public function testSimpleOrderClause(): void
public function testSimpleConditionClause(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -474,7 +474,7 @@ public function testSimpleConditionClause(): void
public function testMultiClause(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -496,7 +496,7 @@ public function testMultiClause(): void
public function testDeduplication(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var UserRepository $userRepo */
$userRepo = $db->getRepository(User::class);
diff --git a/tests/CursorTest.php b/tests/base/BaseCursorTest.php
similarity index 69%
rename from tests/CursorTest.php
rename to tests/base/BaseCursorTest.php
index f262e35..2589552 100644
--- a/tests/CursorTest.php
+++ b/tests/base/BaseCursorTest.php
@@ -11,81 +11,24 @@
declare(strict_types=1);
-namespace Tests;
+namespace Tests\Base;
use Access\Batch;
use Access\Query\Cursor\CurrentIdsCursor;
+use Access\Query\Cursor\MaxValueCursor;
+use Access\Query\Cursor\MinValueCursor;
use Access\Query\Cursor\PageCursor;
use Access\Query\Select;
-use Tests\AbstractBaseTestCase;
+use PHPUnit\Framework\TestCase;
use Tests\Fixtures\Entity\Project;
use Tests\Fixtures\Repository\ProjectRepository;
-use Access\Query\Cursor\MaxValueCursor;
-use Access\Query\Cursor\MinValueCursor;
+use Tests\Sqlite\AbstractBaseTestCase;
-class CursorTest extends AbstractBaseTestCase
+abstract class BaseCursorTest extends TestCase implements DatabaseBuilderInterface
{
- public function testPageCursor(): void
- {
- $query = new Select(Project::class);
- $query->orderBy('id ASC');
-
- $cursor = new PageCursor();
- $query->applyCursor($cursor);
-
- $this->assertEquals(PageCursor::DEFAULT_PAGE_SIZE, $cursor->getPageSize());
-
- $this->assertEquals(
- 'SELECT `projects`.* FROM `projects` ORDER BY id ASC LIMIT 50 OFFSET 0',
- $query->getSql(),
- );
-
- $this->assertEquals([], $query->getValues());
-
- $pageSize = 20;
-
- $cursor->setPage(3);
- $cursor->setPageSize($pageSize);
- $query->applyCursor($cursor);
-
- $this->assertEquals($pageSize, $cursor->getPageSize());
-
- $this->assertEquals(
- 'SELECT `projects`.* FROM `projects` ORDER BY id ASC LIMIT 20 OFFSET 40',
- $query->getSql(),
- );
- }
-
- public function testCurrentIdsCursor(): void
- {
- $query = new Select(Project::class);
- $query->orderBy('RANDOM()');
-
- $cursor = new CurrentIdsCursor();
- $query->applyCursor($cursor);
-
- $this->assertEquals(
- 'SELECT `projects`.* FROM `projects` ORDER BY RAND() LIMIT 50',
- $query->getSql(),
- );
-
- $this->assertEquals([], $query->getValues());
-
- $cursor->addCurrentIds([1, 2]);
-
- $query->applyCursor($cursor);
-
- $this->assertEquals(
- 'SELECT `projects`.* FROM `projects` WHERE `projects`.`id` NOT IN (:w0, :w1) ORDER BY RAND() LIMIT 50',
- $query->getSql(),
- );
-
- $this->assertEquals(['w0' => 1, 'w1' => 2], $query->getValues());
- }
-
public function testSelectPageCursor(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -124,7 +67,7 @@ public function testSelectPageCursor(): void
public function testBatchedPageCursor(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -171,7 +114,7 @@ public function testBatchedPageCursor(): void
public function testSelectCurrentIdsCursor(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -210,7 +153,7 @@ public function testSelectCurrentIdsCursor(): void
public function testBatchedCurrentIdsCursor(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -255,75 +198,9 @@ public function testBatchedCurrentIdsCursor(): void
$this->assertCount(0, $expectedQueries);
}
- public function testMinValueCursor(): void
- {
- $query = new Select(Project::class);
- $query->orderBy('id DESC');
-
- $cursor = new MinValueCursor(field: 'projects.id');
- $query->applyCursor($cursor);
-
- $this->assertEquals(PageCursor::DEFAULT_PAGE_SIZE, $cursor->getPageSize());
-
- $this->assertEquals(
- 'SELECT `projects`.* FROM `projects` ORDER BY id DESC LIMIT 50',
- $query->getSql(),
- );
-
- $this->assertEquals([], $query->getValues());
-
- $pageSize = 20;
-
- $cursor->setOffset(3);
- $cursor->setPageSize($pageSize);
- $query->applyCursor($cursor);
-
- $this->assertEquals($pageSize, $cursor->getPageSize());
-
- $this->assertEquals(
- 'SELECT `projects`.* FROM `projects` WHERE `projects`.`id` < :w0 ORDER BY id DESC LIMIT 20',
- $query->getSql(),
- );
-
- $this->assertEquals(['w0' => 3], $query->getValues());
- }
-
- public function testMaxValueCursor(): void
- {
- $query = new Select(Project::class, 'p');
- $query->orderBy('id ASC');
-
- $cursor = new MaxValueCursor();
- $query->applyCursor($cursor);
-
- $this->assertEquals(PageCursor::DEFAULT_PAGE_SIZE, $cursor->getPageSize());
-
- $this->assertEquals(
- 'SELECT `p`.* FROM `projects` AS `p` ORDER BY id ASC LIMIT 50',
- $query->getSql(),
- );
-
- $this->assertEquals([], $query->getValues());
-
- $pageSize = 20;
-
- $cursor->setOffset(3);
- $cursor->setPageSize($pageSize);
- $query->applyCursor($cursor);
-
- $this->assertEquals($pageSize, $cursor->getPageSize());
-
- $this->assertEquals(
- 'SELECT `p`.* FROM `projects` AS `p` WHERE `p`.`id` > :w0 ORDER BY id ASC LIMIT 20',
- $query->getSql(),
- );
-
- $this->assertEquals(['w0' => 3], $query->getValues());
- }
-
public function testBatchedMinValueCursor(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -374,7 +251,7 @@ public function testBatchedMinValueCursor(): void
public function testBatchedMaxValueCursor(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
diff --git a/tests/DatabaseTest.php b/tests/base/BaseDatabaseTest.php
similarity index 87%
rename from tests/DatabaseTest.php
rename to tests/base/BaseDatabaseTest.php
index ea9ef23..73428fb 100644
--- a/tests/DatabaseTest.php
+++ b/tests/base/BaseDatabaseTest.php
@@ -11,19 +11,20 @@
declare(strict_types=1);
-namespace Tests;
+namespace Tests\Base;
use Access\Database;
use Access\Exception;
use Access\Query;
+use PDO;
+use PHPUnit\Framework\TestCase;
-use Tests\AbstractBaseTestCase;
use Tests\Fixtures\Entity\Photo;
use Tests\Fixtures\Entity\Project;
use Tests\Fixtures\Entity\Role;
use Tests\Fixtures\Entity\User;
-class DatabaseTest extends AbstractBaseTestCase
+abstract class BaseDatabaseTest extends TestCase implements DatabaseBuilderInterface
{
public function testBrokenCreation(): void
{
@@ -35,14 +36,14 @@ public function testBrokenCreation(): void
public function testDirectConstruct(): void
{
- $db = new Database(new \PDO('sqlite::memory:'));
+ $db = new Database(new PDO('sqlite::memory:'));
$this->assertNotNull($db);
}
public function testInsert(): void
{
- $db = self::createDatabase();
+ $db = static::createDatabase();
$dave = new User();
$dave->setEmail('dave@example.com');
@@ -93,7 +94,7 @@ public function testInsert(): void
public function testFindOne(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
$user = $db->findOne(User::class, 1);
@@ -102,7 +103,7 @@ public function testFindOne(): void
public function testFindOneBy(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
$user = $db->findOneBy(User::class, [
'name' => 'Dave',
@@ -113,7 +114,7 @@ public function testFindOneBy(): void
public function testFindByNoFields(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
$users = $db->findBy(User::class, []);
$count = 0;
@@ -132,7 +133,7 @@ public function testFindByNoFields(): void
public function testUpdate(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var User $user */
$user = $db->findOne(User::class, 1);
@@ -149,7 +150,7 @@ public function testUpdate(): void
public function testUpdateSame(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var User $user */
$user = $db->findOne(User::class, 1);
@@ -164,7 +165,7 @@ public function testUpdateSame(): void
public function testDelete(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var Project $project */
$project = $db->findOne(Project::class, 2);
@@ -179,7 +180,7 @@ public function testDelete(): void
public function testDeleteCascade(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var User $user */
$user = $db->findOne(User::class, 2);
@@ -202,7 +203,7 @@ public function testDeleteCascade(): void
public function testSoftDeleteCascade(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var User $user */
$user = $db->findOne(User::class, 2);
@@ -226,7 +227,7 @@ public function testSoftDeleteCascade(): void
public function testQuerySelect(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
$query = new Query\Select(Project::class);
$query->where([
@@ -243,7 +244,7 @@ public function testQuerySelect(): void
public function testQueryUpdate(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
$query = new Query\Update(Project::class);
$query->values(['name' => 'Access']);
@@ -257,7 +258,7 @@ public function testQueryUpdate(): void
public function testKlassValidationInvalid(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
$this->expectException(Exception::class);
$this->expectExceptionMessage('Invalid entity: BLABLA');
@@ -272,7 +273,7 @@ public function testKlassValidationInvalid(): void
public function testKlassValidationEmpty(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
$this->expectException(Exception::class);
$this->expectExceptionMessage('Invalid table name, can not be empty');
@@ -282,7 +283,7 @@ public function testKlassValidationEmpty(): void
public function testRepositoryValidation(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
$this->expectException(Exception::class);
$this->expectExceptionMessage('Invalid repository: BLABLA');
@@ -292,7 +293,7 @@ public function testRepositoryValidation(): void
public function testNonSoftDeletable(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var Project $project */
$project = $db->findOne(Project::class, 1);
@@ -305,7 +306,7 @@ public function testNonSoftDeletable(): void
public function testWithIncludeSoftDeleted(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
// user exists in the database
$user = $db->findOne(User::class, 1);
diff --git a/tests/EntityTest.php b/tests/base/BaseEntityTest.php
similarity index 89%
rename from tests/EntityTest.php
rename to tests/base/BaseEntityTest.php
index f8e9b7a..0b52eaf 100644
--- a/tests/EntityTest.php
+++ b/tests/base/BaseEntityTest.php
@@ -11,11 +11,10 @@
declare(strict_types=1);
-namespace Tests;
+namespace Tests\Base;
use Access\Exception;
-
-use Tests\AbstractBaseTestCase;
+use PHPUnit\Framework\TestCase;
use Tests\Fixtures\Entity\InvalidEnumNameEntity;
use Tests\Fixtures\Entity\MissingEnumNameEntity;
use Tests\Fixtures\Entity\MissingPublicSoftDeleteEntity;
@@ -25,11 +24,11 @@
use Tests\Fixtures\Repository\ProjectRepository;
use Tests\Fixtures\UserStatus;
-class EntityTest extends AbstractBaseTestCase
+abstract class BaseEntityTest extends TestCase implements DatabaseBuilderInterface
{
public function testIdAlreadySet(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var User $user */
$user = $db->findOne(User::class, 1);
@@ -52,7 +51,7 @@ public function testIdNotAvailable(): void
public function testUnavailableField(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var User $user */
$user = $db->findOne(User::class, 1);
@@ -65,7 +64,7 @@ public function testUnavailableField(): void
public function testOverrideId(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var User $user */
$user = $db->findOne(User::class, 1);
@@ -78,7 +77,7 @@ public function testOverrideId(): void
public function testSimpleDeletedAt(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var User $user */
$user = $db->findOne(User::class, 1);
@@ -96,7 +95,7 @@ public function testSimpleDeletedAt(): void
public function testSimpleDeletedAtDatabaseHelper(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var User $user */
$user = $db->findOne(User::class, 2);
@@ -113,7 +112,7 @@ public function testSimpleDeletedAtDatabaseHelper(): void
public function testDeletedAtJoin(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var User $user */
$user = $db->findOne(User::class, 1);
@@ -130,7 +129,7 @@ public function testDeletedAtJoin(): void
public function testCopy(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
$projectToCopyName = 'Access';
$copyProjectName = 'Access copy';
@@ -157,7 +156,7 @@ public function testCopy(): void
public function testEnumValue(): void
{
- $db = self::createDatabase();
+ $db = static::createDatabase();
$dave = new User();
$dave->setEmail('dave@example.com');
@@ -181,7 +180,7 @@ public function testEnumValue(): void
public function testMissingEnumName(): void
{
- $db = self::createDatabase();
+ $db = static::createDatabase();
$entity = new MissingEnumNameEntity();
$entity->setStatus(UserStatus::ACTIVE);
@@ -197,7 +196,7 @@ public function testMissingEnumName(): void
public function testInvalidEnumName(): void
{
- $db = self::createDatabase();
+ $db = static::createDatabase();
$entity = new InvalidEnumNameEntity();
$entity->setStatus(UserStatus::ACTIVE);
@@ -215,7 +214,7 @@ public function testInvalidEnumName(): void
public function testMissingPublicSoftDelete(): void
{
- $db = self::createDatabase();
+ $db = static::createDatabase();
$entity = new MissingPublicSoftDeleteEntity();
@@ -227,7 +226,7 @@ public function testMissingPublicSoftDelete(): void
public function testMissingSetDeleted(): void
{
- $db = self::createDatabase();
+ $db = static::createDatabase();
$entity = new MissingSetDeletedEntity();
diff --git a/tests/LockTest.php b/tests/base/BaseLockTest.php
similarity index 84%
rename from tests/LockTest.php
rename to tests/base/BaseLockTest.php
index 4653321..3805297 100644
--- a/tests/LockTest.php
+++ b/tests/base/BaseLockTest.php
@@ -11,10 +11,10 @@
declare(strict_types=1);
-namespace Tests;
+namespace Tests\Base;
use Access\Exception;
-use Tests\AbstractBaseTestCase;
+use PHPUnit\Framework\TestCase;
use Tests\Fixtures\Entity\Project;
use Tests\Fixtures\Entity\User;
@@ -23,11 +23,11 @@
*
* Add some tests when we run our tests on a different database
*/
-class LockTest extends AbstractBaseTestCase
+abstract class BaseLockTest extends TestCase implements DatabaseBuilderInterface
{
public function testLockRead(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
$lock = $db->createLock();
$lock->read(Project::class);
@@ -40,7 +40,7 @@ public function testLockRead(): void
public function testLockWrite(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
$lock = $db->createLock();
$lock->write(Project::class);
@@ -53,7 +53,7 @@ public function testLockWrite(): void
public function testDestructor(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
$lock = $db->createLock();
$lock->write(Project::class);
@@ -69,7 +69,7 @@ public function testDestructor(): void
public function testEmptyLock(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
$lock = $db->createLock();
$lock->lock();
@@ -82,7 +82,7 @@ public function testEmptyLock(): void
public function testEmptyUnlock(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
$lock = $db->createLock();
$lock->lock();
@@ -95,7 +95,7 @@ public function testEmptyUnlock(): void
public function testLockContains(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
$lock1 = $db->createLock();
$lock1->read(User::class, 'u');
@@ -113,7 +113,7 @@ public function testLockContains(): void
public function testLockContainerAfterMerge(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
$lock1 = $db->createLock();
$lock1->read(User::class, 'u');
diff --git a/tests/OrderByTest.php b/tests/base/BaseOrderByTest.php
similarity index 80%
rename from tests/OrderByTest.php
rename to tests/base/BaseOrderByTest.php
index eb5c55a..bf45314 100644
--- a/tests/OrderByTest.php
+++ b/tests/base/BaseOrderByTest.php
@@ -11,27 +11,20 @@
declare(strict_types=1);
-namespace Tests;
+namespace Tests\Base;
-use Access\Batch;
-use Access\Collection;
-use Access\Exception;
-use Access\Clause;
use Access\Clause\OrderBy\Ascending;
use Access\Clause\OrderBy\Random;
use Access\Query\Select;
-
-use Tests\AbstractBaseTestCase;
+use PHPUnit\Framework\TestCase;
use Tests\Fixtures\Entity\Project;
-use Tests\Fixtures\Entity\User;
use Tests\Fixtures\Repository\ProjectRepository;
-use Tests\Fixtures\Repository\UserRepository;
-class OrderByTest extends AbstractBaseTestCase
+abstract class BaseOrderByTest extends TestCase implements DatabaseBuilderInterface
{
public function testSimpleAscending(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
$query = new Select(Project::class, 'p');
$query->orderBy(new Ascending('p.name'));
@@ -46,7 +39,7 @@ public function testSimpleAscending(): void
public function testRandom(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
$query = new Select(Project::class, 'p');
$query->orderBy(new Random());
@@ -62,7 +55,7 @@ public function testRandom(): void
public function testSimpleConversion(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
$query = new Select(Project::class, 'p');
$query->orderBy('p.name DESC');
diff --git a/tests/PresenterTest.php b/tests/base/BasePresenterTest.php
similarity index 99%
rename from tests/PresenterTest.php
rename to tests/base/BasePresenterTest.php
index c3e5251..c9ae7d2 100644
--- a/tests/PresenterTest.php
+++ b/tests/base/BasePresenterTest.php
@@ -11,16 +11,17 @@
declare(strict_types=1);
-namespace Tests;
+namespace Tests\Base;
-use Access\Presenter;
use Access\Clause;
use Access\Clause\Condition\Equals;
use Access\Clause\OrderBy\Descending;
use Access\Collection;
use Access\Database;
use Access\Exception;
-use Tests\AbstractBaseTestCase;
+use Access\Presenter;
+use PHPUnit\Framework\TestCase;
+
use Tests\Fixtures\Entity\Project;
use Tests\Fixtures\Entity\User;
use Tests\Fixtures\Presenter\BrokenInfiniteLoopPresenter;
@@ -46,7 +47,7 @@
use Tests\Fixtures\Presenter\UserWithUserPresenter;
use Tests\Fixtures\StatusFormatter;
-class PresenterTest extends AbstractBaseTestCase
+abstract class BasePresenterTest extends TestCase implements DatabaseBuilderInterface
{
private const OPTION_SINGLE_PROJECT = 1;
private const OPTION_EXTRA_USER = 2;
@@ -56,7 +57,7 @@ class PresenterTest extends AbstractBaseTestCase
*/
private function createAndSetupEntities(int $options = 0): array
{
- $db = self::createDatabase();
+ $db = static::createDatabase();
$userOne = new User();
$db->save($userOne);
@@ -956,7 +957,7 @@ public function testPresentProvideCollection(): void
public function testSimpleFilterUnique(): void
{
- $db = self::createDatabase();
+ $db = static::createDatabase();
$user = $this->createUser($db, 'Name');
@@ -981,7 +982,7 @@ public function testSimpleFilterUnique(): void
public function testSimpleFilterUniqueMissingField(): void
{
- $db = self::createDatabase();
+ $db = static::createDatabase();
$user = $this->createUser($db, 'Name');
@@ -1001,7 +1002,7 @@ public function testSimpleFilterUniqueMissingField(): void
public function testMultipleFilterUnique(): void
{
- $db = self::createDatabase();
+ $db = static::createDatabase();
$user = $this->createUser($db, 'Name');
diff --git a/tests/ProfilerTest.php b/tests/base/BaseProfilerTest.php
similarity index 91%
rename from tests/ProfilerTest.php
rename to tests/base/BaseProfilerTest.php
index 4ec764d..297b44b 100644
--- a/tests/ProfilerTest.php
+++ b/tests/base/BaseProfilerTest.php
@@ -11,22 +11,21 @@
declare(strict_types=1);
-namespace Tests;
+namespace Tests\Base;
use Access\Database;
use Access\Profiler\BlackholeProfiler;
use Access\Query\Raw;
-
-use Tests\AbstractBaseTestCase;
+use PHPUnit\Framework\TestCase;
use Tests\Fixtures\Entity\Project;
use Tests\Fixtures\Entity\User;
use Tests\Fixtures\Repository\ProjectRepository;
-class ProfilerTest extends AbstractBaseTestCase
+abstract class BaseProfilerTest extends TestCase implements DatabaseBuilderInterface
{
public function testProfiler(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
$profiler = $db->getProfiler();
$export = $profiler->export();
@@ -40,7 +39,7 @@ public function testProfiler(): void
public function testNumberOfResults(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
diff --git a/tests/RepositoryTest.php b/tests/base/BaseRepositoryTest.php
similarity index 88%
rename from tests/RepositoryTest.php
rename to tests/base/BaseRepositoryTest.php
index daecb6f..4a96c8e 100644
--- a/tests/RepositoryTest.php
+++ b/tests/base/BaseRepositoryTest.php
@@ -11,22 +11,22 @@
declare(strict_types=1);
-namespace Tests;
+namespace Tests\Base;
use Access\Collection;
use Access\EntityProvider\VirtualArrayEntity;
use Access\Exception;
-use Tests\AbstractBaseTestCase;
+use PHPUnit\Framework\TestCase;
use Tests\Fixtures\Entity\Project;
use Tests\Fixtures\Entity\User;
use Tests\Fixtures\Repository\ProjectRepository;
use Tests\Fixtures\Repository\UserRepository;
-class RepositoryTest extends AbstractBaseTestCase
+abstract class BaseRepositoryTest extends TestCase implements DatabaseBuilderInterface
{
public function testSelectOne(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -44,7 +44,7 @@ public function testSelectOne(): void
public function testFindAllWithLimit(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
$projects = $db->findAll(Project::class, 1);
@@ -55,7 +55,7 @@ public function testFindAllWithLimit(): void
public function testDirectQuery(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -72,7 +72,7 @@ public function testDirectQuery(): void
public function testFindByIds(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -84,7 +84,7 @@ public function testFindByIds(): void
public function testFindByEmptyIds(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -96,7 +96,7 @@ public function testFindByEmptyIds(): void
public function testFindByIdsAsCollection(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -108,7 +108,7 @@ public function testFindByIdsAsCollection(): void
public function testSelectVirtualField(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -120,7 +120,7 @@ public function testSelectVirtualField(): void
public function testSelectAddedVirtualField(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -132,7 +132,7 @@ public function testSelectAddedVirtualField(): void
public function testSelectReplacedVirtualField(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -144,7 +144,7 @@ public function testSelectReplacedVirtualField(): void
public function testSelectVirtualEntity(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -167,7 +167,7 @@ public function testSelectVirtualEntity(): void
public function testSelectBrokenVirtualEntity(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -182,7 +182,7 @@ public function testSelectBrokenVirtualEntity(): void
public function testSelectVirtualArrayEntity(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -200,7 +200,7 @@ public function testSelectVirtualArrayEntity(): void
public function testSelectVirtualEntityIsset(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -215,7 +215,7 @@ public function testSelectVirtualEntityIsset(): void
public function testSelectVirtualEntitySingleField(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -230,7 +230,7 @@ public function testSelectVirtualEntitySingleField(): void
public function testSelectVirtualEntityMissingField(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -248,7 +248,7 @@ public function testSelectVirtualEntityMissingField(): void
public function testSelectVirtualArrayEntityIllegalSet(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -267,7 +267,7 @@ public function testSelectVirtualArrayEntityIllegalSet(): void
public function testSelectVirtualArrayEntityIllegalUnset(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -285,7 +285,7 @@ public function testSelectVirtualArrayEntityIllegalUnset(): void
public function testSelectdBatched(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -312,7 +312,7 @@ public function testSelectdBatched(): void
public function testFindBySimple(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -328,7 +328,7 @@ public function testFindBySimple(): void
public function testFindByArray(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -344,7 +344,7 @@ public function testFindByArray(): void
public function testFindByRaw(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -360,7 +360,7 @@ public function testFindByRaw(): void
public function testFindByEmptyArray(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -376,7 +376,7 @@ public function testFindByEmptyArray(): void
public function testFindByCollection(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -394,7 +394,7 @@ public function testFindByCollection(): void
public function testFindByEmptyCollection(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var ProjectRepository $projectRepo */
$projectRepo = $db->getRepository(Project::class);
@@ -412,7 +412,7 @@ public function testFindByEmptyCollection(): void
public function testRepositorySave(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var User $user */
$user = $db->findOne(User::class, 1);
@@ -430,7 +430,7 @@ public function testRepositorySave(): void
public function testWithIncludeSoftDeleted(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
/** @var UserRepository $userRepo */
$userRepo = $db->getRepository(User::class);
diff --git a/tests/TransactionTest.php b/tests/base/BaseTransactionTest.php
similarity index 89%
rename from tests/TransactionTest.php
rename to tests/base/BaseTransactionTest.php
index 38c75de..50b56aa 100644
--- a/tests/TransactionTest.php
+++ b/tests/base/BaseTransactionTest.php
@@ -11,17 +11,17 @@
declare(strict_types=1);
-namespace Tests;
+namespace Tests\Base;
use Access\Exception;
-use Tests\AbstractBaseTestCase;
+use PHPUnit\Framework\TestCase;
use Tests\Fixtures\Entity\User;
-class TransactionTest extends AbstractBaseTestCase
+abstract class BaseTransactionTest extends TestCase implements DatabaseBuilderInterface
{
public function testTransactionCommit(): void
{
- $db = self::createDatabase();
+ $db = static::createDatabase();
$users = $db->findAll(User::class);
$this->assertEquals(0, count(iterator_to_array($users)));
@@ -45,7 +45,7 @@ public function testTransactionCommit(): void
public function testTransactionRollBack(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
$users = $db->findAll(User::class);
$this->assertEquals(2, count(iterator_to_array($users)));
@@ -69,7 +69,7 @@ public function testTransactionRollBack(): void
public function testTransactionUnfinished(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
$this->expectException(Exception::class);
$this->expectExceptionMessage('Transaction still in progress');
@@ -79,7 +79,7 @@ public function testTransactionUnfinished(): void
public function testNestedTransaction(): void
{
- $db = self::createDatabase();
+ $db = static::createDatabase();
$users = $db->findAll(User::class);
$this->assertEquals(0, count(iterator_to_array($users)));
@@ -110,7 +110,7 @@ public function testNestedTransaction(): void
public function testNestedTransactionWithInnerRollback(): void
{
- $db = self::createDatabase();
+ $db = static::createDatabase();
$users = $db->findAll(User::class);
$this->assertEquals(0, count(iterator_to_array($users)));
diff --git a/tests/base/DatabaseBuilderInterface.php b/tests/base/DatabaseBuilderInterface.php
new file mode 100644
index 0000000..3054c61
--- /dev/null
+++ b/tests/base/DatabaseBuilderInterface.php
@@ -0,0 +1,26 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Base;
+
+use Access\Database;
+use Psr\Clock\ClockInterface;
+
+interface DatabaseBuilderInterface
+{
+ public static function createDatabase(): Database;
+
+ public static function createDatabaseWithDummyData(): Database;
+
+ public static function createDatabaseWithMockClock(?ClockInterface $clock = null): Database;
+}
diff --git a/tests/Fixtures/Entity/InvalidEnumNameEntity.php b/tests/fixtures/Entity/InvalidEnumNameEntity.php
similarity index 100%
rename from tests/Fixtures/Entity/InvalidEnumNameEntity.php
rename to tests/fixtures/Entity/InvalidEnumNameEntity.php
diff --git a/tests/Fixtures/Entity/LogMessage.php b/tests/fixtures/Entity/LogMessage.php
similarity index 100%
rename from tests/Fixtures/Entity/LogMessage.php
rename to tests/fixtures/Entity/LogMessage.php
diff --git a/tests/Fixtures/Entity/MissingEnumNameEntity.php b/tests/fixtures/Entity/MissingEnumNameEntity.php
similarity index 100%
rename from tests/Fixtures/Entity/MissingEnumNameEntity.php
rename to tests/fixtures/Entity/MissingEnumNameEntity.php
diff --git a/tests/Fixtures/Entity/MissingPublicSoftDeleteEntity.php b/tests/fixtures/Entity/MissingPublicSoftDeleteEntity.php
similarity index 100%
rename from tests/Fixtures/Entity/MissingPublicSoftDeleteEntity.php
rename to tests/fixtures/Entity/MissingPublicSoftDeleteEntity.php
diff --git a/tests/Fixtures/Entity/MissingSetDeletedEntity.php b/tests/fixtures/Entity/MissingSetDeletedEntity.php
similarity index 100%
rename from tests/Fixtures/Entity/MissingSetDeletedEntity.php
rename to tests/fixtures/Entity/MissingSetDeletedEntity.php
diff --git a/tests/Fixtures/Entity/MissingTableEntity.php b/tests/fixtures/Entity/MissingTableEntity.php
similarity index 100%
rename from tests/Fixtures/Entity/MissingTableEntity.php
rename to tests/fixtures/Entity/MissingTableEntity.php
diff --git a/tests/Fixtures/Entity/Photo.php b/tests/fixtures/Entity/Photo.php
similarity index 100%
rename from tests/Fixtures/Entity/Photo.php
rename to tests/fixtures/Entity/Photo.php
diff --git a/tests/Fixtures/Entity/ProfileImage.php b/tests/fixtures/Entity/ProfileImage.php
similarity index 100%
rename from tests/Fixtures/Entity/ProfileImage.php
rename to tests/fixtures/Entity/ProfileImage.php
diff --git a/tests/Fixtures/Entity/Project.php b/tests/fixtures/Entity/Project.php
similarity index 100%
rename from tests/Fixtures/Entity/Project.php
rename to tests/fixtures/Entity/Project.php
diff --git a/tests/Fixtures/Entity/Role.php b/tests/fixtures/Entity/Role.php
similarity index 100%
rename from tests/Fixtures/Entity/Role.php
rename to tests/fixtures/Entity/Role.php
diff --git a/tests/Fixtures/Entity/User.php b/tests/fixtures/Entity/User.php
similarity index 100%
rename from tests/Fixtures/Entity/User.php
rename to tests/fixtures/Entity/User.php
diff --git a/tests/Fixtures/Marker/SingleNumberMarker.php b/tests/fixtures/Marker/SingleNumberMarker.php
similarity index 100%
rename from tests/Fixtures/Marker/SingleNumberMarker.php
rename to tests/fixtures/Marker/SingleNumberMarker.php
diff --git a/tests/Fixtures/MockClock.php b/tests/fixtures/MockClock.php
similarity index 100%
rename from tests/Fixtures/MockClock.php
rename to tests/fixtures/MockClock.php
diff --git a/tests/Fixtures/Presenter/BrokenInfiniteLoopPresenter.php b/tests/fixtures/Presenter/BrokenInfiniteLoopPresenter.php
similarity index 100%
rename from tests/Fixtures/Presenter/BrokenInfiniteLoopPresenter.php
rename to tests/fixtures/Presenter/BrokenInfiniteLoopPresenter.php
diff --git a/tests/Fixtures/Presenter/BrokenMissingDependencyPresenter.php b/tests/fixtures/Presenter/BrokenMissingDependencyPresenter.php
similarity index 100%
rename from tests/Fixtures/Presenter/BrokenMissingDependencyPresenter.php
rename to tests/fixtures/Presenter/BrokenMissingDependencyPresenter.php
diff --git a/tests/Fixtures/Presenter/BrokenMissingTypePresenter.php b/tests/fixtures/Presenter/BrokenMissingTypePresenter.php
similarity index 100%
rename from tests/Fixtures/Presenter/BrokenMissingTypePresenter.php
rename to tests/fixtures/Presenter/BrokenMissingTypePresenter.php
diff --git a/tests/Fixtures/Presenter/BrokenNonPublicReceiveDependenciesPresenter.php b/tests/fixtures/Presenter/BrokenNonPublicReceiveDependenciesPresenter.php
similarity index 100%
rename from tests/Fixtures/Presenter/BrokenNonPublicReceiveDependenciesPresenter.php
rename to tests/fixtures/Presenter/BrokenNonPublicReceiveDependenciesPresenter.php
diff --git a/tests/Fixtures/Presenter/BrokenPresenter.php b/tests/fixtures/Presenter/BrokenPresenter.php
similarity index 100%
rename from tests/Fixtures/Presenter/BrokenPresenter.php
rename to tests/fixtures/Presenter/BrokenPresenter.php
diff --git a/tests/Fixtures/Presenter/BrokenVariadicParametersPresenter.php b/tests/fixtures/Presenter/BrokenVariadicParametersPresenter.php
similarity index 100%
rename from tests/Fixtures/Presenter/BrokenVariadicParametersPresenter.php
rename to tests/fixtures/Presenter/BrokenVariadicParametersPresenter.php
diff --git a/tests/Fixtures/Presenter/BrokenWithoutEntityKlassPresenter.php b/tests/fixtures/Presenter/BrokenWithoutEntityKlassPresenter.php
similarity index 100%
rename from tests/Fixtures/Presenter/BrokenWithoutEntityKlassPresenter.php
rename to tests/fixtures/Presenter/BrokenWithoutEntityKlassPresenter.php
diff --git a/tests/Fixtures/Presenter/PlainProjectPresenter.php b/tests/fixtures/Presenter/PlainProjectPresenter.php
similarity index 100%
rename from tests/Fixtures/Presenter/PlainProjectPresenter.php
rename to tests/fixtures/Presenter/PlainProjectPresenter.php
diff --git a/tests/Fixtures/Presenter/PlainUserPresenter.php b/tests/fixtures/Presenter/PlainUserPresenter.php
similarity index 100%
rename from tests/Fixtures/Presenter/PlainUserPresenter.php
rename to tests/fixtures/Presenter/PlainUserPresenter.php
diff --git a/tests/Fixtures/Presenter/ProjectPresenter.php b/tests/fixtures/Presenter/ProjectPresenter.php
similarity index 100%
rename from tests/Fixtures/Presenter/ProjectPresenter.php
rename to tests/fixtures/Presenter/ProjectPresenter.php
diff --git a/tests/Fixtures/Presenter/ProjectWithDatesPresenter.php b/tests/fixtures/Presenter/ProjectWithDatesPresenter.php
similarity index 100%
rename from tests/Fixtures/Presenter/ProjectWithDatesPresenter.php
rename to tests/fixtures/Presenter/ProjectWithDatesPresenter.php
diff --git a/tests/Fixtures/Presenter/ProjectWithEmptyPresenter.php b/tests/fixtures/Presenter/ProjectWithEmptyPresenter.php
similarity index 100%
rename from tests/Fixtures/Presenter/ProjectWithEmptyPresenter.php
rename to tests/fixtures/Presenter/ProjectWithEmptyPresenter.php
diff --git a/tests/Fixtures/Presenter/ProjectWithOwnerPresenter.php b/tests/fixtures/Presenter/ProjectWithOwnerPresenter.php
similarity index 100%
rename from tests/Fixtures/Presenter/ProjectWithOwnerPresenter.php
rename to tests/fixtures/Presenter/ProjectWithOwnerPresenter.php
diff --git a/tests/Fixtures/Presenter/ProjectWithReceiveDependenciesPresenter.php b/tests/fixtures/Presenter/ProjectWithReceiveDependenciesPresenter.php
similarity index 100%
rename from tests/Fixtures/Presenter/ProjectWithReceiveDependenciesPresenter.php
rename to tests/fixtures/Presenter/ProjectWithReceiveDependenciesPresenter.php
diff --git a/tests/Fixtures/Presenter/SimpleProjectPresenter.php b/tests/fixtures/Presenter/SimpleProjectPresenter.php
similarity index 100%
rename from tests/Fixtures/Presenter/SimpleProjectPresenter.php
rename to tests/fixtures/Presenter/SimpleProjectPresenter.php
diff --git a/tests/Fixtures/Presenter/UserEmptyResultPresenter.php b/tests/fixtures/Presenter/UserEmptyResultPresenter.php
similarity index 100%
rename from tests/Fixtures/Presenter/UserEmptyResultPresenter.php
rename to tests/fixtures/Presenter/UserEmptyResultPresenter.php
diff --git a/tests/Fixtures/Presenter/UserOptionalDependencyPresenter.php b/tests/fixtures/Presenter/UserOptionalDependencyPresenter.php
similarity index 100%
rename from tests/Fixtures/Presenter/UserOptionalDependencyPresenter.php
rename to tests/fixtures/Presenter/UserOptionalDependencyPresenter.php
diff --git a/tests/Fixtures/Presenter/UserPresenter.php b/tests/fixtures/Presenter/UserPresenter.php
similarity index 100%
rename from tests/Fixtures/Presenter/UserPresenter.php
rename to tests/fixtures/Presenter/UserPresenter.php
diff --git a/tests/Fixtures/Presenter/UserWithClausePresenter.php b/tests/fixtures/Presenter/UserWithClausePresenter.php
similarity index 100%
rename from tests/Fixtures/Presenter/UserWithClausePresenter.php
rename to tests/fixtures/Presenter/UserWithClausePresenter.php
diff --git a/tests/Fixtures/Presenter/UserWithDatabasePresenter.php b/tests/fixtures/Presenter/UserWithDatabasePresenter.php
similarity index 100%
rename from tests/Fixtures/Presenter/UserWithDatabasePresenter.php
rename to tests/fixtures/Presenter/UserWithDatabasePresenter.php
diff --git a/tests/Fixtures/Presenter/UserWithProjectNamesPresenter.php b/tests/fixtures/Presenter/UserWithProjectNamesPresenter.php
similarity index 100%
rename from tests/Fixtures/Presenter/UserWithProjectNamesPresenter.php
rename to tests/fixtures/Presenter/UserWithProjectNamesPresenter.php
diff --git a/tests/Fixtures/Presenter/UserWithSingleNumberMarkerPresenter.php b/tests/fixtures/Presenter/UserWithSingleNumberMarkerPresenter.php
similarity index 100%
rename from tests/Fixtures/Presenter/UserWithSingleNumberMarkerPresenter.php
rename to tests/fixtures/Presenter/UserWithSingleNumberMarkerPresenter.php
diff --git a/tests/Fixtures/Presenter/UserWithUserPresenter.php b/tests/fixtures/Presenter/UserWithUserPresenter.php
similarity index 100%
rename from tests/Fixtures/Presenter/UserWithUserPresenter.php
rename to tests/fixtures/Presenter/UserWithUserPresenter.php
diff --git a/tests/Fixtures/Repository/ProjectRepository.php b/tests/fixtures/Repository/ProjectRepository.php
similarity index 100%
rename from tests/Fixtures/Repository/ProjectRepository.php
rename to tests/fixtures/Repository/ProjectRepository.php
diff --git a/tests/Fixtures/Repository/UserRepository.php b/tests/fixtures/Repository/UserRepository.php
similarity index 100%
rename from tests/Fixtures/Repository/UserRepository.php
rename to tests/fixtures/Repository/UserRepository.php
diff --git a/tests/Fixtures/StatusFormatter.php b/tests/fixtures/StatusFormatter.php
similarity index 100%
rename from tests/Fixtures/StatusFormatter.php
rename to tests/fixtures/StatusFormatter.php
diff --git a/tests/Fixtures/UserStatus.php b/tests/fixtures/UserStatus.php
similarity index 100%
rename from tests/Fixtures/UserStatus.php
rename to tests/fixtures/UserStatus.php
diff --git a/tests/mysql/ClockTest.php b/tests/mysql/ClockTest.php
new file mode 100644
index 0000000..812258b
--- /dev/null
+++ b/tests/mysql/ClockTest.php
@@ -0,0 +1,21 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Mysql;
+
+use Tests\Base\BaseClockTest;
+
+class ClockTest extends BaseClockTest
+{
+ use DatabaseBuilderTrait;
+}
diff --git a/tests/mysql/CollectionTest.php b/tests/mysql/CollectionTest.php
new file mode 100644
index 0000000..796d234
--- /dev/null
+++ b/tests/mysql/CollectionTest.php
@@ -0,0 +1,21 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Mysql;
+
+use Tests\Base\BaseCollectionTest;
+
+class CollectionTest extends BaseCollectionTest
+{
+ use DatabaseBuilderTrait;
+}
diff --git a/tests/mysql/CursorTest.php b/tests/mysql/CursorTest.php
new file mode 100644
index 0000000..e135a2a
--- /dev/null
+++ b/tests/mysql/CursorTest.php
@@ -0,0 +1,21 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Mysql;
+
+use Tests\Base\BaseCursorTest;
+
+class CursorTest extends BaseCursorTest
+{
+ use DatabaseBuilderTrait;
+}
diff --git a/tests/mysql/DatabaseBuilderTrait.php b/tests/mysql/DatabaseBuilderTrait.php
new file mode 100644
index 0000000..a3cd9ca
--- /dev/null
+++ b/tests/mysql/DatabaseBuilderTrait.php
@@ -0,0 +1,158 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Mysql;
+
+use Access\Database;
+use Access\Query\Raw;
+use PDO;
+use Psr\Clock\ClockInterface;
+
+use Tests\Fixtures\Entity\ProfileImage;
+use Tests\Fixtures\Entity\Project;
+use Tests\Fixtures\Entity\User;
+use Tests\Fixtures\MockClock;
+
+trait DatabaseBuilderTrait
+{
+ private static function createTables(Database $db): Database
+ {
+ $name = sprintf('access_test_%s', bin2hex(random_bytes(8)));
+
+ if (!empty($_ENV['MYSQL_DATABASE_NAME'])) {
+ $name = $_ENV['MYSQL_DATABASE_NAME'];
+ }
+
+ $db->query(new Raw("DROP DATABASE IF EXISTS `$name`"));
+ $db->query(new Raw("CREATE DATABASE IF NOT EXISTS `$name`"));
+ $db->query(new Raw("USE `$name`"));
+
+ $createProfileImagesQuery = new Raw('CREATE TABLE `profile_images` (
+ `id` INT AUTO_INCREMENT,
+ `created_at` DATETIME,
+ `updated_at` DATETIME,
+ PRIMARY KEY(id)
+ )');
+
+ $db->query($createProfileImagesQuery);
+
+ $createUsersQuery = new Raw('CREATE TABLE `users` (
+ `id` INT AUTO_INCREMENT,
+ `role` VARCHAR(20) DEFAULT NULL,
+ `profile_image_id` INTEGER DEFAULT NULL,
+ `status` VARCHAR(20) DEFAULT NULL,
+ `name` VARCHAR(50) DEFAULT NULL,
+ `email` VARCHAR(150) DEFAULT NULL,
+ `created_at` DATETIME,
+ `updated_at` DATETIME,
+ `deleted_at` DATETIME DEFAULT NULL,
+ PRIMARY KEY(id),
+ FOREIGN KEY(profile_image_id) REFERENCES profile_images(id)
+ )');
+
+ $db->query($createUsersQuery);
+
+ $createProjectsQuery = new Raw('CREATE TABLE `projects` (
+ `id` INT AUTO_INCREMENT,
+ `status` VARCHAR(20) DEFAULT NULL,
+ `owner_id` INTEGER NOT NULL,
+ `name` VARCHAR(50) DEFAULT NULL,
+ `published_at` DATE DEFAULT NULL,
+ `created_at` DATETIME,
+ `updated_at` DATETIME,
+ PRIMARY KEY(id),
+ FOREIGN KEY(owner_id) REFERENCES users(id)
+ )');
+
+ $db->query($createProjectsQuery);
+
+ $createLogMessagesQuery = new Raw('CREATE TABLE `log_messages` (
+ `id` INT AUTO_INCREMENT,
+ `message` VARCHAR(100) DEFAULT NULL,
+ `created_at` DATETIME,
+ PRIMARY KEY(id)
+ )');
+
+ $db->query($createLogMessagesQuery);
+
+ return $db;
+ }
+
+ private static function createPdo(): PDO
+ {
+ $host = $_ENV['MYSQL_DATABASE_HOST'];
+ $port = $_ENV['MYSQL_DATABASE_PORT'];
+ $user = $_ENV['MYSQL_DATABASE_USER'];
+ $password = $_ENV['MYSQL_DATABASE_PASSWORD'];
+
+ return new PDO(sprintf('mysql:host=%s;port=%s', $host, $port), $user, $password);
+ }
+
+ public static function createDatabase(): Database
+ {
+ $pdo = self::createPdo();
+ $db = new Database($pdo);
+
+ return self::createTables($db);
+ }
+
+ public static function createDatabaseWithMockClock(?ClockInterface $clock = null): Database
+ {
+ $pdo = self::createPdo();
+ $db = new Database($pdo);
+ $clock = $clock ?? new MockClock();
+
+ $db = new Database($pdo, null, $clock);
+
+ return self::createTables($db);
+ }
+
+ /**
+ * Create a dummy database with:
+ *
+ * - 1 profile image
+ * - 2 users
+ * - 2 projects
+ */
+ public static function createDatabaseWithDummyData(): Database
+ {
+ $db = self::createDatabase();
+
+ $profileImage = new ProfileImage();
+ $db->save($profileImage);
+
+ $dave = new User();
+ $dave->setEmail('dave@example.com');
+ $dave->setName('Dave');
+ $dave->setProfileImageId($profileImage->getId());
+ $db->insert($dave);
+
+ $bob = new User();
+ $bob->setEmail('bob@example.com');
+ $bob->setName('Bob');
+ $db->insert($bob);
+
+ $access = new Project();
+ $access->setOwnerId($dave->getId());
+ $access->setName('Access');
+ $access->setPublishedAt(\DateTime::createFromFormat('Y-m-d', '2019-02-07') ?: null);
+ $db->save($access);
+
+ $accessFork = new Project();
+ $accessFork->setOwnerId($bob->getId());
+ $accessFork->setName('Access fork');
+ $db->insert($accessFork);
+
+ return $db;
+ }
+}
diff --git a/tests/mysql/DatabaseTest.php b/tests/mysql/DatabaseTest.php
new file mode 100644
index 0000000..a8b9138
--- /dev/null
+++ b/tests/mysql/DatabaseTest.php
@@ -0,0 +1,21 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Mysql;
+
+use Tests\Base\BaseDatabaseTest;
+
+class DatabaseTest extends BaseDatabaseTest
+{
+ use DatabaseBuilderTrait;
+}
diff --git a/tests/mysql/EntityTest.php b/tests/mysql/EntityTest.php
new file mode 100644
index 0000000..08e1168
--- /dev/null
+++ b/tests/mysql/EntityTest.php
@@ -0,0 +1,21 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Mysql;
+
+use Tests\Base\BaseEntityTest;
+
+class EntityTest extends BaseEntityTest
+{
+ use DatabaseBuilderTrait;
+}
diff --git a/tests/mysql/OrderByTest.php b/tests/mysql/OrderByTest.php
new file mode 100644
index 0000000..729394a
--- /dev/null
+++ b/tests/mysql/OrderByTest.php
@@ -0,0 +1,21 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Mysql;
+
+use Tests\Base\BaseOrderByTest;
+
+class OrderByTest extends BaseOrderByTest
+{
+ use DatabaseBuilderTrait;
+}
diff --git a/tests/mysql/PresenterTest.php b/tests/mysql/PresenterTest.php
new file mode 100644
index 0000000..279a334
--- /dev/null
+++ b/tests/mysql/PresenterTest.php
@@ -0,0 +1,21 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Mysql;
+
+use Tests\Base\BasePresenterTest;
+
+class PresenterTest extends BasePresenterTest
+{
+ use DatabaseBuilderTrait;
+}
diff --git a/tests/mysql/RepositoryTest.php b/tests/mysql/RepositoryTest.php
new file mode 100644
index 0000000..8d89d98
--- /dev/null
+++ b/tests/mysql/RepositoryTest.php
@@ -0,0 +1,21 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Mysql;
+
+use Tests\Base\BaseRepositoryTest;
+
+class RepositoryTest extends BaseRepositoryTest
+{
+ use DatabaseBuilderTrait;
+}
diff --git a/tests/mysql/StatementTest.php b/tests/mysql/StatementTest.php
new file mode 100644
index 0000000..e6efc0f
--- /dev/null
+++ b/tests/mysql/StatementTest.php
@@ -0,0 +1,56 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Mysql;
+
+use Access\Exception;
+use Access\Query;
+use PHPUnit\Framework\TestCase;
+
+use Tests\Fixtures\Entity\User;
+
+class StatementTest extends TestCase
+{
+ use DatabaseBuilderTrait;
+
+ public function testInvalidPrepare(): void
+ {
+ $db = static::createDatabaseWithDummyData();
+
+ $this->expectException(Exception::class);
+ $this->expectExceptionMessage('Unable to execute query');
+
+ $query = new Query\Raw('SELECT foo FRM bar');
+ $db->query($query);
+ }
+
+ public function testInvalidExectute(): void
+ {
+ $db = static::createDatabase();
+
+ $this->expectException(Exception::class);
+ $this->expectExceptionMessage('Unable to execute query');
+
+ $query = new Query\Insert(User::class);
+ $query->values([
+ 'id' => 1,
+ 'name' => 'Dave',
+ 'email' => 'dave@example.com',
+ ]);
+
+ $db->query($query);
+
+ // insert with same primary key value
+ $db->query($query);
+ }
+}
diff --git a/tests/mysql/TransactionTest.php b/tests/mysql/TransactionTest.php
new file mode 100644
index 0000000..7ff88ac
--- /dev/null
+++ b/tests/mysql/TransactionTest.php
@@ -0,0 +1,21 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Mysql;
+
+use Tests\Base\BaseTransactionTest;
+
+class TransactionTest extends BaseTransactionTest
+{
+ use DatabaseBuilderTrait;
+}
diff --git a/tests/sqlite/ClockTest.php b/tests/sqlite/ClockTest.php
new file mode 100644
index 0000000..c121031
--- /dev/null
+++ b/tests/sqlite/ClockTest.php
@@ -0,0 +1,21 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Sqlite;
+
+use Tests\Base\BaseClockTest;
+
+class ClockTest extends BaseClockTest
+{
+ use DatabaseBuilderTrait;
+}
diff --git a/tests/sqlite/CollectionTest.php b/tests/sqlite/CollectionTest.php
new file mode 100644
index 0000000..48de4f0
--- /dev/null
+++ b/tests/sqlite/CollectionTest.php
@@ -0,0 +1,21 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Sqlite;
+
+use Tests\Base\BaseCollectionTest;
+
+class CollectionTest extends BaseCollectionTest
+{
+ use DatabaseBuilderTrait;
+}
diff --git a/tests/sqlite/CursorTest.php b/tests/sqlite/CursorTest.php
new file mode 100644
index 0000000..3938b8a
--- /dev/null
+++ b/tests/sqlite/CursorTest.php
@@ -0,0 +1,21 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Sqlite;
+
+use Tests\Base\BaseCursorTest;
+
+class CursorTest extends BaseCursorTest
+{
+ use DatabaseBuilderTrait;
+}
diff --git a/tests/AbstractBaseTestCase.php b/tests/sqlite/DatabaseBuilderTrait.php
similarity index 97%
rename from tests/AbstractBaseTestCase.php
rename to tests/sqlite/DatabaseBuilderTrait.php
index 27ffb73..7a16a3c 100644
--- a/tests/AbstractBaseTestCase.php
+++ b/tests/sqlite/DatabaseBuilderTrait.php
@@ -11,19 +11,18 @@
declare(strict_types=1);
-namespace Tests;
-
-use PHPUnit\Framework\TestCase;
+namespace Tests\Sqlite;
use Access\Database;
use Access\Query\Raw;
use Psr\Clock\ClockInterface;
+
use Tests\Fixtures\Entity\ProfileImage;
use Tests\Fixtures\Entity\Project;
use Tests\Fixtures\Entity\User;
use Tests\Fixtures\MockClock;
-abstract class AbstractBaseTestCase extends TestCase
+trait DatabaseBuilderTrait
{
private static function createTables(Database $db): Database
{
diff --git a/tests/sqlite/DatabaseTest.php b/tests/sqlite/DatabaseTest.php
new file mode 100644
index 0000000..22fe2a5
--- /dev/null
+++ b/tests/sqlite/DatabaseTest.php
@@ -0,0 +1,21 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Sqlite;
+
+use Tests\Base\BaseDatabaseTest;
+
+class DatabaseTest extends BaseDatabaseTest
+{
+ use DatabaseBuilderTrait;
+}
diff --git a/tests/sqlite/EntityTest.php b/tests/sqlite/EntityTest.php
new file mode 100644
index 0000000..3586b28
--- /dev/null
+++ b/tests/sqlite/EntityTest.php
@@ -0,0 +1,21 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Sqlite;
+
+use Tests\Base\BaseEntityTest;
+
+class EntityTest extends BaseEntityTest
+{
+ use DatabaseBuilderTrait;
+}
diff --git a/tests/sqlite/LockTest.php b/tests/sqlite/LockTest.php
new file mode 100644
index 0000000..71a4f09
--- /dev/null
+++ b/tests/sqlite/LockTest.php
@@ -0,0 +1,26 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Sqlite;
+
+use Tests\Base\BaseLockTest;
+
+/**
+ * SQLite has no support for locks, the tests are just "covering" the lock code
+ *
+ * Add some tests when we run our tests on a different database
+ */
+class LockTest extends BaseLockTest
+{
+ use DatabaseBuilderTrait;
+}
diff --git a/tests/sqlite/OrderByTest.php b/tests/sqlite/OrderByTest.php
new file mode 100644
index 0000000..bc90e67
--- /dev/null
+++ b/tests/sqlite/OrderByTest.php
@@ -0,0 +1,21 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Sqlite;
+
+use Tests\Base\BaseOrderByTest;
+
+class OrderByTest extends BaseOrderByTest
+{
+ use DatabaseBuilderTrait;
+}
diff --git a/tests/sqlite/PresenterTest.php b/tests/sqlite/PresenterTest.php
new file mode 100644
index 0000000..e542d4b
--- /dev/null
+++ b/tests/sqlite/PresenterTest.php
@@ -0,0 +1,21 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Sqlite;
+
+use Tests\Base\BasePresenterTest;
+
+class PresenterTest extends BasePresenterTest
+{
+ use DatabaseBuilderTrait;
+}
diff --git a/tests/sqlite/ProfilerTest.php b/tests/sqlite/ProfilerTest.php
new file mode 100644
index 0000000..d3e54ba
--- /dev/null
+++ b/tests/sqlite/ProfilerTest.php
@@ -0,0 +1,21 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Sqlite;
+
+use Tests\Base\BaseProfilerTest;
+
+class ProfilerTest extends BaseProfilerTest
+{
+ use DatabaseBuilderTrait;
+}
diff --git a/tests/sqlite/RepositoryTest.php b/tests/sqlite/RepositoryTest.php
new file mode 100644
index 0000000..b483f0c
--- /dev/null
+++ b/tests/sqlite/RepositoryTest.php
@@ -0,0 +1,21 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Sqlite;
+
+use Tests\Base\BaseRepositoryTest;
+
+class RepositoryTest extends BaseRepositoryTest
+{
+ use DatabaseBuilderTrait;
+}
diff --git a/tests/StatementTest.php b/tests/sqlite/StatementTest.php
similarity index 82%
rename from tests/StatementTest.php
rename to tests/sqlite/StatementTest.php
index 4cf3ef9..8f6702f 100644
--- a/tests/StatementTest.php
+++ b/tests/sqlite/StatementTest.php
@@ -11,18 +11,21 @@
declare(strict_types=1);
-namespace Tests;
+namespace Tests\Sqlite;
use Access\Exception;
use Access\Query;
-use Tests\AbstractBaseTestCase;
+use PHPUnit\Framework\TestCase;
+
use Tests\Fixtures\Entity\User;
-class StatementTest extends AbstractBaseTestCase
+class StatementTest extends TestCase
{
+ use DatabaseBuilderTrait;
+
public function testInvalidPrepare(): void
{
- $db = self::createDatabaseWithDummyData();
+ $db = static::createDatabaseWithDummyData();
$this->expectException(Exception::class);
$this->expectExceptionMessage('Unable to prepare query');
@@ -33,7 +36,7 @@ public function testInvalidPrepare(): void
public function testInvalidExectute(): void
{
- $db = self::createDatabase();
+ $db = static::createDatabase();
$this->expectException(Exception::class);
$this->expectExceptionMessage('Unable to execute query');
diff --git a/tests/sqlite/TransactionTest.php b/tests/sqlite/TransactionTest.php
new file mode 100644
index 0000000..cbc825f
--- /dev/null
+++ b/tests/sqlite/TransactionTest.php
@@ -0,0 +1,21 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Sqlite;
+
+use Tests\Base\BaseTransactionTest;
+
+class TransactionTest extends BaseTransactionTest
+{
+ use DatabaseBuilderTrait;
+}
diff --git a/tests/ClauseTest.php b/tests/unit/ClauseTest.php
similarity index 91%
rename from tests/ClauseTest.php
rename to tests/unit/ClauseTest.php
index 31a789b..763f5bc 100644
--- a/tests/ClauseTest.php
+++ b/tests/unit/ClauseTest.php
@@ -11,14 +11,15 @@
declare(strict_types=1);
-namespace Tests;
+namespace Tests\Unit;
+
+use PHPUnit\Framework\TestCase;
use Access\Clause\Condition\Equals;
use Access\Clause\Multiple;
use Access\Clause\MultipleOr;
-use Tests\AbstractBaseTestCase;
-class ClauseTest extends AbstractBaseTestCase
+class ClauseTest extends TestCase
{
public function testCountableMultiple(): void
{
diff --git a/tests/unit/CursorTest.php b/tests/unit/CursorTest.php
new file mode 100644
index 0000000..232052e
--- /dev/null
+++ b/tests/unit/CursorTest.php
@@ -0,0 +1,151 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Unit;
+
+use PHPUnit\Framework\TestCase;
+
+use Access\Query\Cursor\CurrentIdsCursor;
+use Access\Query\Cursor\MaxValueCursor;
+use Access\Query\Cursor\MinValueCursor;
+use Access\Query\Cursor\PageCursor;
+use Access\Query\Select;
+
+use Tests\Fixtures\Entity\Project;
+
+class CursorTest extends TestCase
+{
+ public function testPageCursor(): void
+ {
+ $query = new Select(Project::class);
+ $query->orderBy('id ASC');
+
+ $cursor = new PageCursor();
+ $query->applyCursor($cursor);
+
+ $this->assertEquals(PageCursor::DEFAULT_PAGE_SIZE, $cursor->getPageSize());
+
+ $this->assertEquals(
+ 'SELECT `projects`.* FROM `projects` ORDER BY id ASC LIMIT 50 OFFSET 0',
+ $query->getSql(),
+ );
+
+ $this->assertEquals([], $query->getValues());
+
+ $pageSize = 20;
+
+ $cursor->setPage(3);
+ $cursor->setPageSize($pageSize);
+ $query->applyCursor($cursor);
+
+ $this->assertEquals($pageSize, $cursor->getPageSize());
+
+ $this->assertEquals(
+ 'SELECT `projects`.* FROM `projects` ORDER BY id ASC LIMIT 20 OFFSET 40',
+ $query->getSql(),
+ );
+ }
+
+ public function testCurrentIdsCursor(): void
+ {
+ $query = new Select(Project::class);
+ $query->orderBy('RANDOM()');
+
+ $cursor = new CurrentIdsCursor();
+ $query->applyCursor($cursor);
+
+ $this->assertEquals(
+ 'SELECT `projects`.* FROM `projects` ORDER BY RAND() LIMIT 50',
+ $query->getSql(),
+ );
+
+ $this->assertEquals([], $query->getValues());
+
+ $cursor->addCurrentIds([1, 2]);
+
+ $query->applyCursor($cursor);
+
+ $this->assertEquals(
+ 'SELECT `projects`.* FROM `projects` WHERE `projects`.`id` NOT IN (:w0, :w1) ORDER BY RAND() LIMIT 50',
+ $query->getSql(),
+ );
+
+ $this->assertEquals(['w0' => 1, 'w1' => 2], $query->getValues());
+ }
+
+ public function testMinValueCursor(): void
+ {
+ $query = new Select(Project::class);
+ $query->orderBy('id DESC');
+
+ $cursor = new MinValueCursor(field: 'projects.id');
+ $query->applyCursor($cursor);
+
+ $this->assertEquals(PageCursor::DEFAULT_PAGE_SIZE, $cursor->getPageSize());
+
+ $this->assertEquals(
+ 'SELECT `projects`.* FROM `projects` ORDER BY id DESC LIMIT 50',
+ $query->getSql(),
+ );
+
+ $this->assertEquals([], $query->getValues());
+
+ $pageSize = 20;
+
+ $cursor->setOffset(3);
+ $cursor->setPageSize($pageSize);
+ $query->applyCursor($cursor);
+
+ $this->assertEquals($pageSize, $cursor->getPageSize());
+
+ $this->assertEquals(
+ 'SELECT `projects`.* FROM `projects` WHERE `projects`.`id` < :w0 ORDER BY id DESC LIMIT 20',
+ $query->getSql(),
+ );
+
+ $this->assertEquals(['w0' => 3], $query->getValues());
+ }
+
+ public function testMaxValueCursor(): void
+ {
+ $query = new Select(Project::class, 'p');
+ $query->orderBy('id ASC');
+
+ $cursor = new MaxValueCursor();
+ $query->applyCursor($cursor);
+
+ $this->assertEquals(PageCursor::DEFAULT_PAGE_SIZE, $cursor->getPageSize());
+
+ $this->assertEquals(
+ 'SELECT `p`.* FROM `projects` AS `p` ORDER BY id ASC LIMIT 50',
+ $query->getSql(),
+ );
+
+ $this->assertEquals([], $query->getValues());
+
+ $pageSize = 20;
+
+ $cursor->setOffset(3);
+ $cursor->setPageSize($pageSize);
+ $query->applyCursor($cursor);
+
+ $this->assertEquals($pageSize, $cursor->getPageSize());
+
+ $this->assertEquals(
+ 'SELECT `p`.* FROM `projects` AS `p` WHERE `p`.`id` > :w0 ORDER BY id ASC LIMIT 20',
+ $query->getSql(),
+ );
+
+ $this->assertEquals(['w0' => 3], $query->getValues());
+ }
+}
diff --git a/tests/DebugQueryTest.php b/tests/unit/DebugQueryTest.php
similarity index 99%
rename from tests/DebugQueryTest.php
rename to tests/unit/DebugQueryTest.php
index 7359337..e4b28fb 100644
--- a/tests/DebugQueryTest.php
+++ b/tests/unit/DebugQueryTest.php
@@ -11,18 +11,19 @@
declare(strict_types=1);
-namespace Tests;
+namespace Tests\Unit;
use Access\Clause;
use Access\DebugQuery;
use Access\Driver\Sqlite;
use Access\Query;
+use PHPUnit\Framework\TestCase;
use Tests\Fixtures\Entity\Project;
use Tests\Fixtures\Entity\User;
use Tests\Fixtures\UserStatus;
-class DebugQueryTest extends AbstractBaseTestCase
+class DebugQueryTest extends TestCase
{
public function testSimpleNull(): void
{
diff --git a/tests/Query/DeleteTest.php b/tests/unit/Query/DeleteTest.php
similarity index 98%
rename from tests/Query/DeleteTest.php
rename to tests/unit/Query/DeleteTest.php
index 7144d0d..30ba464 100644
--- a/tests/Query/DeleteTest.php
+++ b/tests/unit/Query/DeleteTest.php
@@ -2,11 +2,11 @@
declare(strict_types=1);
-namespace Tests\Query;
+namespace Tests\Unit\Query;
use PHPUnit\Framework\TestCase;
-
use Access\Query\Delete;
+
use Tests\Fixtures\Entity\Project;
use Tests\Fixtures\Entity\User;
diff --git a/tests/Query/InsertTest.php b/tests/unit/Query/InsertTest.php
similarity index 94%
rename from tests/Query/InsertTest.php
rename to tests/unit/Query/InsertTest.php
index 81da722..1c46112 100644
--- a/tests/Query/InsertTest.php
+++ b/tests/unit/Query/InsertTest.php
@@ -2,12 +2,12 @@
declare(strict_types=1);
-namespace Tests\Query;
-
-use PHPUnit\Framework\TestCase;
+namespace Tests\Unit\Query;
use Access\Clause\Field;
use Access\Query\Insert;
+use PHPUnit\Framework\TestCase;
+
use Tests\Fixtures\Entity\User;
class InsertTest extends TestCase
diff --git a/tests/Query/LockTablesTest.php b/tests/unit/Query/LockTablesTest.php
similarity index 96%
rename from tests/Query/LockTablesTest.php
rename to tests/unit/Query/LockTablesTest.php
index 5bf761f..54b51fd 100644
--- a/tests/Query/LockTablesTest.php
+++ b/tests/unit/Query/LockTablesTest.php
@@ -11,10 +11,11 @@
declare(strict_types=1);
-namespace Tests\Query;
+namespace Tests\Unit\Query;
+use PHPUnit\Framework\TestCase;
use Access\Query;
-use Tests\AbstractBaseTestCase;
+
use Tests\Fixtures\Entity\Project;
use Tests\Fixtures\Entity\User;
@@ -23,7 +24,7 @@
*
* Add some tests when we run our tests on a different database
*/
-class LockTablesTest extends AbstractBaseTestCase
+class LockTablesTest extends TestCase
{
public function testLockTablesQueryRead(): void
{
diff --git a/tests/Query/RawTest.php b/tests/unit/Query/RawTest.php
similarity index 95%
rename from tests/Query/RawTest.php
rename to tests/unit/Query/RawTest.php
index cd986a3..e0d4f8b 100644
--- a/tests/Query/RawTest.php
+++ b/tests/unit/Query/RawTest.php
@@ -2,10 +2,9 @@
declare(strict_types=1);
-namespace Tests\Query;
+namespace Tests\Unit\Query;
use PHPUnit\Framework\TestCase;
-
use Access\Query\Raw;
class RawTest extends TestCase
diff --git a/tests/Query/SelectTest.php b/tests/unit/Query/SelectTest.php
similarity index 99%
rename from tests/Query/SelectTest.php
rename to tests/unit/Query/SelectTest.php
index 321a5d6..a8bee10 100644
--- a/tests/Query/SelectTest.php
+++ b/tests/unit/Query/SelectTest.php
@@ -2,20 +2,18 @@
declare(strict_types=1);
-namespace Tests\Query;
+namespace Tests\Unit\Query;
use Access\Clause\Condition\Relation;
use Access\Clause\OrderBy\Ascending;
-use PHPUnit\Framework\TestCase;
-
use Access\Exception;
use Access\Query\Select;
+use PHPUnit\Framework\TestCase;
use Tests\Fixtures\Entity\MissingTableEntity;
use Tests\Fixtures\Entity\Project;
use Tests\Fixtures\Entity\User;
use Tests\Fixtures\UserStatus;
-use Tests\Fixtures\UserStatus as FixturesUserStatus;
class SelectTest extends TestCase
{
diff --git a/tests/Query/UnionTest.php b/tests/unit/Query/UnionTest.php
similarity index 98%
rename from tests/Query/UnionTest.php
rename to tests/unit/Query/UnionTest.php
index cf03c30..8cf7e55 100644
--- a/tests/Query/UnionTest.php
+++ b/tests/unit/Query/UnionTest.php
@@ -2,13 +2,13 @@
declare(strict_types=1);
-namespace Tests\Query;
+namespace Tests\Unit\Query;
use Access\Exception\NotSupportedException;
+use Access\Query\Select;
+use Access\Query\Union;
use PHPUnit\Framework\TestCase;
-use Access\Query\Union;
-use Access\Query\Select;
use Tests\Fixtures\Entity\Project;
class UnionTest extends TestCase
diff --git a/tests/Query/UpdateTest.php b/tests/unit/Query/UpdateTest.php
similarity index 99%
rename from tests/Query/UpdateTest.php
rename to tests/unit/Query/UpdateTest.php
index 88b1f6a..99a3ce1 100644
--- a/tests/Query/UpdateTest.php
+++ b/tests/unit/Query/UpdateTest.php
@@ -2,13 +2,13 @@
declare(strict_types=1);
-namespace Tests\Query;
+namespace Tests\Unit\Query;
-use PHPUnit\Framework\TestCase;
-
-use Access\Query\Update;
use Access\Clause\Condition;
use Access\Clause\Field;
+use Access\Query\Update;
+use PHPUnit\Framework\TestCase;
+
use Tests\Fixtures\Entity\Project;
use Tests\Fixtures\Entity\User;