Changes for beta10 (#5)

- Add In/InArray support
- Add ORDER BY support for `Find` functions
- Update dependencies
- Implement fixes identified via static analysis

Reviewed-on: #5
This commit was merged in pull request #5.
This commit is contained in:
2024-09-27 02:15:00 +00:00
parent 9e0e663811
commit d067f8983f
66 changed files with 1728 additions and 664 deletions

View File

@@ -34,7 +34,8 @@ class CustomTest extends TestCase
ThrowawayDb::destroy($this->dbName);
}
public function testRunQuerySucceedsWithAValidQuery()
#[TestDox('runQuery() succeeds with a valid query')]
public function testRunQuerySucceedsWithAValidQuery(): void
{
$stmt = &Custom::runQuery('SELECT data FROM ' . ThrowawayDb::TABLE . ' LIMIT 1', []);
try {
@@ -44,7 +45,8 @@ class CustomTest extends TestCase
}
}
public function testRunQueryFailsWithAnInvalidQuery()
#[TestDox('runQuery() fails with an invalid query')]
public function testRunQueryFailsWithAnInvalidQuery(): void
{
$this->expectException(DocumentException::class);
$stmt = &Custom::runQuery('GRAB stuff FROM over_there UNTIL done', []);
@@ -55,7 +57,8 @@ class CustomTest extends TestCase
}
}
public function testListSucceedsWhenDataIsFound()
#[TestDox('list() succeeds when data is found')]
public function testListSucceedsWhenDataIsFound(): void
{
$list = Custom::list(Query::selectFromTable(ThrowawayDb::TABLE), [], new DocumentMapper(TestDocument::class));
$this->assertNotNull($list, 'The document list should not be null');
@@ -64,7 +67,8 @@ class CustomTest extends TestCase
$this->assertEquals(5, $count, 'There should have been 5 documents in the list');
}
public function testListSucceedsWhenNoDataIsFound()
#[TestDox('list() succeeds when no data is found')]
public function testListSucceedsWhenNoDataIsFound(): void
{
$list = Custom::list(
Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE (data->>'num_value')::numeric > :value",
@@ -73,7 +77,8 @@ class CustomTest extends TestCase
$this->assertFalse($list->hasItems(), 'There should have been no documents in the list');
}
public function testArraySucceedsWhenDataIsFound()
#[TestDox('array() succeeds when data is found')]
public function testArraySucceedsWhenDataIsFound(): void
{
$array = Custom::array(Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE data->>'sub' IS NOT NULL", [],
new DocumentMapper(TestDocument::class));
@@ -81,7 +86,8 @@ class CustomTest extends TestCase
$this->assertCount(2, $array, 'There should have been 2 documents in the array');
}
public function testArraySucceedsWhenNoDataIsFound()
#[TestDox('array() succeeds when no data is found')]
public function testArraySucceedsWhenNoDataIsFound(): void
{
$array = Custom::array(Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE data->>'value' = :value",
[':value' => 'not there'], new DocumentMapper(TestDocument::class));
@@ -89,6 +95,7 @@ class CustomTest extends TestCase
$this->assertCount(0, $array, 'There should have been no documents in the array');
}
#[TestDox('single() succeeds when a row is found')]
public function testSingleSucceedsWhenARowIsFound(): void
{
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id", [':id' => 'one'],
@@ -97,6 +104,7 @@ class CustomTest extends TestCase
$this->assertEquals('one', $doc->get()->id, 'The incorrect document was returned');
}
#[TestDox('single() succeeds when a row is not found')]
public function testSingleSucceedsWhenARowIsNotFound(): void
{
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id",
@@ -104,14 +112,16 @@ class CustomTest extends TestCase
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
}
public function testNonQuerySucceedsWhenOperatingOnData()
#[TestDox('nonQuery() succeeds when operating on data')]
public function testNonQuerySucceedsWhenOperatingOnData(): void
{
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
$remaining = Count::all(ThrowawayDb::TABLE);
$this->assertEquals(0, $remaining, 'There should be no documents remaining in the table');
}
public function testNonQuerySucceedsWhenNoDataMatchesWhereClause()
#[TestDox('nonQuery() succeeds when no data matches WHERE clause')]
public function testNonQuerySucceedsWhenNoDataMatchesWhereClause(): void
{
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE . " WHERE (data->>'num_value')::numeric > :value",
[':value' => 100]);
@@ -119,7 +129,8 @@ class CustomTest extends TestCase
$this->assertEquals(5, $remaining, 'There should be 5 documents remaining in the table');
}
public function testScalarSucceeds()
#[TestDox('scalar() succeeds')]
public function testScalarSucceeds(): void
{
$value = Custom::scalar("SELECT 5 AS it", [], new CountMapper());
$this->assertEquals(5, $value, 'The scalar value was not returned correctly');