Implement In/InArray

- WIP on testdox name changes
This commit is contained in:
2024-09-22 17:44:07 -04:00
parent e830b1ac3e
commit 294b608ac8
9 changed files with 402 additions and 116 deletions

View File

@@ -20,18 +20,19 @@ use Test\{PjsonDocument, PjsonId};
#[TestDox('Parameters (Unit tests)')]
class ParametersTest extends TestCase
{
#[TestDox('ID succeeds with string')]
#[TestDox('id() succeeds with string')]
public function testIdSucceedsWithString(): void
{
$this->assertEquals([':id' => 'key'], Parameters::id('key'), 'ID parameter not constructed correctly');
}
#[TestDox('ID succeeds with non string')]
#[TestDox('id() succeeds with non string')]
public function testIdSucceedsWithNonString(): void
{
$this->assertEquals([':id' => '7'], Parameters::id(7), 'ID parameter not constructed correctly');
}
#[TestDox('json() succeeds for array')]
public function testJsonSucceedsForArray(): void
{
$this->assertEquals([':it' => '{"id":18,"url":"https://www.unittest.com"}'],
@@ -39,20 +40,21 @@ class ParametersTest extends TestCase
'JSON parameter not constructed correctly');
}
#[TestDox('json() succeeds for array with empty array parameter')]
public function testJsonSucceedsForArrayWithEmptyArrayParameter(): void
{
$this->assertEquals([':it' => '{"id":18,"urls":[]}'], Parameters::json(':it', ['id' => 18, 'urls' => []]),
'JSON parameter not constructed correctly');
}
#[TestDox('json succeeds for 1D array with empty array parameter')]
#[TestDox('json() succeeds for 1D array with empty array parameter')]
public function testJsonSucceedsFor1DArrayWithEmptyArrayParameter(): void
{
$this->assertEquals([':it' => '{"urls":[]}'], Parameters::json(':it', ['urls' => []]),
'JSON parameter not constructed correctly');
}
#[TestDox('json succeeds for stdClass')]
#[TestDox('json() succeeds for stdClass')]
public function testJsonSucceedsForStdClass(): void
{
$obj = new stdClass();
@@ -62,6 +64,7 @@ class ParametersTest extends TestCase
'JSON parameter not constructed correctly');
}
#[TestDox('json() succeeds for Pjson class')]
public function testJsonSucceedsForPjsonClass(): void
{
$this->assertEquals([':it' => '{"id":"999","name":"a test","num_value":98}'],
@@ -69,6 +72,7 @@ class ParametersTest extends TestCase
'JSON parameter not constructed correctly');
}
#[TestDox('json() succeeds for array of Pjson class')]
public function testJsonSucceedsForArrayOfPjsonClass(): void
{
$this->assertEquals([':it' => '{"pjson":[{"id":"997","name":"another test","num_value":94}]}'],
@@ -77,6 +81,7 @@ class ParametersTest extends TestCase
'JSON parameter not constructed correctly');
}
#[TestDox('nameFields() succeeds')]
public function testNameFieldsSucceeds(): void
{
$named = Parameters::nameFields(
@@ -87,6 +92,7 @@ class ParametersTest extends TestCase
$this->assertEquals(':field2', $named[2]->paramName, 'Parameter 3 not named correctly');
}
#[TestDox('addFields() succeeds')]
public function testAddFieldsSucceeds(): void
{
$this->assertEquals([':a' => 1, ':b' => 'two', ':z' => 18],
@@ -94,7 +100,7 @@ class ParametersTest extends TestCase
'Field parameters not added correctly');
}
#[TestDox('Field names succeeds for PostgreSQL')]
#[TestDox('fieldNames() succeeds for PostgreSQL')]
public function testFieldNamesSucceedsForPostgreSQL(): void
{
try {
@@ -106,7 +112,7 @@ class ParametersTest extends TestCase
}
}
#[TestDox('Field names succeeds for SQLite')]
#[TestDox('fieldNames() succeeds for SQLite')]
public function testFieldNamesSucceedsForSQLite(): void
{
try {
@@ -118,6 +124,7 @@ class ParametersTest extends TestCase
}
}
#[TestDox('fieldNames() fails when mode not set')]
public function testFieldNamesFailsWhenModeNotSet(): void
{
$this->expectException(DocumentException::class);