mirror of
https://github.com/danog/AsyncOrm.git
synced 2024-11-30 04:39:45 +01:00
Cleanup
This commit is contained in:
parent
a2977f951c
commit
dc814038c9
@ -128,7 +128,7 @@ final class ObjectContainer
|
|||||||
$ref = $obj->reference->get();
|
$ref = $obj->reference->get();
|
||||||
if ($ref !== null) {
|
if ($ref !== null) {
|
||||||
$obj->ttl = \time() + $this->cacheTtl;
|
$obj->ttl = \time() + $this->cacheTtl;
|
||||||
yield $obj;
|
yield $key => $ref;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -140,7 +140,6 @@ final class ObjectContainer
|
|||||||
|
|
||||||
public function count(): int
|
public function count(): int
|
||||||
{
|
{
|
||||||
$this->flushCache();
|
|
||||||
return $this->inner->count();
|
return $this->inner->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ use Amp\Postgres\PostgresConfig;
|
|||||||
use Amp\Process\Process;
|
use Amp\Process\Process;
|
||||||
use Amp\Redis\RedisConfig;
|
use Amp\Redis\RedisConfig;
|
||||||
use AssertionError;
|
use AssertionError;
|
||||||
|
use danog\AsyncOrm\DbObject;
|
||||||
use danog\AsyncOrm\Driver\MemoryArray;
|
use danog\AsyncOrm\Driver\MemoryArray;
|
||||||
use danog\AsyncOrm\FieldConfig;
|
use danog\AsyncOrm\FieldConfig;
|
||||||
use danog\AsyncOrm\Internal\Driver\CachedArray;
|
use danog\AsyncOrm\Internal\Driver\CachedArray;
|
||||||
@ -112,6 +113,14 @@ final class OrmTest extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function assertSameNotObject(mixed $a, mixed $b): void
|
||||||
|
{
|
||||||
|
if ($b instanceof DbObject) {
|
||||||
|
$this->assertSame($a::class, $b::class);
|
||||||
|
} else {
|
||||||
|
$this->assertSame($a, $b);
|
||||||
|
}
|
||||||
|
}
|
||||||
private static int $cnt = 0;
|
private static int $cnt = 0;
|
||||||
|
|
||||||
#[DataProvider('provideSettingsKeysValues')]
|
#[DataProvider('provideSettingsKeysValues')]
|
||||||
@ -127,9 +136,11 @@ final class OrmTest extends TestCase
|
|||||||
$orm = $field->build();
|
$orm = $field->build();
|
||||||
$orm[$key] = $value;
|
$orm[$key] = $value;
|
||||||
|
|
||||||
$this->assertSame($value, $orm[$key]);
|
$this->assertSameNotObject($value, $orm[$key]);
|
||||||
$this->assertTrue(isset($orm[$key]));
|
$this->assertTrue(isset($orm[$key]));
|
||||||
$this->assertSame([$key => $value], $orm->getArrayCopy());
|
if (!$value instanceof DbObject) {
|
||||||
|
$this->assertSameNotObject([$key => $value], $orm->getArrayCopy());
|
||||||
|
}
|
||||||
unset($orm[$key]);
|
unset($orm[$key]);
|
||||||
|
|
||||||
$this->assertNull($orm[$key]);
|
$this->assertNull($orm[$key]);
|
||||||
@ -142,7 +153,9 @@ final class OrmTest extends TestCase
|
|||||||
$this->assertCount(0, $orm);
|
$this->assertCount(0, $orm);
|
||||||
$this->assertNull($orm[$key]);
|
$this->assertNull($orm[$key]);
|
||||||
$this->assertFalse(isset($orm[$key]));
|
$this->assertFalse(isset($orm[$key]));
|
||||||
$this->assertSame([], $orm->getArrayCopy());
|
if (!$value instanceof DbObject) {
|
||||||
|
$this->assertSameNotObject([], $orm->getArrayCopy());
|
||||||
|
}
|
||||||
|
|
||||||
if ($orm instanceof MemoryArray) {
|
if ($orm instanceof MemoryArray) {
|
||||||
$orm->clear();
|
$orm->clear();
|
||||||
@ -159,8 +172,7 @@ final class OrmTest extends TestCase
|
|||||||
$orm[$key] = $value;
|
$orm[$key] = $value;
|
||||||
|
|
||||||
$this->assertCount(1, $orm);
|
$this->assertCount(1, $orm);
|
||||||
$this->assertCount(1, $orm);
|
$this->assertSameNotObject($value, $orm[$key]);
|
||||||
$this->assertSame($value, $orm[$key]);
|
|
||||||
$this->assertTrue(isset($orm[$key]));
|
$this->assertTrue(isset($orm[$key]));
|
||||||
|
|
||||||
if ($orm instanceof CachedArray) {
|
if ($orm instanceof CachedArray) {
|
||||||
@ -170,7 +182,7 @@ final class OrmTest extends TestCase
|
|||||||
while (\gc_collect_cycles());
|
while (\gc_collect_cycles());
|
||||||
|
|
||||||
$orm = $field->build();
|
$orm = $field->build();
|
||||||
$this->assertSame($value, $orm[$key]);
|
$this->assertSameNotObject($value, $orm[$key]);
|
||||||
$this->assertTrue(isset($orm[$key]));
|
$this->assertTrue(isset($orm[$key]));
|
||||||
|
|
||||||
unset($orm[$key]);
|
unset($orm[$key]);
|
||||||
@ -187,8 +199,8 @@ final class OrmTest extends TestCase
|
|||||||
$cnt = 0;
|
$cnt = 0;
|
||||||
foreach ($orm as $kk => $vv) {
|
foreach ($orm as $kk => $vv) {
|
||||||
$cnt++;
|
$cnt++;
|
||||||
$this->assertSame($key, $kk);
|
$this->assertSameNotObject($key, $kk);
|
||||||
$this->assertSame($value, $vv);
|
$this->assertSameNotObject($value, $vv);
|
||||||
}
|
}
|
||||||
$this->assertEquals(1, $cnt);
|
$this->assertEquals(1, $cnt);
|
||||||
|
|
||||||
@ -350,11 +362,20 @@ final class OrmTest extends TestCase
|
|||||||
[ValueType::BOOL, true],
|
[ValueType::BOOL, true],
|
||||||
[ValueType::BOOL, false],
|
[ValueType::BOOL, false],
|
||||||
|
|
||||||
|
[ValueType::OBJECT, new TestObject],
|
||||||
|
|
||||||
[ValueType::SCALAR, 'test'],
|
[ValueType::SCALAR, 'test'],
|
||||||
[ValueType::SCALAR, 123],
|
[ValueType::SCALAR, 123],
|
||||||
[ValueType::SCALAR, ['test' => 123]],
|
[ValueType::SCALAR, ['test' => 123]],
|
||||||
[ValueType::SCALAR, 123.321],
|
[ValueType::SCALAR, 123.321],
|
||||||
|
[ValueType::SCALAR, new TestObject],
|
||||||
] as [$valueType, $value]) {
|
] as [$valueType, $value]) {
|
||||||
|
if ($valueType === ValueType::OBJECT && (
|
||||||
|
$settings instanceof Memory
|
||||||
|
|| $settings->serializer instanceof Json
|
||||||
|
)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
yield [
|
yield [
|
||||||
$settings,
|
$settings,
|
||||||
KeyType::INT,
|
KeyType::INT,
|
||||||
|
Loading…
Reference in New Issue
Block a user