Skip to content

Commit ede25fd

Browse files
committed
writing tests
1 parent a8a536e commit ede25fd

File tree

8 files changed

+60
-106
lines changed

8 files changed

+60
-106
lines changed

tests/nest/Nest.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function __construct($root) {
1616
$this->root = $root . '/';
1717
$this->testCase = $this->root . 'nest/test-case/';
1818
$this->dbStorage = $this->root . 'nest/test-db-storage/';
19-
$this->testStore = $this->dbStorage . 'mysite/';
19+
$this->testStore = $this->dbStorage;
2020
}
2121

2222
function getAllTestCases() {
@@ -51,15 +51,33 @@ public function runTest() {
5151
'timeout' => 120
5252
] );
5353

54+
$total = [
55+
'success' => 0,
56+
'failed' => 0,
57+
'tests' => 0
58+
];
59+
5460
// Empty the test store.
5561
if ( file_exists( $this->testStore ) ) $this->emptyTestStore();
5662
foreach ($this->getAllTestCases() as $key => $testCase) {
63+
$total[ 'tests' ] = $total[ 'tests' ] + 1;
5764
require_once $this->testCase . $testCase;
58-
$this->print_default( $title );
59-
$this->print_success(
60-
$this->translateFileNameToFunctionName( $testCase )( $database )
61-
);
65+
$this->print_warning( $test['title'] );
66+
if( $test['result'] === true ) {
67+
$this->print_success( '✔ Test passed.' );
68+
$total[ 'success' ] = $total[ 'success' ] + 1;
69+
} else {
70+
$total[ 'failed' ] = $total[ 'failed' ] + 1;
71+
$this->print_danger( '✘ Test failed.' );
72+
$this->print_default( $test[ 'message' ] );
73+
}
6274
}
75+
echo ". . . . . . . . . . . . . . . .\n";
76+
// Test stat
77+
$this->print_default( "↳ Total tests\t: " . $total[ 'tests' ] );
78+
if( $total[ 'success' ] > 0 ) $this->print_success( "✔ Total passed\t: " . $total[ 'success' ] );
79+
if( $total[ 'failed' ] > 0 ) $this->print_danger( "✘ Total failed:\t: " . $total[ 'failed' ] );
80+
6381
}
6482

6583
}

tests/nest/nest.utils.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
/**
33
* A list of methods for the Nest testing framework for SleekDB.
4+
*
45
*/
56
trait NestUtils {
67

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

3-
$title = 'Trying to connect to the store "mysite"';
3+
$test = [
4+
'title' => 'Connecting to the store "mysite"',
5+
'result' => false,
6+
'message' => ''
7+
];
48

5-
function connect_to_store( $database ) {
9+
try {
610
$database->store( "mysite" );
7-
}
11+
$test['result'] = true;
12+
} catch( Exception $e ) {
13+
$test['result'] = false;
14+
$test['message'] = $e->getMessage();
15+
}
Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
<?php
22

3-
$title = 'Inserting a single data';
3+
$test = [
4+
'title' => 'Inserting a single data',
5+
'result' => false,
6+
'message' => ''
7+
];
48

5-
function insert_single_data() {
6-
return "Hello from insert-single-data";
7-
}
9+
try {
10+
11+
$data = $database->store( "mysite" )->insert([
12+
'title' => 'Lorem ipsum dolor sit amet',
13+
'count' => 2,
14+
'price' => 43.23,
15+
'rate' => 'BDT'
16+
]);
17+
18+
// if(!isset($data))
19+
print_r($data);
20+
exit();
21+
22+
$test['result'] = true;
23+
} catch( Exception $e ) {
24+
$test['result'] = false;
25+
$test['message'] = $e->getMessage();
26+
}

tests/nest/test-db-storage/index.php

Lines changed: 0 additions & 93 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"title":"Lorem ipsum dolor sit amet","count":2,"price":43.23,"rate":"BDT","_id":1}

tests/nest/test-db-storage/mysite/mysite/_cnt.sdb

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)