54 lines
1.5 KiB
PHP
54 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use ReflectionClass;
|
|
use Services\Mongo;
|
|
use Services\Mongo\MongoDriver;
|
|
use System\Classes\Config;
|
|
|
|
class MongoDriverTest extends TestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
if (!extension_loaded('mongodb')) {
|
|
$this->markTestSkipped('ext-mongodb не установлен (см. docker/php-apache/8.2.8/Dockerfile)');
|
|
}
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
$ref = new ReflectionClass(Mongo::class);
|
|
$prop = $ref->getProperty('_instances');
|
|
$prop->setAccessible(true);
|
|
$prop->setValue(null, []);
|
|
}
|
|
|
|
public function testInstanceReturnsMongoDriver(): void
|
|
{
|
|
$this->assertInstanceOf(MongoDriver::class, Mongo::instance());
|
|
}
|
|
|
|
public function testInstanceIsCachedPerConnectionName(): void
|
|
{
|
|
$this->assertSame(Mongo::instance('default'), Mongo::instance('default'));
|
|
}
|
|
|
|
public function testCollectionReturnsMongoCollection(): void
|
|
{
|
|
$config = Config::get('mongo', 'default');
|
|
$driver = new MongoDriver($config);
|
|
|
|
$this->assertInstanceOf(\MongoDB\Collection::class, $driver->collection('bicycle_test_collection'));
|
|
}
|
|
|
|
public function testDatabaseReturnsMongoDatabase(): void
|
|
{
|
|
$config = Config::get('mongo', 'default');
|
|
$driver = new MongoDriver($config);
|
|
|
|
$this->assertInstanceOf(\MongoDB\Database::class, $driver->database());
|
|
}
|
|
}
|