Skip to content

Commit

Permalink
Automatic tests for CometQL api
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorTrapenok committed Aug 9, 2017
1 parent 0ecb548 commit e7097c2
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

## JavaScript API

See documentation here [EN](https://comet-server.com/wiki/doku.php/en:comet:javascript_api#javascript_api) [RU](https://comet-server.com/wiki/doku.php/comet:javascript_api#javascript_api)
4 changes: 4 additions & 0 deletions coverage/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

## Calculate coverage

Scripts for calculate coverage in tests
Empty file added tests/api-tests/index.html
Empty file.
3 changes: 3 additions & 0 deletions tests/api-tests/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Automatic tests

Automatic tests for CometQL api
66 changes: 66 additions & 0 deletions tests/api-tests/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

// More info about CppComet http://comet-server.org/doku.php/en
// More info about CometQL http://comet-server.org/doku.php/en:comet:cometql
// More info about auth in CppComet http://comet-server.org/doku.php/en:comet:authentication

header('Content-Type: text/html; charset=utf-8');
header("Access-Control-Allow-Origin: *");
if($_SERVER['REQUEST_METHOD'] == 'OPTIONS')
{
exit();
}

ini_set('display_errors','on');
error_reporting (E_ALL);
session_start();

include './utils/timetest.php';
include './utils/testClass.php';

$count = 100;
if(isset($_GET['count']))
{
$count = $_GET['count'];
if($count > 100)
{
return "-1";
}
}

$test = preg_replace("#[^A-z0-9\_\-]#usi", "", $_GET['test']);
if(!file_exists("./tests/".$test.".php"))
{
return "-1";
}

include "./tests/".$test.".php";

// We connect to the comet server with login and password for the access demo (you can get your data for connection after registration at comet-server.com)
// Login 15
// Password lPXBFPqNg3f661JcegBY0N0dPXqUBdHXqj2cHf04PZgLHxT6z55e20ozojvMRvB8
// CometQL_v1 database
$cppTest->init([
"host" => "app.comet-server.ru",
"user" => "15",
"password" => "lPXBFPqNg3f661JcegBY0N0dPXqUBdHXqj2cHf04PZgLHxT6z55e20ozojvMRvB8",
"api_version" => "CometQL_v1"
]);


$cppTest->start();
timeTest::test('cpp', 'test');
for($i =0; $i<$count; $i++)
{
$cppTest->test();
}
$t = timeTest::test('cpp','test');
$t = $t[count($t) - 1];

$cppTest->stop();

echo json_encode([
'count' => $count,
'test' => $test,
'time' => $t['time']
]);
13 changes: 13 additions & 0 deletions tests/api-tests/tests/mysqli_connect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

class test_mysqli_connect extends testClass{

function test()
{
$l = mysqli_connect($this->opt['host'], $this->opt['user'], $this->opt['password'], $this->opt['api_version']);
echo mysqli_error($l)."\n";
mysqli_close($l);
}
}

$cppTest = new test_mysqli_connect();
17 changes: 17 additions & 0 deletions tests/api-tests/tests/users_auth_insert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php


class users_auth_insert extends testClass{

public $count = 0;

function test()
{
$this->count++;
$query = "INSERT INTO users_auth (id, hash )VALUES (".$this->count.", 'hash".$this->count."');";
mysqli_query($this->link, $query);
}
}

$cppTest = new users_auth_insert();

35 changes: 35 additions & 0 deletions tests/api-tests/utils/testClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

class testClass{

public $link;
public $opt;

function init($opt){
$this->opt = $opt;
}

function start()
{
$this->link = mysqli_connect(
$this->opt['host'],
$this->opt['user'],
$this->opt['password'],
$this->opt['api_version']);
if(!$this->link || mysqli_errno($this->link))
{
echo "Error:". mysqli_error($this->link);
exit();
}
}

function test(){

}

function stop()
{
mysqli_close($this->link);
}

}
23 changes: 23 additions & 0 deletions tests/api-tests/utils/timetest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

class timeTest{

public static $timeTestArray = array();
public static function test($group, $name = '')
{
if(!isset(self::$timeTestArray[$group]))
{
self::$timeTestArray[$group] = array();
self::$timeTestArray[$group][] = array("now" =>microtime(true), "name" => $name, "delta" => 0, "time" => 0 );
return self::$timeTestArray[$group];
}

self::$timeTestArray[$group][] = array(
"now" =>microtime(true),
"name" => $name,
"time" => microtime(true) - self::$timeTestArray[$group][0]["now"], // Общее время на группу
"delta" => microtime(true) - self::$timeTestArray[$group][count(self::$timeTestArray[$group])-1]["now"] // Время на последнеею операцию
);
return self::$timeTestArray[$group];
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit e7097c2

Please sign in to comment.