More fixes and tests

This commit is contained in:
Daniil Gentili 2024-03-29 19:39:04 +01:00
parent e2981bbefd
commit 16e4448dd8
2 changed files with 22 additions and 1 deletions

View File

@ -134,7 +134,7 @@ final class ObjectContainer
}
$value->initDb($this, $key, $this->config);
$this->cache[$key] = new ObjectReference($value, \time() + $this->cacheTtl);
yield $value;
yield $key => $value;
}
}

View File

@ -17,6 +17,7 @@
namespace danog\AsyncOrm\Test;
use Amp\ByteStream\ReadableStream;
use Amp\DeferredFuture;
use Amp\Mysql\MysqlConfig;
use Amp\Postgres\PostgresConfig;
use Amp\Process\Process;
@ -41,6 +42,7 @@ use danog\AsyncOrm\ValueType;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use ReflectionProperty;
use Revolt\EventLoop;
use WeakReference;
use function Amp\async;
@ -231,6 +233,25 @@ final class OrmTest extends TestCase
}
$this->assertEquals(0, $cnt);
$this->assertCount(0, $orm);
// Test that db is flushed on __destruct
$orm = $field->build();
$orm[$key] = $value;
unset($orm);
$f = new DeferredFuture;
EventLoop::queue($f->complete(...));
$f->getFuture()->await();
$orm = $field->build();
$this->assertCount(1, $orm);
$cnt = 0;
foreach ($orm as $kk => $vv) {
$cnt++;
$this->assertSameNotObject($key, $kk);
$this->assertSameNotObject($value, $vv);
}
$this->assertEquals(1, $cnt);
$orm->clear();
}
#[DataProvider('provideSettings')]