Daniel J. Summers
486028bd40
- Changes `items` and `hasItems` on `DocumentList` to be properties - Updates dependent option/result library, which contains similar changes Reviewed-on: #7
99 lines
3.5 KiB
PHP
99 lines
3.5 KiB
PHP
<?php
|
|
/**
|
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
|
* @license MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Test\Integration\SQLite;
|
|
|
|
use BitBadger\PDODocument\{DocumentException, Field, Find, RemoveFields};
|
|
use PHPUnit\Framework\Attributes\TestDox;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Test\Integration\TestDocument;
|
|
|
|
/**
|
|
* SQLite integration tests for the RemoveFields class
|
|
*/
|
|
#[TestDox('Remove Fields (SQLite integration)')]
|
|
class RemoveFieldsTest extends TestCase
|
|
{
|
|
/** @var string Database name for throwaway database */
|
|
private string $dbName;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->dbName = ThrowawayDb::create();
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
ThrowawayDb::destroy($this->dbName);
|
|
parent::tearDown();
|
|
}
|
|
|
|
#[TestDox('byId() succeeds when fields are removed')]
|
|
public function testByIdSucceedsWhenFieldsAreRemoved(): void
|
|
{
|
|
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->value;
|
|
$this->assertEquals('', $doc->value, 'Value should have been blank (its default value)');
|
|
$this->assertNull($doc->sub, 'Sub-document should have been null');
|
|
}
|
|
|
|
#[TestDox('byId() succeeds when a field is not removed')]
|
|
public function testByIdSucceedsWhenAFieldIsNotRemoved(): void
|
|
{
|
|
RemoveFields::byId(ThrowawayDb::TABLE, 'one', ['a_field_that_does_not_exist']);
|
|
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
|
}
|
|
|
|
#[TestDox('byId() succeeds when no document is matched')]
|
|
public function testByIdSucceedsWhenNoDocumentIsMatched(): void
|
|
{
|
|
RemoveFields::byId(ThrowawayDb::TABLE, 'fifty', ['sub']);
|
|
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
|
}
|
|
|
|
#[TestDox('byFields() succeeds when a field is removed')]
|
|
public function testByFieldsSucceedsWhenAFieldIsRemoved(): void
|
|
{
|
|
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->value->sub, 'Sub-document should have been null');
|
|
}
|
|
|
|
#[TestDox('byFields() succeeds when a field is not removed')]
|
|
public function testByFieldsSucceedsWhenAFieldIsNotRemoved(): void
|
|
{
|
|
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], ['nada']);
|
|
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
|
}
|
|
|
|
#[TestDox('byFields() succeeds when no document is matched')]
|
|
public function testByFieldsSucceedsWhenNoDocumentIsMatched(): void
|
|
{
|
|
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::notEqual('missing', 'nope')], ['value']);
|
|
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
|
}
|
|
|
|
#[TestDox('byContains() fails')]
|
|
public function testByContainsFails(): void
|
|
{
|
|
$this->expectException(DocumentException::class);
|
|
RemoveFields::byContains('', [], []);
|
|
}
|
|
|
|
#[TestDox('byJsonPath() fails')]
|
|
public function testByJsonPathFails(): void
|
|
{
|
|
$this->expectException(DocumentException::class);
|
|
RemoveFields::byJsonPath('', '', []);
|
|
}
|
|
}
|