-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathMongoDBTest.php
More file actions
115 lines (96 loc) · 2.73 KB
/
MongoDBTest.php
File metadata and controls
115 lines (96 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
namespace Tests\E2E\Adapter;
use Exception;
use Redis;
use Utopia\Cache\Adapter\Redis as RedisAdapter;
use Utopia\Cache\Cache;
use Utopia\Database\Adapter\Mongo;
use Utopia\Database\Database;
use Utopia\Mongo\Client;
class MongoDBTest extends Base
{
public static ?Database $database = null;
protected static string $namespace;
/**
* Return name of adapter
*
* @return string
*/
public static function getAdapterName(): string
{
return "mongodb";
}
/**
* @return Database
* @throws Exception
*/
public function getDatabase(): Database
{
if (!is_null(self::$database)) {
return self::$database;
}
$redis = new Redis();
$redis->connect('redis', 6379);
$redis->flushAll();
$cache = new Cache(new RedisAdapter($redis));
$schema = 'utopiaTests'; // same as $this->testDatabase
$client = new Client(
$schema,
'mongo',
27017,
'root',
'password',
false
);
$database = new Database(new Mongo($client), $cache);
$database->getAdapter()->setSupportForAttributes(true);
$database
->setAuthorization(self::$authorization)
->setDatabase($schema)
->setNamespace(static::$namespace = 'myapp_' . uniqid());
if ($database->exists()) {
$database->delete();
}
$database->create();
return self::$database = $database;
}
/**
* @throws Exception
*/
public function testCreateExistsDelete(): void
{
// Mongo creates databases on the fly, so exists would always pass. So we override this test to remove the exists check.
$this->assertNotNull($this->getDatabase()->create());
$this->assertEquals(true, $this->getDatabase()->delete($this->testDatabase));
$this->assertEquals(true, $this->getDatabase()->create());
$this->assertEquals($this->getDatabase(), $this->getDatabase()->setDatabase($this->testDatabase));
}
public function testRenameAttribute(): void
{
$this->assertTrue(true);
}
public function testRenameAttributeExisting(): void
{
$this->assertTrue(true);
}
public function testUpdateAttributeStructure(): void
{
$this->assertTrue(true);
}
public function testKeywords(): void
{
$this->assertTrue(true);
}
protected function getPDO(): mixed
{
return null;
}
protected function deleteColumn(string $collection, string $column): bool
{
return true;
}
protected function deleteIndex(string $collection, string $index): bool
{
return true;
}
}