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:
@@ -35,7 +35,7 @@ class DocumentTest extends TestCase
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for array no auto ID')]
|
||||
#[TestDox('insert() succeeds for array no auto ID')]
|
||||
public function testInsertSucceedsForArrayNoAutoId(): void
|
||||
{
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => 'turkey', 'sub' => ['foo' => 'gobble', 'bar' => 'gobble']]);
|
||||
@@ -50,7 +50,7 @@ class DocumentTest extends TestCase
|
||||
$this->assertEquals('gobble', $doc->sub->bar, 'The sub-document bar property was incorrect');
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for array with auto number ID not provided')]
|
||||
#[TestDox('insert() succeeds for array with auto number ID not provided')]
|
||||
public function testInsertSucceedsForArrayWithAutoNumberIdNotProvided(): void
|
||||
{
|
||||
Configuration::$autoId = AutoId::Number;
|
||||
@@ -74,7 +74,7 @@ class DocumentTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for array with auto number ID with ID provided')]
|
||||
#[TestDox('insert() succeeds for array with auto number ID with ID provided')]
|
||||
public function testInsertSucceedsForArrayWithAutoNumberIdWithIdProvided(): void
|
||||
{
|
||||
Configuration::$autoId = AutoId::Number;
|
||||
@@ -90,14 +90,14 @@ class DocumentTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for array with auto UUID ID not provided')]
|
||||
#[TestDox('insert() succeeds for array with auto UUID ID not provided')]
|
||||
public function testInsertSucceedsForArrayWithAutoUuidIdNotProvided(): void
|
||||
{
|
||||
Configuration::$autoId = AutoId::UUID;
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => '', 'num_value' => 5]);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 5)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 5)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertNotEmpty($doc->get()->id, 'The ID should have been auto-generated');
|
||||
} finally {
|
||||
@@ -105,7 +105,7 @@ class DocumentTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for array with auto UUID ID with ID provided')]
|
||||
#[TestDox('insert() succeeds for array with auto UUID ID with ID provided')]
|
||||
public function testInsertSucceedsForArrayWithAutoUuidIdWithIdProvided(): void
|
||||
{
|
||||
Configuration::$autoId = AutoId::UUID;
|
||||
@@ -113,7 +113,7 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
$uuid = AutoId::generateUUID();
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => $uuid, 'value' => 'uuid', 'num_value' => 12]);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 12)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 12)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals($uuid, $doc->get()->id, 'The ID should not have been changed');
|
||||
} finally {
|
||||
@@ -121,7 +121,7 @@ class DocumentTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for array with auto string ID not provided')]
|
||||
#[TestDox('insert() succeeds for array with auto string ID not provided')]
|
||||
public function testInsertSucceedsForArrayWithAutoStringIdNotProvided(): void
|
||||
{
|
||||
Configuration::$autoId = AutoId::RandomString;
|
||||
@@ -129,7 +129,7 @@ class DocumentTest extends TestCase
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => '', 'value' => 'new', 'num_value' => 8]);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 8)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 8)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals(6, strlen($doc->get()->id),
|
||||
'The ID should have been auto-generated and had 6 characters');
|
||||
@@ -139,14 +139,14 @@ class DocumentTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for array with auto string ID with ID provided')]
|
||||
#[TestDox('insert() succeeds for array with auto string ID with ID provided')]
|
||||
public function testInsertSucceedsForArrayWithAutoStringIdWithIdProvided(): void
|
||||
{
|
||||
Configuration::$autoId = AutoId::RandomString;
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => 'my-key', 'value' => 'old', 'num_value' => 3]);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 3)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 3)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('my-key', $doc->get()->id, 'The ID should not have been changed');
|
||||
} finally {
|
||||
@@ -154,7 +154,7 @@ class DocumentTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for object no auto ID')]
|
||||
#[TestDox('insert() succeeds for object no auto ID')]
|
||||
public function testInsertSucceedsForObjectNoAutoId(): void
|
||||
{
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument('turkey', sub: new SubDocument('gobble', 'gobble')));
|
||||
@@ -169,7 +169,7 @@ class DocumentTest extends TestCase
|
||||
$this->assertEquals('gobble', $doc->sub->bar, 'The sub-document bar property was incorrect');
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for object with auto number ID not provided')]
|
||||
#[TestDox('insert() succeeds for object with auto number ID not provided')]
|
||||
public function testInsertSucceedsForObjectWithAutoNumberIdNotProvided(): void
|
||||
{
|
||||
Configuration::$autoId = AutoId::Number;
|
||||
@@ -177,12 +177,12 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
|
||||
Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'taco'));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'taco')], NumDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'taco')], NumDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals(1, $doc->get()->id, 'The ID 1 should have been auto-generated');
|
||||
|
||||
Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'burrito'));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'burrito')], NumDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'burrito')], NumDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals(2, $doc->get()->id, 'The ID 2 should have been auto-generated');
|
||||
} finally {
|
||||
@@ -190,14 +190,14 @@ class DocumentTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for object with auto number ID with ID provided')]
|
||||
#[TestDox('insert() succeeds for object with auto number ID with ID provided')]
|
||||
public function testInsertSucceedsForObjectWithAutoNumberIdWithIdProvided(): void
|
||||
{
|
||||
Configuration::$autoId = AutoId::Number;
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, new NumDocument(64, 'large'));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'large')], NumDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'large')], NumDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals(64, $doc->get()->id, 'The ID 64 should have been stored');
|
||||
} finally {
|
||||
@@ -205,14 +205,14 @@ class DocumentTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for object with auto UUID ID not provided')]
|
||||
#[TestDox('insert() succeeds for object with auto UUID ID not provided')]
|
||||
public function testInsertSucceedsForObjectWithAutoUuidIdNotProvided(): void
|
||||
{
|
||||
Configuration::$autoId = AutoId::UUID;
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument(value: 'something', num_value: 9));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EX('value')], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::exists('value')], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertNotEmpty($doc->get()->id, 'The ID should have been auto-generated');
|
||||
} finally {
|
||||
@@ -220,7 +220,7 @@ class DocumentTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for object with auto UUID ID with ID provided')]
|
||||
#[TestDox('insert() succeeds for object with auto UUID ID with ID provided')]
|
||||
public function testInsertSucceedsForObjectWithAutoUuidIdWithIdProvided(): void
|
||||
{
|
||||
Configuration::$autoId = AutoId::UUID;
|
||||
@@ -228,7 +228,7 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
$uuid = AutoId::generateUUID();
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument($uuid, num_value: 14));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 14)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 14)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals($uuid, $doc->get()->id, 'The ID should not have been changed');
|
||||
} finally {
|
||||
@@ -236,7 +236,7 @@ class DocumentTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for object with auto string ID not provided')]
|
||||
#[TestDox('insert() succeeds for object with auto string ID not provided')]
|
||||
public function testInsertSucceedsForObjectWithAutoStringIdNotProvided(): void
|
||||
{
|
||||
Configuration::$autoId = AutoId::RandomString;
|
||||
@@ -244,7 +244,7 @@ class DocumentTest extends TestCase
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument(num_value: 55));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 55)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 55)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals(40, strlen($doc->get()->id),
|
||||
'The ID should have been auto-generated and had 40 characters');
|
||||
@@ -254,14 +254,14 @@ class DocumentTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for object with auto string ID with ID provided')]
|
||||
#[TestDox('insert() succeeds for object with auto string ID with ID provided')]
|
||||
public function testInsertSucceedsForObjectWithAutoStringIdWithIdProvided(): void
|
||||
{
|
||||
Configuration::$autoId = AutoId::RandomString;
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument('my-key', num_value: 3));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 3)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 3)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('my-key', $doc->get()->id, 'The ID should not have been changed');
|
||||
} finally {
|
||||
@@ -269,12 +269,14 @@ class DocumentTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('insert() fails for duplicate key')]
|
||||
public function testInsertFailsForDuplicateKey(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument('one'));
|
||||
}
|
||||
|
||||
#[TestDox('save() succeeds when a document is inserted')]
|
||||
public function testSaveSucceedsWhenADocumentIsInserted(): void
|
||||
{
|
||||
Document::save(ThrowawayDb::TABLE, new TestDocument('test', sub: new SubDocument('a', 'b')));
|
||||
@@ -282,6 +284,7 @@ class DocumentTest extends TestCase
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
}
|
||||
|
||||
#[TestDox('save() succeeds when a document is updated')]
|
||||
public function testSaveSucceedsWhenADocumentIsUpdated(): void
|
||||
{
|
||||
Document::save(ThrowawayDb::TABLE, new TestDocument('two', num_value: 44));
|
||||
@@ -292,6 +295,7 @@ class DocumentTest extends TestCase
|
||||
$this->assertNull($doc->sub, 'The sub-document should have been null');
|
||||
}
|
||||
|
||||
#[TestDox('update() succeeds when replacing a document')]
|
||||
public function testUpdateSucceedsWhenReplacingADocument(): void
|
||||
{
|
||||
Document::update(ThrowawayDb::TABLE, 'one', new TestDocument('one', 'howdy', 8, new SubDocument('y', 'z')));
|
||||
@@ -305,6 +309,7 @@ class DocumentTest extends TestCase
|
||||
$this->assertEquals('z', $doc->sub->bar, 'The sub-document bar property was incorrect');
|
||||
}
|
||||
|
||||
#[TestDox('update() succeeds when no document is replaced')]
|
||||
public function testUpdateSucceedsWhenNoDocumentIsReplaced(): void
|
||||
{
|
||||
Document::update(ThrowawayDb::TABLE, 'two-hundred', new TestDocument('200'));
|
||||
|
||||
Reference in New Issue
Block a user