mirror of
https://github.com/danog/AsyncOrm.git
synced 2024-12-02 09:38:31 +01:00
Fixes
This commit is contained in:
parent
819b23495e
commit
9784a2e1cf
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@
|
|||||||
/vendor/
|
/vendor/
|
||||||
*.cache
|
*.cache
|
||||||
composer.lock
|
composer.lock
|
||||||
|
/coverage/
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
xmlns="https://getpsalm.org/schema/config"
|
xmlns="https://getpsalm.org/schema/config"
|
||||||
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
|
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
|
||||||
findUnusedBaselineEntry="true"
|
findUnusedBaselineEntry="true"
|
||||||
findUnusedCode="false"
|
findUnusedCode="true"
|
||||||
>
|
>
|
||||||
<projectFiles>
|
<projectFiles>
|
||||||
<directory name="src" />
|
<directory name="src" />
|
||||||
|
@ -25,7 +25,6 @@ use AssertionError;
|
|||||||
use danog\AsyncOrm\Driver\Mysql;
|
use danog\AsyncOrm\Driver\Mysql;
|
||||||
use danog\AsyncOrm\Driver\SqlArray;
|
use danog\AsyncOrm\Driver\SqlArray;
|
||||||
use danog\AsyncOrm\FieldConfig;
|
use danog\AsyncOrm\FieldConfig;
|
||||||
use danog\AsyncOrm\Internal\Serializer\IntString;
|
|
||||||
use danog\AsyncOrm\Internal\Serializer\Passthrough;
|
use danog\AsyncOrm\Internal\Serializer\Passthrough;
|
||||||
use danog\AsyncOrm\KeyType;
|
use danog\AsyncOrm\KeyType;
|
||||||
use danog\AsyncOrm\Serializer;
|
use danog\AsyncOrm\Serializer;
|
||||||
@ -60,8 +59,7 @@ final class MysqlArray extends SqlArray
|
|||||||
{
|
{
|
||||||
/** @var Serializer<TValue> */
|
/** @var Serializer<TValue> */
|
||||||
$serializer = match ($config->valueType) {
|
$serializer = match ($config->valueType) {
|
||||||
ValueType::INT => new IntString,
|
ValueType::INT, ValueType::STRING => new Passthrough,
|
||||||
ValueType::STRING => new Passthrough,
|
|
||||||
default => $serializer
|
default => $serializer
|
||||||
};
|
};
|
||||||
$settings = $config->settings;
|
$settings = $config->settings;
|
||||||
@ -202,7 +200,11 @@ final class MysqlArray extends SqlArray
|
|||||||
protected function execute(string $sql, array $params = []): SqlResult
|
protected function execute(string $sql, array $params = []): SqlResult
|
||||||
{
|
{
|
||||||
foreach ($params as $key => $value) {
|
foreach ($params as $key => $value) {
|
||||||
|
if (\is_int($value)) {
|
||||||
|
$value = (string) $value;
|
||||||
|
} else {
|
||||||
$value = $this->pdo->quote($value);
|
$value = $this->pdo->quote($value);
|
||||||
|
}
|
||||||
$sql = \str_replace(":$key", $value, $sql);
|
$sql = \str_replace(":$key", $value, $sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ use Amp\Sync\LocalKeyedMutex;
|
|||||||
use danog\AsyncOrm\Driver\SqlArray;
|
use danog\AsyncOrm\Driver\SqlArray;
|
||||||
use danog\AsyncOrm\FieldConfig;
|
use danog\AsyncOrm\FieldConfig;
|
||||||
use danog\AsyncOrm\Internal\Serializer\ByteaSerializer;
|
use danog\AsyncOrm\Internal\Serializer\ByteaSerializer;
|
||||||
|
use danog\AsyncOrm\Internal\Serializer\Passthrough;
|
||||||
use danog\AsyncOrm\KeyType;
|
use danog\AsyncOrm\KeyType;
|
||||||
use danog\AsyncOrm\Serializer;
|
use danog\AsyncOrm\Serializer;
|
||||||
use danog\AsyncOrm\Settings\Postgres;
|
use danog\AsyncOrm\Settings\Postgres;
|
||||||
@ -92,7 +93,7 @@ class PostgresArray extends SqlArray
|
|||||||
default => "BYTEA",
|
default => "BYTEA",
|
||||||
};
|
};
|
||||||
$serializer = match ($config->valueType) {
|
$serializer = match ($config->valueType) {
|
||||||
ValueType::INT, ValueType::STRING => $serializer,
|
ValueType::INT, ValueType::STRING => new Passthrough,
|
||||||
default => new ByteaSerializer($serializer)
|
default => new ByteaSerializer($serializer)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,15 +23,28 @@ use Amp\Process\Process;
|
|||||||
use Amp\Redis\RedisConfig;
|
use Amp\Redis\RedisConfig;
|
||||||
use AssertionError;
|
use AssertionError;
|
||||||
use danog\AsyncOrm\DbArray;
|
use danog\AsyncOrm\DbArray;
|
||||||
|
use danog\AsyncOrm\Driver\DriverArray;
|
||||||
|
use danog\AsyncOrm\Driver\MemoryArray;
|
||||||
|
use danog\AsyncOrm\Driver\SqlArray;
|
||||||
use danog\AsyncOrm\FieldConfig;
|
use danog\AsyncOrm\FieldConfig;
|
||||||
|
use danog\AsyncOrm\Internal\Containers\CacheContainer;
|
||||||
|
use danog\AsyncOrm\Internal\Driver\CachedArray;
|
||||||
|
use danog\AsyncOrm\Internal\Driver\MysqlArray;
|
||||||
|
use danog\AsyncOrm\Internal\Driver\PostgresArray;
|
||||||
|
use danog\AsyncOrm\Internal\Driver\RedisArray;
|
||||||
|
use danog\AsyncOrm\Internal\Serializer\IntString;
|
||||||
|
use danog\AsyncOrm\Internal\Serializer\Passthrough;
|
||||||
use danog\AsyncOrm\KeyType;
|
use danog\AsyncOrm\KeyType;
|
||||||
|
use danog\AsyncOrm\Serializer;
|
||||||
use danog\AsyncOrm\Serializer\Igbinary;
|
use danog\AsyncOrm\Serializer\Igbinary;
|
||||||
use danog\AsyncOrm\Serializer\Json;
|
use danog\AsyncOrm\Serializer\Json;
|
||||||
use danog\AsyncOrm\Serializer\Native;
|
use danog\AsyncOrm\Serializer\Native;
|
||||||
use danog\AsyncOrm\Settings;
|
use danog\AsyncOrm\Settings;
|
||||||
|
use danog\AsyncOrm\Settings\Memory;
|
||||||
use danog\AsyncOrm\Settings\Mysql;
|
use danog\AsyncOrm\Settings\Mysql;
|
||||||
use danog\AsyncOrm\Settings\Postgres;
|
use danog\AsyncOrm\Settings\Postgres;
|
||||||
use danog\AsyncOrm\Settings\Redis;
|
use danog\AsyncOrm\Settings\Redis;
|
||||||
|
use danog\AsyncOrm\Settings\SqlSettings;
|
||||||
use danog\AsyncOrm\ValueType;
|
use danog\AsyncOrm\ValueType;
|
||||||
use PHPUnit\Framework\Attributes\CoversClass;
|
use PHPUnit\Framework\Attributes\CoversClass;
|
||||||
use PHPUnit\Framework\Attributes\DataProvider;
|
use PHPUnit\Framework\Attributes\DataProvider;
|
||||||
@ -46,7 +59,27 @@ use function Amp\ByteStream\splitLines;
|
|||||||
use function Amp\Future\await;
|
use function Amp\Future\await;
|
||||||
use function Amp\Future\awaitAny;
|
use function Amp\Future\awaitAny;
|
||||||
|
|
||||||
|
#[CoversClass(FieldConfig::class)]
|
||||||
|
#[CoversClass(KeyType::class)]
|
||||||
|
#[CoversClass(ValueType::class)]
|
||||||
|
#[CoversClass(Serializer::class)]
|
||||||
|
#[CoversClass(Passthrough::class)]
|
||||||
|
#[CoversClass(IntString::class)]
|
||||||
|
#[CoversClass(CacheContainer::class)]
|
||||||
|
#[CoversClass(CachedArray::class)]
|
||||||
#[CoversClass(DbArray::class)]
|
#[CoversClass(DbArray::class)]
|
||||||
|
#[CoversClass(DriverArray::class)]
|
||||||
|
#[CoversClass(SqlArray::class)]
|
||||||
|
#[CoversClass(PostgresArray::class)]
|
||||||
|
#[CoversClass(RedisArray::class)]
|
||||||
|
#[CoversClass(MemoryArray::class)]
|
||||||
|
#[CoversClass(MysqlArray::class)]
|
||||||
|
#[CoversClass(Settings::class)]
|
||||||
|
#[CoversClass(Memory::class)]
|
||||||
|
#[CoversClass(Postgres::class)]
|
||||||
|
#[CoversClass(Mysql::class)]
|
||||||
|
#[CoversClass(Redis::class)]
|
||||||
|
#[CoversClass(SqlSettings::class)]
|
||||||
final class OrmTest extends TestCase
|
final class OrmTest extends TestCase
|
||||||
{
|
{
|
||||||
/** @var array<string, Process> */
|
/** @var array<string, Process> */
|
||||||
@ -121,28 +154,68 @@ final class OrmTest extends TestCase
|
|||||||
$orm = $field->build();
|
$orm = $field->build();
|
||||||
$orm[$key] = 123;
|
$orm[$key] = 123;
|
||||||
|
|
||||||
$this->assertEquals(123, $orm[$key]);
|
$this->assertSame(123, $orm[$key]);
|
||||||
$this->assertTrue(isset($orm[$key]));
|
$this->assertTrue(isset($orm[$key]));
|
||||||
unset($orm[$key]);
|
unset($orm[$key]);
|
||||||
|
|
||||||
$this->assertNull($orm[$key]);
|
$this->assertNull($orm[$key]);
|
||||||
$this->assertFalse(isset($orm[$key]));
|
$this->assertFalse(isset($orm[$key]));
|
||||||
|
|
||||||
|
if ($orm instanceof CachedArray) {
|
||||||
|
$orm->flushCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertCount(0, $orm);
|
||||||
|
$this->assertNull($orm[$key]);
|
||||||
|
$this->assertFalse(isset($orm[$key]));
|
||||||
|
|
||||||
|
if ($orm instanceof MemoryArray) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$orm = $field->build();
|
$orm = $field->build();
|
||||||
$orm[$key] = 124;
|
$orm[$key] = 124;
|
||||||
|
|
||||||
$this->assertEquals(124, $orm[$key]);
|
$this->assertCount(1, $orm);
|
||||||
|
$this->assertSame(124, $orm[$key]);
|
||||||
$this->assertTrue(isset($orm[$key]));
|
$this->assertTrue(isset($orm[$key]));
|
||||||
|
|
||||||
|
if ($orm instanceof CachedArray) {
|
||||||
|
$orm->flushCache();
|
||||||
|
}
|
||||||
unset($orm);
|
unset($orm);
|
||||||
while (\gc_collect_cycles());
|
while (\gc_collect_cycles());
|
||||||
|
|
||||||
$orm = $field->build();
|
$orm = $field->build();
|
||||||
$this->assertEquals(124, $orm[$key]);
|
$this->assertSame(124, $orm[$key]);
|
||||||
$this->assertTrue(isset($orm[$key]));
|
$this->assertTrue(isset($orm[$key]));
|
||||||
|
|
||||||
unset($orm[$key]);
|
unset($orm[$key]);
|
||||||
$this->assertNull($orm[$key]);
|
$this->assertNull($orm[$key]);
|
||||||
$this->assertFalse(isset($orm[$key]));
|
$this->assertFalse(isset($orm[$key]));
|
||||||
|
|
||||||
|
if ($orm instanceof CachedArray) {
|
||||||
|
$orm->flushCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertCount(0, $orm);
|
||||||
|
$orm[$key] = 123;
|
||||||
|
$this->assertCount(1, $orm);
|
||||||
|
$cnt = 0;
|
||||||
|
foreach ($orm as $kk => $vv) {
|
||||||
|
$cnt++;
|
||||||
|
$this->assertSame($key, $kk);
|
||||||
|
$this->assertSame(123, $vv);
|
||||||
|
}
|
||||||
|
$this->assertEquals(1, $cnt);
|
||||||
|
|
||||||
|
$orm->clear();
|
||||||
|
$cnt = 0;
|
||||||
|
foreach ($orm as $kk => $vv) {
|
||||||
|
$cnt++;
|
||||||
|
}
|
||||||
|
$this->assertEquals(0, $cnt);
|
||||||
|
$this->assertCount(0, $orm);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[DataProvider('provideSettings')]
|
#[DataProvider('provideSettings')]
|
||||||
@ -157,9 +230,13 @@ final class OrmTest extends TestCase
|
|||||||
$orm = $field->build();
|
$orm = $field->build();
|
||||||
$orm[321] = 123;
|
$orm[321] = 123;
|
||||||
|
|
||||||
$this->assertEquals(123, $orm[321]);
|
$this->assertSame(123, $orm[321]);
|
||||||
$this->assertTrue(isset($orm[321]));
|
$this->assertTrue(isset($orm[321]));
|
||||||
|
|
||||||
|
if ($orm instanceof MemoryArray) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$field = new FieldConfig(
|
$field = new FieldConfig(
|
||||||
__METHOD__,
|
__METHOD__,
|
||||||
$settings,
|
$settings,
|
||||||
@ -167,7 +244,7 @@ final class OrmTest extends TestCase
|
|||||||
ValueType::INT
|
ValueType::INT
|
||||||
);
|
);
|
||||||
$orm = $field->build();
|
$orm = $field->build();
|
||||||
$this->assertEquals(123, $orm[321]);
|
$this->assertSame(123, $orm[321]);
|
||||||
$this->assertTrue(isset($orm[321]));
|
$this->assertTrue(isset($orm[321]));
|
||||||
|
|
||||||
$field = new FieldConfig(
|
$field = new FieldConfig(
|
||||||
@ -177,7 +254,7 @@ final class OrmTest extends TestCase
|
|||||||
ValueType::INT
|
ValueType::INT
|
||||||
);
|
);
|
||||||
$orm = $field->build();
|
$orm = $field->build();
|
||||||
$this->assertEquals(123, $orm[321]);
|
$this->assertSame(123, $orm[321]);
|
||||||
$this->assertTrue(isset($orm[321]));
|
$this->assertTrue(isset($orm[321]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,24 +286,27 @@ final class OrmTest extends TestCase
|
|||||||
|
|
||||||
public static function provideSettings(): \Generator
|
public static function provideSettings(): \Generator
|
||||||
{
|
{
|
||||||
|
yield [new Memory()];
|
||||||
foreach ([new Native, new Igbinary, new Json] as $serializer) {
|
foreach ([new Native, new Igbinary, new Json] as $serializer) {
|
||||||
|
foreach ([0, 100] as $ttl) {
|
||||||
yield from [
|
yield from [
|
||||||
[new Redis(
|
[new Redis(
|
||||||
RedisConfig::fromUri('redis://127.0.0.1'),
|
RedisConfig::fromUri('redis://127.0.0.1'),
|
||||||
$serializer,
|
$serializer,
|
||||||
0,
|
$ttl,
|
||||||
)],
|
)],
|
||||||
[new Postgres(
|
[new Postgres(
|
||||||
PostgresConfig::fromString('host=127.0.0.1:5432 user=postgres db=test'),
|
PostgresConfig::fromString('host=127.0.0.1:5432 user=postgres db=test'),
|
||||||
$serializer,
|
$serializer,
|
||||||
0,
|
$ttl,
|
||||||
)],
|
)],
|
||||||
[new Mysql(
|
[new Mysql(
|
||||||
MysqlConfig::fromString('host=127.0.0.1:3306 user=root db=test'),
|
MysqlConfig::fromString('host=127.0.0.1:3306 user=root db=test'),
|
||||||
$serializer,
|
$serializer,
|
||||||
0,
|
$ttl,
|
||||||
)],
|
)],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user