Skip to content

Commit 52fc3c1

Browse files
Migrated tests from Phpunit to Pest
1 parent b654659 commit 52fc3c1

18 files changed

+101
-89
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
matrix:
1414
os: [ubuntu-latest]
1515
arangodb: ["3.10", 3.11, 3.12]
16-
php: [8.1, 8.2, 8.3]
16+
php: [8.2, 8.3]
1717
stability: [prefer-stable]
1818

1919
name: P${{ matrix.php }} - A${{ matrix.arangodb }} - ${{ matrix.stability }}

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@
4646
"scripts": {
4747
"analyse": "vendor/bin/phpstan analyse",
4848
"test": "vendor/bin/pest",
49-
"test:coverage": "vendor/bin/phpunit --coverage-clover clover.xml --whitelist src",
49+
"test:coverage": "vendor/bin/pest --coverage-clover clover.xml",
5050
"style": "vendor/bin/pint"
5151
},
5252
"config": {
53-
"sort-packages": true
53+
"sort-packages": true,
54+
"allow-plugins": {
55+
"pestphp/pest-plugin": true
56+
}
5457
}
5558
}

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
</include>
1717
</coverage>
1818
<php>
19-
<env name="ARANGODB_VERSION" value="3.8"/>
19+
<env name="ARANGODB_VERSION" value="3.12"/>
2020
</php>
2121
</phpunit>

tests/AdminManagerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use ArangoClient\Admin\AdminManager;
66

77
uses(Tests\TestCase::class);
8+
89
beforeEach(function () {
910
$this->adminManager = new AdminManager($this->arangoClient);
1011
});
@@ -28,5 +29,6 @@
2829

2930
test('get running transactions', function () {
3031
$transactions = $this->adminManager->getRunningTransactions();
32+
3133
expect($transactions)->toBeEmpty();
3234
});

tests/ArangoClientTest.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,3 @@
234234

235235
$this->schemaManager->deleteCollection($collection);
236236
});
237-
238-
// Helpers
239-
function checkHttp2Support()
240-
{
241-
// First assert that CURL supports http2!
242-
if (!curl_version()['features'] || CURL_VERSION_HTTP2 === 0) {
243-
test()->markTestSkipped('The installed version of CURL does not support the HTTP2 protocol.');
244-
}
245-
// HTTP/2 is only supported by ArangoDB 3.7 and up.
246-
test()->skipTestOnArangoVersions('3.7');
247-
}

tests/ExceptionsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
uses(Tests\TestCase::class);
4-
53
declare(strict_types=1);
64

5+
uses(Tests\TestCase::class);
6+
77
test('test409 conflict exception', function () {
88
$database = 'test_arangodb_php_existing_database';
99
if (!$this->schemaManager->hasDatabase($database)) {

tests/MonitorManagerTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,5 @@
7272
arangodb_aql_local_query_memory_limit_reached_total{role="SINGLE"} 0 2211753600';
7373

7474
$result = $prometheus->parseText($rawMetrics);
75-
expect($result)->toBeObject();
7675
expect($result->arangodb_aql_local_query_memory_limit_reached_total->timestamp)->toEqual(2211753600);
7776
});

tests/Pest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,14 @@
3939
*/
4040

4141
/** @link https://pestphp.com/docs/custom-helpers */
42+
43+
// Helpers
44+
function checkHttp2Support()
45+
{
46+
// First assert that CURL supports http2!
47+
if (!curl_version()['features'] || CURL_VERSION_HTTP2 === 0) {
48+
test()->markTestSkipped('The installed version of CURL does not support the HTTP2 protocol.');
49+
}
50+
// HTTP/2 is only supported by ArangoDB 3.7 and up.
51+
test()->skipTestOnArangoVersions('3.7');
52+
}

tests/SchemaManagerAnalyzersTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
uses(Tests\TestCase::class);
46

5-
declare(strict_types=1);
67
beforeEach(function () {
7-
\Tests\TestCase::setUp();
8-
98
if (!$this->schemaManager->hasAnalyzer($this->analyzer['name'])) {
109
$this->schemaManager->createAnalyzer($this->analyzer);
1110
}
1211
});
1312

1413
afterEach(function () {
15-
\Tests\TestCase::tearDown();
16-
1714
if ($this->schemaManager->hasAnalyzer($this->analyzer['name'])) {
1815
$this->schemaManager->deleteAnalyzer($this->analyzer['name']);
1916
}
2017
});
2118

22-
2319
test('get analyzers', function () {
2420
$analyzers = $this->schemaManager->getAnalyzers();
2521

@@ -79,11 +75,11 @@
7975
'name' => 'coolnewanalyzer',
8076
'type' => 'identity',
8177
];
82-
$created = $this->schemaManager->createAnalyzer($analyzer);
78+
$this->schemaManager->createAnalyzer($analyzer);
8379

8480
$fullName = 'arangodb_php_client__test::' . $analyzer['name'];
8581

86-
$deleted = $this->schemaManager->deleteAnalyzer($fullName);
82+
$this->schemaManager->deleteAnalyzer($fullName);
8783

8884
$hasAnalyzer = $this->schemaManager->hasAnalyzer($fullName);
8985
expect($hasAnalyzer)->toBeFalse();

tests/SchemaManagerCollectionsTest.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
<?php
22

3-
uses(Tests\TestCase::class);
4-
53
declare(strict_types=1);
64

7-
test('get collections before version38', function () {
8-
$this->skipTestOnArangoVersions('3.8', '>=');
9-
$result = $this->schemaManager->getCollections();
10-
11-
expect(10)->toBeLessThanOrEqual(count($result));
12-
expect($result[0])->toBeObject();
13-
});
5+
uses(Tests\TestCase::class);
146

157
test('get collections', function () {
16-
$this->skipTestOnArangoVersions('3.8', '<');
178
$result = $this->schemaManager->getCollections();
189

1910
expect(8)->toBeLessThanOrEqual(count($result));
@@ -32,8 +23,7 @@
3223
$result = $this->schemaManager->getCollection($collections[0]->name);
3324

3425
expect($result)->toBeObject();
35-
$this->assertObjectHasProperty('name', $result);
36-
$this->assertObjectHasProperty('isSystem', $result);
26+
expect((array) $result)->toHaveKeys(['globallyUniqueId', 'isSystem', 'status', 'type', 'name', 'id']);
3727
});
3828

3929
test('has collection', function () {
@@ -131,7 +121,9 @@
131121
if (!$this->schemaManager->hasCollection($collection)) {
132122
$this->schemaManager->createCollection($collection);
133123
}
124+
134125
expect($this->schemaManager->getCollectionWithDocumentCount($collection)->count)->toBe(0);
126+
135127
$query = 'FOR i IN 1..10
136128
INSERT {
137129
_key: CONCAT("test", i),
@@ -146,7 +138,11 @@
146138
$this->schemaManager->truncateCollection($collection);
147139

148140
expect($this->schemaManager->getCollectionWithDocumentCount($collection)->count)->toBe(0);
149-
$this->schemaManager->deleteCollection($collection);
141+
142+
if ($this->schemaManager->hasCollection($collection)) {
143+
$this->schemaManager->deleteCollection($collection);
144+
}
145+
150146
});
151147

152148
test('create and delete collection', function () {

0 commit comments

Comments
 (0)