Add support, custom, and other queries
This commit is contained in:
@@ -12,11 +12,13 @@ use PHPUnit\Framework\TestCase;
|
||||
*/
|
||||
class ConfigurationTest extends TestCase
|
||||
{
|
||||
#[TestDox('ID field default succeeds')]
|
||||
public function testIdFieldDefaultSucceeds(): void
|
||||
{
|
||||
$this->assertEquals('id', Configuration::$idField, 'Default ID field should be "id"');
|
||||
}
|
||||
|
||||
#[TestDox('ID field change succeeds')]
|
||||
public function testIdFieldChangeSucceeds()
|
||||
{
|
||||
try {
|
||||
|
||||
17
tests/unit/Mapper/CountMapperTest.php
Normal file
17
tests/unit/Mapper/CountMapperTest.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Test\Unit\Mapper;
|
||||
|
||||
use BitBadger\PDODocument\Mapper\CountMapper;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Unit tests for the CountMapper class
|
||||
*/
|
||||
class CountMapperTest extends TestCase
|
||||
{
|
||||
public function testMapSucceeds(): void
|
||||
{
|
||||
$this->assertEquals(5, (new CountMapper())->map([5, 8, 10]), 'Count not correct');
|
||||
}
|
||||
}
|
||||
45
tests/unit/Mapper/ExistsMapperTest.php
Normal file
45
tests/unit/Mapper/ExistsMapperTest.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Test\Unit\Mapper;
|
||||
|
||||
use BitBadger\PDODocument\Configuration;
|
||||
use BitBadger\PDODocument\DocumentException;
|
||||
use BitBadger\PDODocument\Mapper\ExistsMapper;
|
||||
use BitBadger\PDODocument\Mode;
|
||||
use PHPUnit\Framework\Attributes\TestDox;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Unit tests for the ExistsMapper class
|
||||
*/
|
||||
class ExistsMapperTest extends TestCase
|
||||
{
|
||||
#[TestDox('Map succeeds for PostgreSQL')]
|
||||
public function testMapSucceedsForPostgreSQL(): void
|
||||
{
|
||||
try {
|
||||
Configuration::$mode = Mode::PgSQL;
|
||||
$this->assertFalse((new ExistsMapper())->map([false, 'nope']), 'Result should have been false');
|
||||
} finally {
|
||||
Configuration::$mode = null;
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Map succeeds for SQLite')]
|
||||
public function testMapSucceedsForSQLite(): void
|
||||
{
|
||||
try {
|
||||
Configuration::$mode = Mode::SQLite;
|
||||
$this->assertTrue((new ExistsMapper())->map([1, 'yep']), 'Result should have been true');
|
||||
} finally {
|
||||
Configuration::$mode = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function testMapFailsWhenModeNotSet(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
Configuration::$mode = null;
|
||||
(new ExistsMapper())->map(['0']);
|
||||
}
|
||||
}
|
||||
83
tests/unit/ParametersTest.php
Normal file
83
tests/unit/ParametersTest.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use BitBadger\PDODocument\Configuration;
|
||||
use BitBadger\PDODocument\DocumentException;
|
||||
use BitBadger\PDODocument\Field;
|
||||
use BitBadger\PDODocument\Mode;
|
||||
use BitBadger\PDODocument\Parameters;
|
||||
use PHPUnit\Framework\Attributes\TestDox;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Unit tests for the Parameters class
|
||||
*/
|
||||
class ParametersTest extends TestCase
|
||||
{
|
||||
#[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')]
|
||||
public function testIdSucceedsWithNonString(): void
|
||||
{
|
||||
$this->assertEquals(['@id' => '7'], Parameters::id(7), 'ID parameter not constructed correctly');
|
||||
}
|
||||
|
||||
public function testJsonSucceeds(): void
|
||||
{
|
||||
$this->assertEquals(['@it' => '{"id":18,"url":"https://www.unittest.com"}'],
|
||||
Parameters::json('@it', ['id' => 18, 'url' => 'https://www.unittest.com']),
|
||||
'JSON parameter not constructed correctly');
|
||||
}
|
||||
|
||||
public function testNameFieldsSucceeds(): void
|
||||
{
|
||||
$named = Parameters::nameFields([Field::EQ('it', 17), Field::EQ('also', 22, '@also'), Field::EQ('other', 24)]);
|
||||
$this->assertCount(3, $named, 'There should be 3 parameters in the array');
|
||||
$this->assertEquals('@field0', $named[0]->paramName, 'Parameter 1 not named correctly');
|
||||
$this->assertEquals('@also', $named[1]->paramName, 'Parameter 2 not named correctly');
|
||||
$this->assertEquals('@field2', $named[2]->paramName, 'Parameter 3 not named correctly');
|
||||
}
|
||||
|
||||
public function testAddFieldsSucceeds(): void
|
||||
{
|
||||
$this->assertEquals(['@a' => 1, '@b' => 'two', '@z' => 18],
|
||||
Parameters::addFields([Field::EQ('b', 'two', '@b'), Field::EQ('z', 18, '@z')], ['@a' => 1]),
|
||||
'Field parameters not added correctly');
|
||||
}
|
||||
|
||||
#[TestDox('Field names succeeds for PostgreSQL')]
|
||||
public function testFieldNamesSucceedsForPostgreSQL(): void
|
||||
{
|
||||
try {
|
||||
Configuration::$mode = Mode::PgSQL;
|
||||
$this->assertEquals(['@names' => "ARRAY['one','two','seven']"],
|
||||
Parameters::fieldNames('@names', ['one', 'two', 'seven']), 'Field name parameters not correct');
|
||||
} finally {
|
||||
Configuration::$mode = null;
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Field names succeeds for SQLite')]
|
||||
public function testFieldNamesSucceedsForSQLite(): void
|
||||
{
|
||||
try {
|
||||
Configuration::$mode = Mode::SQLite;
|
||||
$this->assertEquals(['@it0' => 'test', '@it1' => 'unit', '@it2' => 'wow'],
|
||||
Parameters::fieldNames('@it', ['test', 'unit', 'wow']), 'Field name parameters not correct');
|
||||
} finally {
|
||||
Configuration::$mode = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function testFieldNamesFailsWhenModeNotSet(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
Configuration::$mode = null;
|
||||
Parameters::fieldNames('', []);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user