File tree Expand file tree Collapse file tree 3 files changed +42
-2
lines changed Expand file tree Collapse file tree 3 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,18 @@ public function listDatabases(): array
4141 return (array ) $ this ->connector ->request ('get ' , '/_api/database ' );
4242 }
4343
44+ /**
45+ * @param $database
46+ * @return bool
47+ * @throws Exceptions\ArangoDbException
48+ * @throws GuzzleException
49+ */
50+ public function exists ($ database ): bool
51+ {
52+ $ databaseList = $ this ->listDatabases ();
53+ return in_array ($ database , $ databaseList );
54+ }
55+
4456 /**
4557 * @return array<mixed>
4658 *
Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ public function testListMyDatabases()
5252
5353 public function testCreateAndDeleteDatabase ()
5454 {
55- $ database = 'test__arangodb_php_client_database ' ;
55+ $ database = 'arangodb_php_client_database__test ' ;
5656 $ existingDatabases = $ this ->client ->listDatabases ();
5757
5858 if (! in_array ($ database , $ existingDatabases )) {
@@ -64,6 +64,14 @@ public function testCreateAndDeleteDatabase()
6464 $ this ->assertTrue ($ result );
6565 $ existingDatabases = $ this ->client ->listDatabases ();
6666 $ this ->assertNotContains ($ database , $ existingDatabases );
67+ }
68+
69+ public function testDatabaseExists ()
70+ {
71+ $ check = $ this ->databaseClient ->exists ('someNoneExistingDatabase ' );
72+ $ this ->assertFalse ($ check );
6773
74+ $ check = $ this ->databaseClient ->exists ($ this ->testDatabaseName );
75+ $ this ->assertTrue ($ check );
6876 }
6977}
Original file line number Diff line number Diff line change 55namespace Tests ;
66
77use ArangoClient \Connector ;
8+ use ArangoClient \DatabaseClient ;
89use PHPUnit \Framework \TestCase as PhpUnitTestCase ;
910
1011abstract class TestCase extends PhpUnitTestCase
1112{
12- protected $ connector ;
13+ protected Connector $ connector ;
14+
15+ protected DatabaseClient $ databaseClient ;
16+
17+ protected string $ testDatabaseName = 'arangodb_php_client_database__test ' ;
1318
1419 protected function setUp (): void
1520 {
1621 $ this ->connector = new Connector ();
22+
23+ $ this ->databaseClient = new DatabaseClient ($ this ->connector );
24+
25+ $ this ->createTestDatabase ();
26+ }
27+
28+ /**
29+ * @throws \ArangoClient\Exceptions\ArangoDbException
30+ * @throws \GuzzleHttp\Exception\GuzzleException
31+ */
32+ protected function createTestDatabase ()
33+ {
34+ if (! $ this ->databaseClient ->exists ($ this ->testDatabaseName )) {
35+ $ this ->databaseClient ->create ($ this ->testDatabaseName );
36+ }
1737 }
1838}
You can’t perform that action at this time.
0 commit comments