Update to PHP 8.4, new option lib
This commit is contained in:
@@ -100,8 +100,8 @@ class CustomTest extends TestCase
|
||||
{
|
||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id", [':id' => 'one'],
|
||||
new DocumentMapper(TestDocument::class));
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('one', $doc->get()->id, 'The incorrect document was returned');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals('one', $doc->value->id, 'The incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('single() succeeds when a row is not found')]
|
||||
@@ -109,7 +109,7 @@ class CustomTest extends TestCase
|
||||
{
|
||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id",
|
||||
[':id' => 'eighty'], new DocumentMapper(TestDocument::class));
|
||||
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||
$this->assertTrue($doc->isNone, 'There should not have been a document returned');
|
||||
}
|
||||
|
||||
#[TestDox('nonQuery() succeeds when operating on data')]
|
||||
|
||||
@@ -40,8 +40,8 @@ class DocumentTest extends TestCase
|
||||
{
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => 'turkey', 'sub' => ['foo' => 'gobble', 'bar' => 'gobble']]);
|
||||
$tryDoc = Find::byId(ThrowawayDb::TABLE, 'turkey', TestDocument::class);
|
||||
$this->assertTrue($tryDoc->isSome(), 'There should have been a document inserted');
|
||||
$doc = $tryDoc->get();
|
||||
$this->assertTrue($tryDoc->isSome, 'There should have been a document inserted');
|
||||
$doc = $tryDoc->value;
|
||||
$this->assertEquals('turkey', $doc->id, 'The ID was incorrect');
|
||||
$this->assertEquals('', $doc->value, 'The value was incorrect');
|
||||
$this->assertEquals(0, $doc->num_value, 'The numeric value was incorrect');
|
||||
@@ -59,15 +59,15 @@ class DocumentTest extends TestCase
|
||||
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => 0, 'value' => 'new', 'num_value' => 8]);
|
||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE, [], new ArrayMapper());
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$obj = json_decode($doc->get()['data']);
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$obj = json_decode($doc->value['data']);
|
||||
$this->assertEquals(1, $obj->id, 'The ID 1 should have been auto-generated');
|
||||
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => 0, 'value' => 'again', 'num_value' => 7]);
|
||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE " . Query::whereById(docId: 2),
|
||||
[':id' => 2], new ArrayMapper());
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$obj = json_decode($doc->get()['data']);
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$obj = json_decode($doc->value['data']);
|
||||
$this->assertEquals(2, $obj->id, 'The ID 2 should have been auto-generated');
|
||||
} finally {
|
||||
Configuration::$autoId = AutoId::None;
|
||||
@@ -82,8 +82,8 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => 7, 'value' => 'new', 'num_value' => 8]);
|
||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE, [], new ArrayMapper());
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$obj = json_decode($doc->get()['data']);
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$obj = json_decode($doc->value['data']);
|
||||
$this->assertEquals(7, $obj->id, 'The ID 7 should have been stored');
|
||||
} finally {
|
||||
Configuration::$autoId = AutoId::None;
|
||||
@@ -98,8 +98,8 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => '', 'num_value' => 5]);
|
||||
$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');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertNotEmpty($doc->value->id, 'The ID should have been auto-generated');
|
||||
} finally {
|
||||
Configuration::$autoId = AutoId::None;
|
||||
}
|
||||
@@ -114,8 +114,8 @@ class DocumentTest extends TestCase
|
||||
$uuid = AutoId::generateUUID();
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => $uuid, 'value' => 'uuid', 'num_value' => 12]);
|
||||
$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');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals($uuid, $doc->value->id, 'The ID should not have been changed');
|
||||
} finally {
|
||||
Configuration::$autoId = AutoId::None;
|
||||
}
|
||||
@@ -130,8 +130,8 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => '', 'value' => 'new', 'num_value' => 8]);
|
||||
$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),
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals(6, strlen($doc->value->id),
|
||||
'The ID should have been auto-generated and had 6 characters');
|
||||
} finally {
|
||||
Configuration::$autoId = AutoId::None;
|
||||
@@ -147,8 +147,8 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => 'my-key', 'value' => 'old', 'num_value' => 3]);
|
||||
$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');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals('my-key', $doc->value->id, 'The ID should not have been changed');
|
||||
} finally {
|
||||
Configuration::$autoId = AutoId::None;
|
||||
}
|
||||
@@ -159,8 +159,8 @@ class DocumentTest extends TestCase
|
||||
{
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument('turkey', sub: new SubDocument('gobble', 'gobble')));
|
||||
$tryDoc = Find::byId(ThrowawayDb::TABLE, 'turkey', TestDocument::class);
|
||||
$this->assertTrue($tryDoc->isSome(), 'There should have been a document inserted');
|
||||
$doc = $tryDoc->get();
|
||||
$this->assertTrue($tryDoc->isSome, 'There should have been a document inserted');
|
||||
$doc = $tryDoc->value;
|
||||
$this->assertEquals('turkey', $doc->id, 'The ID was incorrect');
|
||||
$this->assertEquals('', $doc->value, 'The value was incorrect');
|
||||
$this->assertEquals(0, $doc->num_value, 'The numeric value was incorrect');
|
||||
@@ -178,13 +178,13 @@ class DocumentTest extends TestCase
|
||||
|
||||
Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'taco'));
|
||||
$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');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals(1, $doc->value->id, 'The ID 1 should have been auto-generated');
|
||||
|
||||
Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'burrito'));
|
||||
$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');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals(2, $doc->value->id, 'The ID 2 should have been auto-generated');
|
||||
} finally {
|
||||
Configuration::$autoId = AutoId::None;
|
||||
}
|
||||
@@ -198,8 +198,8 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, new NumDocument(64, 'large'));
|
||||
$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');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals(64, $doc->value->id, 'The ID 64 should have been stored');
|
||||
} finally {
|
||||
Configuration::$autoId = AutoId::None;
|
||||
}
|
||||
@@ -213,8 +213,8 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument(value: 'something', num_value: 9));
|
||||
$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');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertNotEmpty($doc->value->id, 'The ID should have been auto-generated');
|
||||
} finally {
|
||||
Configuration::$autoId = AutoId::None;
|
||||
}
|
||||
@@ -229,8 +229,8 @@ class DocumentTest extends TestCase
|
||||
$uuid = AutoId::generateUUID();
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument($uuid, num_value: 14));
|
||||
$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');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals($uuid, $doc->value->id, 'The ID should not have been changed');
|
||||
} finally {
|
||||
Configuration::$autoId = AutoId::None;
|
||||
}
|
||||
@@ -245,8 +245,8 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument(num_value: 55));
|
||||
$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),
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals(40, strlen($doc->value->id),
|
||||
'The ID should have been auto-generated and had 40 characters');
|
||||
} finally {
|
||||
Configuration::$autoId = AutoId::None;
|
||||
@@ -262,8 +262,8 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument('my-key', num_value: 3));
|
||||
$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');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals('my-key', $doc->value->id, 'The ID should not have been changed');
|
||||
} finally {
|
||||
Configuration::$autoId = AutoId::None;
|
||||
}
|
||||
@@ -281,7 +281,7 @@ class DocumentTest extends TestCase
|
||||
{
|
||||
Document::save(ThrowawayDb::TABLE, new TestDocument('test', sub: new SubDocument('a', 'b')));
|
||||
$doc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
}
|
||||
|
||||
#[TestDox('save() succeeds when a document is updated')]
|
||||
@@ -289,8 +289,8 @@ class DocumentTest extends TestCase
|
||||
{
|
||||
Document::save(ThrowawayDb::TABLE, new TestDocument('two', num_value: 44));
|
||||
$tryDoc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class);
|
||||
$this->assertTrue($tryDoc->isSome(), 'There should have been a document returned');
|
||||
$doc = $tryDoc->get();
|
||||
$this->assertTrue($tryDoc->isSome, 'There should have been a document returned');
|
||||
$doc = $tryDoc->value;
|
||||
$this->assertEquals(44, $doc->num_value, 'The numeric value was not updated');
|
||||
$this->assertNull($doc->sub, 'The sub-document should have been null');
|
||||
}
|
||||
@@ -300,8 +300,8 @@ class DocumentTest extends TestCase
|
||||
{
|
||||
Document::update(ThrowawayDb::TABLE, 'one', new TestDocument('one', 'howdy', 8, new SubDocument('y', 'z')));
|
||||
$tryDoc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class);
|
||||
$this->assertNotFalse($tryDoc->isSome(), 'There should have been a document returned');
|
||||
$doc = $tryDoc->get();
|
||||
$this->assertNotFalse($tryDoc->isSome, 'There should have been a document returned');
|
||||
$doc = $tryDoc->value;
|
||||
$this->assertEquals('howdy', $doc->value, 'The value was incorrect');
|
||||
$this->assertEquals(8, $doc->num_value, 'The numeric value was incorrect');
|
||||
$this->assertNotNull($doc->sub, 'The sub-document should not have been null');
|
||||
@@ -314,6 +314,6 @@ class DocumentTest extends TestCase
|
||||
{
|
||||
Document::update(ThrowawayDb::TABLE, 'two-hundred', new TestDocument('200'));
|
||||
$doc = Find::byId(ThrowawayDb::TABLE, 'two-hundred', TestDocument::class);
|
||||
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||
$this->assertTrue($doc->isNone, 'There should not have been a document returned');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,8 +85,8 @@ class FindTest extends TestCase
|
||||
public function testByIdSucceedsWhenADocumentIsFound(): void
|
||||
{
|
||||
$doc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('two', $doc->get()->id, 'An incorrect document was returned');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals('two', $doc->value->id, 'An incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('byId() succeeds when a document is found with numeric ID')]
|
||||
@@ -95,15 +95,15 @@ class FindTest extends TestCase
|
||||
Delete::byFields(ThrowawayDb::TABLE, [Field::notExists('absent')]);
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => 18, 'value' => 'howdy']);
|
||||
$doc = Find::byId(ThrowawayDb::TABLE, 18, NumDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals(18, $doc->get()->id, 'An incorrect document was returned');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals(18, $doc->value->id, 'An incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('byId() succeeds when a document is not found')]
|
||||
public function testByIdSucceedsWhenADocumentIsNotFound(): void
|
||||
{
|
||||
$doc = Find::byId(ThrowawayDb::TABLE, 'seventy-five', TestDocument::class);
|
||||
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||
$this->assertTrue($doc->isNone, 'There should not have been a document returned');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds when documents are found')]
|
||||
@@ -229,16 +229,16 @@ class FindTest extends TestCase
|
||||
public function testFirstByFieldsSucceedsWhenADocumentIsFound(): void
|
||||
{
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'another')], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('two', $doc->get()->id, 'The incorrect document was returned');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals('two', $doc->value->id, 'The incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('firstByFields() succeeds when multiple documents are found')]
|
||||
public function testFirstByFieldsSucceedsWhenMultipleDocumentsAreFound(): void
|
||||
{
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('sub.foo', 'green')], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertContains($doc->get()->id, ['two', 'four'], 'An incorrect document was returned');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertContains($doc->value->id, ['two', 'four'], 'An incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('firstByFields() succeeds when multiple ordered documents are found')]
|
||||
@@ -246,31 +246,31 @@ class FindTest extends TestCase
|
||||
{
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('sub.foo', 'green')], TestDocument::class,
|
||||
orderBy: [Field::named('n:num_value DESC')]);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('four', $doc->get()->id, 'The incorrect document was returned');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals('four', $doc->value->id, 'The incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('firstByFields() succeeds when a document is not found')]
|
||||
public function testFirstByFieldsSucceedsWhenADocumentIsNotFound(): void
|
||||
{
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'absent')], TestDocument::class);
|
||||
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||
$this->assertTrue($doc->isNone, 'There should not have been a document returned');
|
||||
}
|
||||
|
||||
#[TestDox('firstByContains() succeeds when a document is found')]
|
||||
public function testFirstByContainsSucceedsWhenADocumentIsFound(): void
|
||||
{
|
||||
$doc = Find::firstByContains(ThrowawayDb::TABLE, ['value' => 'FIRST!'], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('one', $doc->get()->id, 'The incorrect document was returned');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals('one', $doc->value->id, 'The incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('firstByContains() succeeds when multiple documents are found')]
|
||||
public function testFirstByContainsSucceedsWhenMultipleDocumentsAreFound(): void
|
||||
{
|
||||
$doc = Find::firstByContains(ThrowawayDb::TABLE, ['value' => 'purple'], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertContains($doc->get()->id, ['four', 'five'], 'An incorrect document was returned');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertContains($doc->value->id, ['four', 'five'], 'An incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('firstByContains() succeeds when multiple ordered documents are found')]
|
||||
@@ -278,31 +278,31 @@ class FindTest extends TestCase
|
||||
{
|
||||
$doc = Find::firstByContains(ThrowawayDb::TABLE, ['value' => 'purple'], TestDocument::class,
|
||||
[Field::named('sub.bar NULLS FIRST')]);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('five', $doc->get()->id, 'The incorrect document was returned');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals('five', $doc->value->id, 'The incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('firstByContains() succeeds when a document is not found')]
|
||||
public function testFirstByContainsSucceedsWhenADocumentIsNotFound(): void
|
||||
{
|
||||
$doc = Find::firstByContains(ThrowawayDb::TABLE, ['value' => 'indigo'], TestDocument::class);
|
||||
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||
$this->assertTrue($doc->isNone, 'There should not have been a document returned');
|
||||
}
|
||||
|
||||
#[TestDox('firstByJsonPath() succeeds when a document is found')]
|
||||
public function testFirstByJsonPathSucceedsWhenADocumentIsFound(): void
|
||||
{
|
||||
$doc = Find::firstByJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ == 10)', TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('two', $doc->get()->id, 'The incorrect document was returned');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals('two', $doc->value->id, 'The incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('firstByJsonPath() succeeds when multiple documents are found')]
|
||||
public function testFirstByJsonPathSucceedsWhenMultipleDocumentsAreFound(): void
|
||||
{
|
||||
$doc = Find::firstByJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 10)', TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertContains($doc->get()->id, ['four', 'five'], 'An incorrect document was returned');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertContains($doc->value->id, ['four', 'five'], 'An incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('firstByJsonPath() succeeds when multiple ordered documents are found')]
|
||||
@@ -310,14 +310,14 @@ class FindTest extends TestCase
|
||||
{
|
||||
$doc = Find::firstByJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 10)', TestDocument::class,
|
||||
[Field::named('id DESC')]);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('four', $doc->get()->id, 'The incorrect document was returned');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals('four', $doc->value->id, 'The incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('firstByJsonPath() succeeds when a document is not found')]
|
||||
public function testFirstByJsonPathSucceedsWhenADocumentIsNotFound(): void
|
||||
{
|
||||
$doc = Find::firstByJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 100)', TestDocument::class);
|
||||
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||
$this->assertTrue($doc->isNone, 'There should not have been a document returned');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ class PatchTest extends TestCase
|
||||
{
|
||||
Patch::byId(ThrowawayDb::TABLE, 'one', ['num_value' => 44]);
|
||||
$doc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals(44, $doc->get()->num_value, 'The updated document is not correct');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals(44, $doc->value->num_value, 'The updated document is not correct');
|
||||
}
|
||||
|
||||
#[TestDox('byId() succeeds when no document is updated')]
|
||||
@@ -74,8 +74,8 @@ class PatchTest extends TestCase
|
||||
{
|
||||
Patch::byContains(ThrowawayDb::TABLE, ['value' => 'another'], ['num_value' => 12]);
|
||||
$tryDoc = Find::firstByContains(ThrowawayDb::TABLE, ['value' => 'another'], TestDocument::class);
|
||||
$this->assertTrue($tryDoc->isSome(), 'There should have been a document returned');
|
||||
$doc = $tryDoc->get();
|
||||
$this->assertTrue($tryDoc->isSome, 'There should have been a document returned');
|
||||
$doc = $tryDoc->value;
|
||||
$this->assertEquals('two', $doc->id, 'An incorrect document was returned');
|
||||
$this->assertEquals(12, $doc->num_value, 'The document was not patched');
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ class RemoveFieldsTest extends TestCase
|
||||
{
|
||||
RemoveFields::byId(ThrowawayDb::TABLE, 'two', ['sub', 'value']);
|
||||
$tryDoc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class);
|
||||
$this->assertTrue($tryDoc->isSome(), 'There should have been a document returned');
|
||||
$doc = $tryDoc->get();
|
||||
$this->assertTrue($tryDoc->isSome, 'There should have been a document returned');
|
||||
$doc = $tryDoc->value;
|
||||
$this->assertEquals('', $doc->value, 'Value should have been blank (its default value)');
|
||||
$this->assertNull($doc->sub, 'Sub-document should have been null');
|
||||
}
|
||||
@@ -64,8 +64,8 @@ class RemoveFieldsTest extends TestCase
|
||||
{
|
||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], ['sub']);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertNull($doc->get()->sub, 'Sub-document should have been null');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertNull($doc->value->sub, 'Sub-document should have been null');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds when a field is not removed')]
|
||||
|
||||
@@ -99,8 +99,8 @@ class CustomTest extends TestCase
|
||||
{
|
||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id", [':id' => 'one'],
|
||||
new DocumentMapper(TestDocument::class));
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('one', $doc->get()->id, 'The incorrect document was returned');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals('one', $doc->value->id, 'The incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('single() succeeds when a row is not found')]
|
||||
@@ -108,7 +108,7 @@ class CustomTest extends TestCase
|
||||
{
|
||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id",
|
||||
[':id' => 'eighty'], new DocumentMapper(TestDocument::class));
|
||||
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||
$this->assertTrue($doc->isNone, 'There should not have been a document returned');
|
||||
}
|
||||
|
||||
#[TestDox('nonQuery() succeeds when operating on data')]
|
||||
|
||||
@@ -40,8 +40,8 @@ class DocumentTest extends TestCase
|
||||
{
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => 'turkey', 'sub' => ['foo' => 'gobble', 'bar' => 'gobble']]);
|
||||
$tryDoc = Find::byId(ThrowawayDb::TABLE, 'turkey', TestDocument::class);
|
||||
$this->assertTrue($tryDoc->isSome(), 'There should have been a document inserted');
|
||||
$doc = $tryDoc->get();
|
||||
$this->assertTrue($tryDoc->isSome, 'There should have been a document inserted');
|
||||
$doc = $tryDoc->value;
|
||||
$this->assertEquals('turkey', $doc->id, 'The ID was incorrect');
|
||||
$this->assertEquals('', $doc->value, 'The value was incorrect');
|
||||
$this->assertEquals(0, $doc->num_value, 'The numeric value was incorrect');
|
||||
@@ -59,15 +59,15 @@ class DocumentTest extends TestCase
|
||||
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => 0, 'value' => 'new', 'num_value' => 8]);
|
||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE, [], new ArrayMapper());
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$obj = json_decode($doc->get()['data']);
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$obj = json_decode($doc->value['data']);
|
||||
$this->assertEquals(1, $obj->id, 'The ID 1 should have been auto-generated');
|
||||
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => 0, 'value' => 'again', 'num_value' => 7]);
|
||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = 2", [],
|
||||
new ArrayMapper());
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$obj = json_decode($doc->get()['data']);
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$obj = json_decode($doc->value['data']);
|
||||
$this->assertEquals(2, $obj->id, 'The ID 2 should have been auto-generated');
|
||||
} finally {
|
||||
Configuration::$autoId = AutoId::None;
|
||||
@@ -82,8 +82,8 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => 7, 'value' => 'new', 'num_value' => 8]);
|
||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE, [], new ArrayMapper());
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$obj = json_decode($doc->get()['data']);
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$obj = json_decode($doc->value['data']);
|
||||
$this->assertEquals(7, $obj->id, 'The ID 7 should have been stored');
|
||||
} finally {
|
||||
Configuration::$autoId = AutoId::None;
|
||||
@@ -98,8 +98,8 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => '', 'num_value' => 5]);
|
||||
$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');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertNotEmpty($doc->value->id, 'The ID should have been auto-generated');
|
||||
} finally {
|
||||
Configuration::$autoId = AutoId::None;
|
||||
}
|
||||
@@ -114,8 +114,8 @@ class DocumentTest extends TestCase
|
||||
$uuid = AutoId::generateUUID();
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => $uuid, 'value' => 'uuid', 'num_value' => 12]);
|
||||
$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');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals($uuid, $doc->value->id, 'The ID should not have been changed');
|
||||
} finally {
|
||||
Configuration::$autoId = AutoId::None;
|
||||
}
|
||||
@@ -130,8 +130,8 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => '', 'value' => 'new', 'num_value' => 8]);
|
||||
$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),
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals(6, strlen($doc->value->id),
|
||||
'The ID should have been auto-generated and had 6 characters');
|
||||
} finally {
|
||||
Configuration::$autoId = AutoId::None;
|
||||
@@ -147,8 +147,8 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => 'my-key', 'value' => 'old', 'num_value' => 3]);
|
||||
$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');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals('my-key', $doc->value->id, 'The ID should not have been changed');
|
||||
} finally {
|
||||
Configuration::$autoId = AutoId::None;
|
||||
}
|
||||
@@ -159,8 +159,8 @@ class DocumentTest extends TestCase
|
||||
{
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument('turkey', sub: new SubDocument('gobble', 'gobble')));
|
||||
$tryDoc = Find::byId(ThrowawayDb::TABLE, 'turkey', TestDocument::class);
|
||||
$this->assertNotFalse($tryDoc->isSome(), 'There should have been a document inserted');
|
||||
$doc = $tryDoc->get();
|
||||
$this->assertNotFalse($tryDoc->isSome, 'There should have been a document inserted');
|
||||
$doc = $tryDoc->value;
|
||||
$this->assertEquals('turkey', $doc->id, 'The ID was incorrect');
|
||||
$this->assertEquals('', $doc->value, 'The value was incorrect');
|
||||
$this->assertEquals(0, $doc->num_value, 'The numeric value was incorrect');
|
||||
@@ -178,13 +178,13 @@ class DocumentTest extends TestCase
|
||||
|
||||
Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'taco'));
|
||||
$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');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals(1, $doc->value->id, 'The ID 1 should have been auto-generated');
|
||||
|
||||
Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'burrito'));
|
||||
$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');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals(2, $doc->value->id, 'The ID 2 should have been auto-generated');
|
||||
} finally {
|
||||
Configuration::$autoId = AutoId::None;
|
||||
}
|
||||
@@ -198,8 +198,8 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, new NumDocument(64, 'large'));
|
||||
$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');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals(64, $doc->value->id, 'The ID 64 should have been stored');
|
||||
} finally {
|
||||
Configuration::$autoId = AutoId::None;
|
||||
}
|
||||
@@ -213,8 +213,8 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument(value: 'something', num_value: 9));
|
||||
$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');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertNotEmpty($doc->value->id, 'The ID should have been auto-generated');
|
||||
} finally {
|
||||
Configuration::$autoId = AutoId::None;
|
||||
}
|
||||
@@ -229,8 +229,8 @@ class DocumentTest extends TestCase
|
||||
$uuid = AutoId::generateUUID();
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument($uuid, num_value: 14));
|
||||
$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');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals($uuid, $doc->value->id, 'The ID should not have been changed');
|
||||
} finally {
|
||||
Configuration::$autoId = AutoId::None;
|
||||
}
|
||||
@@ -245,8 +245,8 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument(num_value: 55));
|
||||
$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),
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals(40, strlen($doc->value->id),
|
||||
'The ID should have been auto-generated and had 40 characters');
|
||||
} finally {
|
||||
Configuration::$autoId = AutoId::None;
|
||||
@@ -262,8 +262,8 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument('my-key', num_value: 3));
|
||||
$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');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals('my-key', $doc->value->id, 'The ID should not have been changed');
|
||||
} finally {
|
||||
Configuration::$autoId = AutoId::None;
|
||||
}
|
||||
@@ -281,7 +281,7 @@ class DocumentTest extends TestCase
|
||||
{
|
||||
Document::save(ThrowawayDb::TABLE, new TestDocument('test', sub: new SubDocument('a', 'b')));
|
||||
$doc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
}
|
||||
|
||||
#[TestDox('save() succeeds when a document is updated')]
|
||||
@@ -289,8 +289,8 @@ class DocumentTest extends TestCase
|
||||
{
|
||||
Document::save(ThrowawayDb::TABLE, new TestDocument('two', num_value: 44));
|
||||
$tryDoc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class);
|
||||
$this->assertTrue($tryDoc->isSome(), 'There should have been a document returned');
|
||||
$doc = $tryDoc->get();
|
||||
$this->assertTrue($tryDoc->isSome, 'There should have been a document returned');
|
||||
$doc = $tryDoc->value;
|
||||
$this->assertEquals(44, $doc->num_value, 'The numeric value was not updated');
|
||||
$this->assertNull($doc->sub, 'The sub-document should have been null');
|
||||
}
|
||||
@@ -300,8 +300,8 @@ class DocumentTest extends TestCase
|
||||
{
|
||||
Document::update(ThrowawayDb::TABLE, 'one', new TestDocument('one', 'howdy', 8, new SubDocument('y', 'z')));
|
||||
$tryDoc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class);
|
||||
$this->assertTrue($tryDoc->isSome(), 'There should have been a document returned');
|
||||
$doc = $tryDoc->get();
|
||||
$this->assertTrue($tryDoc->isSome, 'There should have been a document returned');
|
||||
$doc = $tryDoc->value;
|
||||
$this->assertEquals('howdy', $doc->value, 'The value was incorrect');
|
||||
$this->assertEquals(8, $doc->num_value, 'The numeric value was incorrect');
|
||||
$this->assertNotNull($doc->sub, 'The sub-document should not have been null');
|
||||
@@ -314,6 +314,6 @@ class DocumentTest extends TestCase
|
||||
{
|
||||
Document::update(ThrowawayDb::TABLE, 'two-hundred', new TestDocument('200'));
|
||||
$doc = Find::byId(ThrowawayDb::TABLE, 'two-hundred', TestDocument::class);
|
||||
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||
$this->assertTrue($doc->isNone, 'There should not have been a document returned');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,8 +86,8 @@ class FindTest extends TestCase
|
||||
public function testByIdSucceedsWhenADocumentIsFound(): void
|
||||
{
|
||||
$doc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('two', $doc->get()->id, 'An incorrect document was returned');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals('two', $doc->value->id, 'An incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('byId() succeeds when a document is found with numeric ID')]
|
||||
@@ -95,15 +95,15 @@ class FindTest extends TestCase
|
||||
{
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => 18, 'value' => 'howdy']);
|
||||
$doc = Find::byId(ThrowawayDb::TABLE, 18, TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('18', $doc->get()->id, 'An incorrect document was returned');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals('18', $doc->value->id, 'An incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('byId() succeeds when a document is not found')]
|
||||
public function testByIdSucceedsWhenADocumentIsNotFound(): void
|
||||
{
|
||||
$doc = Find::byId(ThrowawayDb::TABLE, 'seventy-five', TestDocument::class);
|
||||
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||
$this->assertTrue($doc->isNone, 'There should not have been a document returned');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds when documents are found')]
|
||||
@@ -187,16 +187,16 @@ class FindTest extends TestCase
|
||||
public function testFirstByFieldsSucceedsWhenADocumentIsFound(): void
|
||||
{
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'another')], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('two', $doc->get()->id, 'The incorrect document was returned');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals('two', $doc->value->id, 'The incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('firstByFields() succeeds when multiple documents are found')]
|
||||
public function testFirstByFieldsSucceedsWhenMultipleDocumentsAreFound(): void
|
||||
{
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('sub.foo', 'green')], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertContains($doc->get()->id, ['two', 'four'], 'An incorrect document was returned');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertContains($doc->value->id, ['two', 'four'], 'An incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('firstByFields() succeeds when multiple ordered documents are found')]
|
||||
@@ -204,15 +204,15 @@ class FindTest extends TestCase
|
||||
{
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('sub.foo', 'green')], TestDocument::class,
|
||||
orderBy: [Field::named('n:num_value DESC')]);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('four', $doc->get()->id, 'The incorrect document was returned');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals('four', $doc->value->id, 'The incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('firstByFields() succeeds when a document is not found')]
|
||||
public function testFirstByFieldsSucceedsWhenADocumentIsNotFound(): void
|
||||
{
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'absent')], TestDocument::class);
|
||||
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||
$this->assertTrue($doc->isNone, 'There should not have been a document returned');
|
||||
}
|
||||
|
||||
#[TestDox('firstByContains() fails')]
|
||||
|
||||
@@ -39,8 +39,8 @@ class PatchTest extends TestCase
|
||||
{
|
||||
Patch::byId(ThrowawayDb::TABLE, 'one', ['num_value' => 44]);
|
||||
$doc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals(44, $doc->get()->num_value, 'The updated document is not correct');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals(44, $doc->value->num_value, 'The updated document is not correct');
|
||||
}
|
||||
|
||||
#[TestDox('byId() succeeds when no document is updated')]
|
||||
|
||||
@@ -39,8 +39,8 @@ class RemoveFieldsTest extends TestCase
|
||||
{
|
||||
RemoveFields::byId(ThrowawayDb::TABLE, 'two', ['sub', 'value']);
|
||||
$tryDoc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class);
|
||||
$this->assertTrue($tryDoc->isSome(), 'There should have been a document returned');
|
||||
$doc = $tryDoc->get();
|
||||
$this->assertTrue($tryDoc->isSome, 'There should have been a document returned');
|
||||
$doc = $tryDoc->value;
|
||||
$this->assertEquals('', $doc->value, 'Value should have been blank (its default value)');
|
||||
$this->assertNull($doc->sub, 'Sub-document should have been null');
|
||||
}
|
||||
@@ -64,8 +64,8 @@ class RemoveFieldsTest extends TestCase
|
||||
{
|
||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], ['sub']);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertNull($doc->get()->sub, 'Sub-document should have been null');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertNull($doc->value->sub, 'Sub-document should have been null');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds when a field is not removed')]
|
||||
|
||||
@@ -22,7 +22,7 @@ class ArrayMapperTest extends TestCase
|
||||
public function testMapSucceeds(): void
|
||||
{
|
||||
$result = ['one' => 2, 'three' => 4, 'eight' => 'five'];
|
||||
$mapped = (new ArrayMapper())->map($result);
|
||||
$mapped = new ArrayMapper()->map($result);
|
||||
$this->assertSame($result, $mapped, 'The array mapper should return the parameter given to it');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,6 @@ class CountMapperTest extends TestCase
|
||||
#[TestDox('map() succeeds')]
|
||||
public function testMapSucceeds(): void
|
||||
{
|
||||
$this->assertEquals(5, (new CountMapper())->map([5, 8, 10]), 'Count not correct');
|
||||
$this->assertEquals(5, new CountMapper()->map([5, 8, 10]), 'Count not correct');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ class DocumentMapperTest extends TestCase
|
||||
#[TestDox('map() succeeds with valid JSON')]
|
||||
public function testMapSucceedsWithValidJSON(): void
|
||||
{
|
||||
$doc = (new DocumentMapper(TestDocument::class))->map(['data' => '{"id":7,"subDoc":{"id":22,"name":"tester"}}']);
|
||||
$doc = new DocumentMapper(TestDocument::class)->map(['data' => '{"id":7,"subDoc":{"id":22,"name":"tester"}}']);
|
||||
$this->assertNotNull($doc, 'The document should not have been null');
|
||||
$this->assertEquals(7, $doc->id, 'ID not filled correctly');
|
||||
$this->assertNotNull($doc->subDoc, 'The sub-document should not have been null');
|
||||
@@ -58,7 +58,7 @@ class DocumentMapperTest extends TestCase
|
||||
#[TestDox('map() succeeds with valid JSON for Pjson class')]
|
||||
public function testMapSucceedsWithValidJSONForPjsonClass(): void
|
||||
{
|
||||
$doc = (new DocumentMapper(PjsonDocument::class))->map(['data' => '{"id":"seven","name":"bob","num_value":8}']);
|
||||
$doc = new DocumentMapper(PjsonDocument::class)->map(['data' => '{"id":"seven","name":"bob","num_value":8}']);
|
||||
$this->assertNotNull($doc, 'The document should not have been null');
|
||||
$this->assertEquals(new PjsonId('seven'), $doc->id, 'ID not filled correctly');
|
||||
$this->assertEquals('bob', $doc->name, 'Name not filled correctly');
|
||||
@@ -70,13 +70,13 @@ class DocumentMapperTest extends TestCase
|
||||
public function testMapFailsWithInvalidJSON(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
(new DocumentMapper(TestDocument::class))->map(['data' => 'this is not valid']);
|
||||
new DocumentMapper(TestDocument::class)->map(['data' => 'this is not valid']);
|
||||
}
|
||||
|
||||
#[TestDox('map() fails with invalid JSON for Pjson class')]
|
||||
public function testMapFailsWithInvalidJSONForPjsonClass(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
(new DocumentMapper(PjsonDocument::class))->map(['data' => 'not even close']);
|
||||
new DocumentMapper(PjsonDocument::class)->map(['data' => 'not even close']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class ExistsMapperTest extends TestCase
|
||||
{
|
||||
try {
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
$this->assertFalse((new ExistsMapper())->map([false, 'nope']), 'Result should have been false');
|
||||
$this->assertFalse(new ExistsMapper()->map([false, 'nope']), 'Result should have been false');
|
||||
} finally {
|
||||
Configuration::overrideMode(null);
|
||||
}
|
||||
@@ -35,7 +35,7 @@ class ExistsMapperTest extends TestCase
|
||||
{
|
||||
try {
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
$this->assertTrue((new ExistsMapper())->map([1, 'yep']), 'Result should have been true');
|
||||
$this->assertTrue(new ExistsMapper()->map([1, 'yep']), 'Result should have been true');
|
||||
} finally {
|
||||
Configuration::overrideMode(null);
|
||||
}
|
||||
@@ -46,6 +46,6 @@ class ExistsMapperTest extends TestCase
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
Configuration::overrideMode(null);
|
||||
(new ExistsMapper())->map(['0']);
|
||||
new ExistsMapper()->map(['0']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user