feat(test): add multi-engine integration matrix
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Libs\Neuron;
|
||||
use PDO;
|
||||
use Tests\TestCase;
|
||||
@@ -15,7 +16,8 @@ use Tests\TestCase;
|
||||
*/
|
||||
final class BootstrapTest extends TestCase
|
||||
{
|
||||
public function testFrameworkClassesAreAutoloaded(): void
|
||||
#[Test]
|
||||
public function frameworkClassesAreAutoloaded(): void
|
||||
{
|
||||
$this->assertTrue(
|
||||
class_exists(Neuron::class),
|
||||
@@ -27,7 +29,9 @@ final class BootstrapTest extends TestCase
|
||||
$this->assertNull($neuron->doesNotExist);
|
||||
}
|
||||
|
||||
public function testDatabaseConstantsPointToInMemorySqlite(): void
|
||||
#[Test]
|
||||
|
||||
public function databaseConstantsPointToInMemorySqlite(): void
|
||||
{
|
||||
$this->assertSame(
|
||||
'sqlite',
|
||||
@@ -37,7 +41,9 @@ final class BootstrapTest extends TestCase
|
||||
$this->assertSame(':memory:', DB_NAME, 'DB_NAME should be :memory: so tests never touch disks or servers');
|
||||
}
|
||||
|
||||
public function testTestDatabaseIsUsable(): void
|
||||
#[Test]
|
||||
|
||||
public function testDatabaseIsUsable(): void
|
||||
{
|
||||
$db = self::db();
|
||||
$this->assertInstanceOf(PDO::class, $db, 'Could not obtain the test PDO connection');
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Libs\Neuron;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -13,7 +14,8 @@ use Tests\TestCase;
|
||||
*/
|
||||
final class NeuronTest extends TestCase
|
||||
{
|
||||
public function testConstructFromAssociativeArray(): void
|
||||
#[Test]
|
||||
public function constructFromAssociativeArray(): void
|
||||
{
|
||||
$n = new Neuron(['username' => 'kj', 'level' => 3]);
|
||||
|
||||
@@ -21,7 +23,9 @@ final class NeuronTest extends TestCase
|
||||
$this->assertSame(3, $n->level);
|
||||
}
|
||||
|
||||
public function testConstructFromObjectCopiesPublicProperties(): void
|
||||
#[Test]
|
||||
|
||||
public function constructFromObjectCopiesPublicProperties(): void
|
||||
{
|
||||
$source = new \stdClass();
|
||||
$source->id = 7;
|
||||
@@ -33,14 +37,18 @@ final class NeuronTest extends TestCase
|
||||
$this->assertSame('kj@example.com', $n->email);
|
||||
}
|
||||
|
||||
public function testUndefinedPropertyIsNullWithoutNotice(): void
|
||||
#[Test]
|
||||
|
||||
public function undefinedPropertyIsNullWithoutNotice(): void
|
||||
{
|
||||
$n = new Neuron();
|
||||
|
||||
$this->assertNull($n->thisDoesNotExist);
|
||||
}
|
||||
|
||||
public function testDynamicPropertiesCanBeAssignedAndRead(): void
|
||||
#[Test]
|
||||
|
||||
public function dynamicPropertiesCanBeAssignedAndRead(): void
|
||||
{
|
||||
$n = new Neuron();
|
||||
$n->fresh = ['a', 'b'];
|
||||
@@ -48,7 +56,9 @@ final class NeuronTest extends TestCase
|
||||
$this->assertSame(['a', 'b'], $n->fresh);
|
||||
}
|
||||
|
||||
public function testNestedValuesArePreservedVerbatim(): void
|
||||
#[Test]
|
||||
|
||||
public function nestedValuesArePreservedVerbatim(): void
|
||||
{
|
||||
$payload = ['meta' => ['tags' => ['x', 'y'], 'n' => null]];
|
||||
$n = new Neuron($payload);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Libs\Neuron;
|
||||
use Libs\Validator;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
@@ -43,19 +44,24 @@ final class ValidatorTest extends TestCase
|
||||
}
|
||||
|
||||
#[DataProvider('scalarRuleProvider')]
|
||||
public function testScalarRules(string $rule, mixed $value, bool $expected): void
|
||||
#[Test]
|
||||
public function scalarRules(string $rule, mixed $value, bool $expected): void
|
||||
{
|
||||
$this->assertSame($expected, Validator::checkRule($value, $rule), "rule {$rule} with " . var_export($value, true));
|
||||
}
|
||||
|
||||
public function testExistsAndRequiredDisagreeOnEmptyString(): void
|
||||
#[Test]
|
||||
|
||||
public function existsAndRequiredDisagreeOnEmptyString(): void
|
||||
{
|
||||
$this->assertTrue(Validator::checkRule('', 'exists'));
|
||||
$this->assertFalse(Validator::checkRule('', 'required'));
|
||||
$this->assertFalse(Validator::checkRule(null, 'exists'));
|
||||
}
|
||||
|
||||
public function testSizeRulesMeasureStringNumberAndArray(): void
|
||||
#[Test]
|
||||
|
||||
public function sizeRulesMeasureStringNumberAndArray(): void
|
||||
{
|
||||
$this->assertTrue(Validator::checkRule('abc', 'min:3'));
|
||||
$this->assertFalse(Validator::checkRule('abc', 'min:4'));
|
||||
@@ -65,32 +71,42 @@ final class ValidatorTest extends TestCase
|
||||
$this->assertFalse(Validator::checkRule('hey', 'size:4'));
|
||||
}
|
||||
|
||||
public function testRegexKeepsColonsAndCommasInsidePattern(): void
|
||||
#[Test]
|
||||
|
||||
public function regexKeepsColonsAndCommasInsidePattern(): void
|
||||
{
|
||||
$this->assertTrue(Validator::checkRule('a,b', 'regex:/^a,b$/'));
|
||||
$this->assertFalse(Validator::checkRule('a;b', 'regex:/^a,b$/'));
|
||||
}
|
||||
|
||||
public function testEnumIsLooseComparison(): void
|
||||
#[Test]
|
||||
|
||||
public function enumIsLooseComparison(): void
|
||||
{
|
||||
$this->assertTrue(Validator::checkRule('1', 'enum:1,2,3'));
|
||||
$this->assertFalse(Validator::checkRule('9', 'enum:1,2,3'));
|
||||
}
|
||||
|
||||
public function testNotNegatesNextRule(): void
|
||||
#[Test]
|
||||
|
||||
public function notNegatesNextRule(): void
|
||||
{
|
||||
$this->assertTrue(Validator::checkRule('3.5', 'not:int'));
|
||||
$this->assertFalse(Validator::checkRule('42', 'not:int'));
|
||||
}
|
||||
|
||||
public function testParseRule(): void
|
||||
#[Test]
|
||||
|
||||
public function parseRule(): void
|
||||
{
|
||||
$this->assertSame(['required', ''], Validator::parseRule('required'));
|
||||
$this->assertSame(['enum', 'a,b'], Validator::parseRule('enum:a,b'));
|
||||
$this->assertSame(['regex', '/^a,b$/'], Validator::parseRule('regex:/^a,b$/'));
|
||||
}
|
||||
|
||||
public function testValidateListPassesFullyValidBatch(): void
|
||||
#[Test]
|
||||
|
||||
public function validateListPassesFullyValidBatch(): void
|
||||
{
|
||||
$data = new Neuron(['username' => 'kj', 'email' => 'kj@duckbrain.dev']);
|
||||
|
||||
@@ -101,7 +117,9 @@ final class ValidatorTest extends TestCase
|
||||
$this->assertSame('', Validator::$lastFailed);
|
||||
}
|
||||
|
||||
public function testValidateListStopsAtFirstFailure(): void
|
||||
#[Test]
|
||||
|
||||
public function validateListStopsAtFirstFailure(): void
|
||||
{
|
||||
$data = new Neuron(['email' => 'not-an-email', 'name' => null]);
|
||||
|
||||
@@ -112,7 +130,9 @@ final class ValidatorTest extends TestCase
|
||||
$this->assertSame('email.email', Validator::$lastFailed);
|
||||
}
|
||||
|
||||
public function testValidateListNullableSkipsRestWhenEmpty(): void
|
||||
#[Test]
|
||||
|
||||
public function validateListNullableSkipsRestWhenEmpty(): void
|
||||
{
|
||||
$rules = ['bio' => 'nullable|min:10'];
|
||||
|
||||
@@ -120,7 +140,9 @@ final class ValidatorTest extends TestCase
|
||||
$this->assertFalse(Validator::validateList($rules, new Neuron(['bio' => 'too-short'])));
|
||||
}
|
||||
|
||||
public function testValidateListConfirmedUsesSiblingField(): void
|
||||
#[Test]
|
||||
|
||||
public function validateListConfirmedUsesSiblingField(): void
|
||||
{
|
||||
$rules = ['password' => 'required|confirmed'];
|
||||
|
||||
@@ -132,7 +154,9 @@ final class ValidatorTest extends TestCase
|
||||
$this->assertSame('password.confirmed', Validator::$lastFailed);
|
||||
}
|
||||
|
||||
public function testMessageBuildsHumanTextFromLastFailed(): void
|
||||
#[Test]
|
||||
|
||||
public function messageBuildsHumanTextFromLastFailed(): void
|
||||
{
|
||||
$this->assertSame(
|
||||
'The email must be a valid email address.',
|
||||
@@ -152,7 +176,9 @@ final class ValidatorTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testMessageRespectsAttributesAndOverrides(): void
|
||||
#[Test]
|
||||
|
||||
public function messageRespectsAttributesAndOverrides(): void
|
||||
{
|
||||
$this->assertSame(
|
||||
'The user name field is required.',
|
||||
|
||||
Reference in New Issue
Block a user