[phpunit::update] api first tests
This commit is contained in:
parent
402f7c7f06
commit
8aafcbfdcf
|
@ -5,5 +5,6 @@ parameters:
|
||||||
phplint: ~
|
phplint: ~
|
||||||
phpunit:
|
phpunit:
|
||||||
config_file: phpunit/phpunit.xml
|
config_file: phpunit/phpunit.xml
|
||||||
|
always_execute: true
|
||||||
jsonlint:
|
jsonlint:
|
||||||
detect_key_conflicts: true
|
detect_key_conflicts: true
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
require_once './vendor/autoload.php';
|
|
||||||
|
|
||||||
/* [0] On definit la racine __ROOT__ si c'est pas deja fait
|
/* [0] On definit la racine __ROOT__ si c'est pas deja fait
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
|
@ -67,4 +66,8 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
require_once __ROOT__.'/vendor/autoload.php';
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -43,49 +43,49 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td class="danger">Total</td>
|
<td class="danger">Total</td>
|
||||||
<td class="danger big"> <div class="progress">
|
<td class="danger big"> <div class="progress">
|
||||||
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="0.00" aria-valuemin="0" aria-valuemax="100" style="width: 0.00%">
|
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="23.47" aria-valuemin="0" aria-valuemax="100" style="width: 23.47%">
|
||||||
<span class="sr-only">0.00% covered (danger)</span>
|
<span class="sr-only">23.47% covered (danger)</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="danger small"><div align="right">0.00%</div></td>
|
<td class="danger small"><div align="right">23.47%</div></td>
|
||||||
<td class="danger small"><div align="right">0 / 3248</div></td>
|
<td class="danger small"><div align="right">667 / 2842</div></td>
|
||||||
<td class="danger big"> <div class="progress">
|
<td class="danger big"> <div class="progress">
|
||||||
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="0.00" aria-valuemin="0" aria-valuemax="100" style="width: 0.00%">
|
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="10.14" aria-valuemin="0" aria-valuemax="100" style="width: 10.14%">
|
||||||
<span class="sr-only">0.00% covered (danger)</span>
|
<span class="sr-only">10.14% covered (danger)</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="danger small"><div align="right">0.00%</div></td>
|
<td class="danger small"><div align="right">10.14%</div></td>
|
||||||
<td class="danger small"><div align="right">0 / 219</div></td>
|
<td class="danger small"><div align="right">21 / 207</div></td>
|
||||||
<td class="danger big"> <div class="progress">
|
<td class="danger big"> <div class="progress">
|
||||||
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="0.00" aria-valuemin="0" aria-valuemax="100" style="width: 0.00%">
|
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="2.44" aria-valuemin="0" aria-valuemax="100" style="width: 2.44%">
|
||||||
<span class="sr-only">0.00% covered (danger)</span>
|
<span class="sr-only">2.44% covered (danger)</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="danger small"><div align="right">0.00%</div></td>
|
<td class="danger small"><div align="right">2.44%</div></td>
|
||||||
<td class="danger small"><div align="right">0 / 41</div></td>
|
<td class="danger small"><div align="right">1 / 41</div></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td class="danger"><span class="glyphicon glyphicon-folder-open"></span> <a href="api/index.html">api</a></td>
|
<td class="danger"><span class="glyphicon glyphicon-folder-open"></span> <a href="api/index.html">api</a></td>
|
||||||
<td class="danger big"> <div class="progress">
|
<td class="danger big"> <div class="progress">
|
||||||
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="0.00" aria-valuemin="0" aria-valuemax="100" style="width: 0.00%">
|
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="17.55" aria-valuemin="0" aria-valuemax="100" style="width: 17.55%">
|
||||||
<span class="sr-only">0.00% covered (danger)</span>
|
<span class="sr-only">17.55% covered (danger)</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="danger small"><div align="right">0.00%</div></td>
|
<td class="danger small"><div align="right">17.55%</div></td>
|
||||||
<td class="danger small"><div align="right">0 / 1139</div></td>
|
<td class="danger small"><div align="right">179 / 1020</div></td>
|
||||||
<td class="danger big"> <div class="progress">
|
<td class="danger big"> <div class="progress">
|
||||||
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="0.00" aria-valuemin="0" aria-valuemax="100" style="width: 0.00%">
|
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="5.56" aria-valuemin="0" aria-valuemax="100" style="width: 5.56%">
|
||||||
<span class="sr-only">0.00% covered (danger)</span>
|
<span class="sr-only">5.56% covered (danger)</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="danger small"><div align="right">0.00%</div></td>
|
<td class="danger small"><div align="right">5.56%</div></td>
|
||||||
<td class="danger small"><div align="right">0 / 72</div></td>
|
<td class="danger small"><div align="right">4 / 72</div></td>
|
||||||
<td class="danger big"> <div class="progress">
|
<td class="danger big"> <div class="progress">
|
||||||
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="0.00" aria-valuemin="0" aria-valuemax="100" style="width: 0.00%">
|
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="0.00" aria-valuemin="0" aria-valuemax="100" style="width: 0.00%">
|
||||||
<span class="sr-only">0.00% covered (danger)</span>
|
<span class="sr-only">0.00% covered (danger)</span>
|
||||||
|
@ -99,49 +99,49 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td class="danger"><span class="glyphicon glyphicon-folder-open"></span> <a href="database/index.html">database</a></td>
|
<td class="danger"><span class="glyphicon glyphicon-folder-open"></span> <a href="database/index.html">database</a></td>
|
||||||
<td class="danger big"> <div class="progress">
|
<td class="danger big"> <div class="progress">
|
||||||
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="0.00" aria-valuemin="0" aria-valuemax="100" style="width: 0.00%">
|
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="18.46" aria-valuemin="0" aria-valuemax="100" style="width: 18.46%">
|
||||||
<span class="sr-only">0.00% covered (danger)</span>
|
<span class="sr-only">18.46% covered (danger)</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="danger small"><div align="right">0.00%</div></td>
|
<td class="danger small"><div align="right">18.46%</div></td>
|
||||||
<td class="danger small"><div align="right">0 / 952</div></td>
|
<td class="danger small"><div align="right">141 / 764</div></td>
|
||||||
<td class="danger big"> <div class="progress">
|
<td class="danger big"> <div class="progress">
|
||||||
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="0.00" aria-valuemin="0" aria-valuemax="100" style="width: 0.00%">
|
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="11.11" aria-valuemin="0" aria-valuemax="100" style="width: 11.11%">
|
||||||
<span class="sr-only">0.00% covered (danger)</span>
|
<span class="sr-only">11.11% covered (danger)</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="danger small"><div align="right">0.00%</div></td>
|
<td class="danger small"><div align="right">11.11%</div></td>
|
||||||
<td class="danger small"><div align="right">0 / 84</div></td>
|
<td class="danger small"><div align="right">8 / 72</div></td>
|
||||||
<td class="danger big"> <div class="progress">
|
<td class="danger big"> <div class="progress">
|
||||||
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="0.00" aria-valuemin="0" aria-valuemax="100" style="width: 0.00%">
|
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="7.69" aria-valuemin="0" aria-valuemax="100" style="width: 7.69%">
|
||||||
<span class="sr-only">0.00% covered (danger)</span>
|
<span class="sr-only">7.69% covered (danger)</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="danger small"><div align="right">0.00%</div></td>
|
<td class="danger small"><div align="right">7.69%</div></td>
|
||||||
<td class="danger small"><div align="right">0 / 13</div></td>
|
<td class="danger small"><div align="right">1 / 13</div></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td class="danger"><span class="glyphicon glyphicon-folder-open"></span> <a href="error/index.html">error</a></td>
|
<td class="danger"><span class="glyphicon glyphicon-folder-open"></span> <a href="error/index.html">error</a></td>
|
||||||
<td class="danger big"> <div class="progress">
|
<td class="danger big"> <div class="progress">
|
||||||
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="0.00" aria-valuemin="0" aria-valuemax="100" style="width: 0.00%">
|
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="5.68" aria-valuemin="0" aria-valuemax="100" style="width: 5.68%">
|
||||||
<span class="sr-only">0.00% covered (danger)</span>
|
<span class="sr-only">5.68% covered (danger)</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="danger small"><div align="right">0.00%</div></td>
|
<td class="danger small"><div align="right">5.68%</div></td>
|
||||||
<td class="danger small"><div align="right">0 / 99</div></td>
|
<td class="danger small"><div align="right">5 / 88</div></td>
|
||||||
<td class="danger big"> <div class="progress">
|
<td class="danger big"> <div class="progress">
|
||||||
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="0.00" aria-valuemin="0" aria-valuemax="100" style="width: 0.00%">
|
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="40.00" aria-valuemin="0" aria-valuemax="100" style="width: 40.00%">
|
||||||
<span class="sr-only">0.00% covered (danger)</span>
|
<span class="sr-only">40.00% covered (danger)</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="danger small"><div align="right">0.00%</div></td>
|
<td class="danger small"><div align="right">40.00%</div></td>
|
||||||
<td class="danger small"><div align="right">0 / 5</div></td>
|
<td class="danger small"><div align="right">2 / 5</div></td>
|
||||||
<td class="danger big"> <div class="progress">
|
<td class="danger big"> <div class="progress">
|
||||||
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="0.00" aria-valuemin="0" aria-valuemax="100" style="width: 0.00%">
|
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="0.00" aria-valuemin="0" aria-valuemax="100" style="width: 0.00%">
|
||||||
<span class="sr-only">0.00% covered (danger)</span>
|
<span class="sr-only">0.00% covered (danger)</span>
|
||||||
|
@ -181,23 +181,23 @@
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td class="danger"><span class="glyphicon glyphicon-folder-open"></span> <a href="orm/index.html">orm</a></td>
|
<td class="warning"><span class="glyphicon glyphicon-folder-open"></span> <a href="orm/index.html">orm</a></td>
|
||||||
<td class="danger big"> <div class="progress">
|
<td class="warning big"> <div class="progress">
|
||||||
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="0.00" aria-valuemin="0" aria-valuemax="100" style="width: 0.00%">
|
<div class="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="69.23" aria-valuemin="0" aria-valuemax="100" style="width: 69.23%">
|
||||||
<span class="sr-only">0.00% covered (danger)</span>
|
<span class="sr-only">69.23% covered (warning)</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="danger small"><div align="right">0.00%</div></td>
|
<td class="warning small"><div align="right">69.23%</div></td>
|
||||||
<td class="danger small"><div align="right">0 / 582</div></td>
|
<td class="warning small"><div align="right">342 / 494</div></td>
|
||||||
<td class="danger big"> <div class="progress">
|
<td class="danger big"> <div class="progress">
|
||||||
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="0.00" aria-valuemin="0" aria-valuemax="100" style="width: 0.00%">
|
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="28.00" aria-valuemin="0" aria-valuemax="100" style="width: 28.00%">
|
||||||
<span class="sr-only">0.00% covered (danger)</span>
|
<span class="sr-only">28.00% covered (danger)</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="danger small"><div align="right">0.00%</div></td>
|
<td class="danger small"><div align="right">28.00%</div></td>
|
||||||
<td class="danger small"><div align="right">0 / 25</div></td>
|
<td class="danger small"><div align="right">7 / 25</div></td>
|
||||||
<td class="danger big"> <div class="progress">
|
<td class="danger big"> <div class="progress">
|
||||||
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="0.00" aria-valuemin="0" aria-valuemax="100" style="width: 0.00%">
|
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="0.00" aria-valuemin="0" aria-valuemax="100" style="width: 0.00%">
|
||||||
<span class="sr-only">0.00% covered (danger)</span>
|
<span class="sr-only">0.00% covered (danger)</span>
|
||||||
|
@ -276,7 +276,7 @@
|
||||||
<span class="success"><strong>High</strong>: 90% to 100%</span>
|
<span class="success"><strong>High</strong>: 90% to 100%</span>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.2.1</a> using <a href="https://secure.php.net/" target="_top">PHP 7.0.15-0ubuntu0.16.04.4</a> with <a href="https://xdebug.org/">Xdebug 2.4.0</a> and <a href="https://phpunit.de/">PHPUnit 6.1.3</a> at Fri May 12 16:15:58 UTC 2017.</small>
|
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.2.1</a> using <a href="https://secure.php.net/" target="_top">PHP 7.0.15-0ubuntu0.16.04.4</a> with <a href="https://xdebug.org/">Xdebug 2.4.0</a> and <a href="https://phpunit.de/">PHPUnit 6.1.3</a> at Fri May 12 21:51:59 UTC 2017.</small>
|
||||||
</p>
|
</p>
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
<phpunit bootstrap="bootstrap.php">
|
<phpunit bootstrap="./bootstrap.php">
|
||||||
|
|
||||||
<testsuites>
|
<testsuites>
|
||||||
|
|
||||||
<testsuite name="api/config">
|
<testsuite name="user">
|
||||||
<directory prefix="api">./tests</directory>
|
<file>./tests/user/create.php</file>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
|
|
||||||
</testsuites>
|
</testsuites>
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
<?php
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class apiconfig extends TestCase{
|
|
||||||
|
|
||||||
|
|
||||||
public function checkConfig(){
|
|
||||||
|
|
||||||
/* [1] Check configuration
|
|
||||||
=========================================================*/
|
|
||||||
/* (1) Check file */
|
|
||||||
$path = __CONFIG__.'/modules.json';
|
|
||||||
$this->assertFileExists($path);
|
|
||||||
|
|
||||||
/* (2) Checks json */
|
|
||||||
$config = json_decode( file_get_contents($path), true );
|
|
||||||
$this->assertNotNull($config);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
|
@ -0,0 +1,127 @@
|
||||||
|
<?php
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
use \api\core\Request;
|
||||||
|
use \error\core\Err;
|
||||||
|
use \orm\core\Table;
|
||||||
|
use \orm\core\Rows;
|
||||||
|
|
||||||
|
class create extends TestCase{
|
||||||
|
|
||||||
|
private static $created;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @before
|
||||||
|
*/
|
||||||
|
public function setUp(){
|
||||||
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
||||||
|
$_SERVER['SERVER_NAME'] = 'localhost';
|
||||||
|
|
||||||
|
$adminReq = Table::get('admin')
|
||||||
|
->select('id_warehouse')
|
||||||
|
->select('token')
|
||||||
|
->fetch();
|
||||||
|
|
||||||
|
$_SERVER['PHP_AUTH_DIGEST'] = $adminReq[0]['token'];
|
||||||
|
|
||||||
|
$warehouseReq = Table::get('warehouse')
|
||||||
|
->whereId($adminReq[0]['id_warehouse'])
|
||||||
|
->select('token')
|
||||||
|
->fetch();
|
||||||
|
|
||||||
|
$_SERVER['PHP_AUTH_DIGEST'] = $warehouseReq[0]['token'].$_SERVER['PHP_AUTH_DIGEST'];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* API manifest
|
||||||
|
*
|
||||||
|
* FIELD TYPE
|
||||||
|
* --------- -------
|
||||||
|
* code rfid
|
||||||
|
* username varchar(1,30,alphanumeric)
|
||||||
|
* firstname varchar(3,30,letters)
|
||||||
|
* lastname varchar(3,30,letters)
|
||||||
|
* mail mail
|
||||||
|
*
|
||||||
|
* Note: letters is alphanumeric + ' '
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
public function testCreateCorrect(){
|
||||||
|
|
||||||
|
/* (1) Création requête */
|
||||||
|
$req = new Request('userDefault/create', [
|
||||||
|
'code' => '12-AB-CD-EF',
|
||||||
|
'username' => 'abcdef123456',
|
||||||
|
'firstname' => 'a bcdef123456',
|
||||||
|
'lastname' => 'ab cdef123456',
|
||||||
|
'mail' => 'ab@cd.ef'
|
||||||
|
]);
|
||||||
|
|
||||||
|
/* (2) Gestion erreur */
|
||||||
|
$this->assertEquals($req->error->get(), Err::Success);
|
||||||
|
|
||||||
|
/* (3) Exécution */
|
||||||
|
$res = $req->dispatch();
|
||||||
|
|
||||||
|
/* (4) Gestion erreur */
|
||||||
|
$this->assertEquals($res->error->get(), Err::Success);
|
||||||
|
|
||||||
|
self::$created = $res->get('id_user');
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @depends testCreateCorrect
|
||||||
|
*/
|
||||||
|
public function testCreateAlready(){
|
||||||
|
|
||||||
|
/* (1) Création requête */
|
||||||
|
$req = new Request('userDefault/create', [
|
||||||
|
'code' => '12-AB-CD-EF',
|
||||||
|
'username' => 'abcdef123456',
|
||||||
|
'firstname' => 'a bcdef123456',
|
||||||
|
'lastname' => 'ab cdef123456',
|
||||||
|
'mail' => 'ab@cd.ef'
|
||||||
|
]);
|
||||||
|
|
||||||
|
/* (2) Gestion erreur */
|
||||||
|
$this->assertEquals($req->error->get(), Err::Success);
|
||||||
|
|
||||||
|
/* (3) Gestion erreur */
|
||||||
|
$res = $req->dispatch();
|
||||||
|
|
||||||
|
/* (4) Gestion erreur */
|
||||||
|
$this->assertEquals($res->error->get(), Err::AlreadyExists);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @depends testCreateAlready
|
||||||
|
*/
|
||||||
|
public function testRemoveCreated(){
|
||||||
|
|
||||||
|
/* (1) Création requête */
|
||||||
|
$req = new Request('userDefault/delete', [
|
||||||
|
'id_user' => self::$created
|
||||||
|
]);
|
||||||
|
|
||||||
|
/* (2) Gestion erreur */
|
||||||
|
$this->assertEquals($req->error->get(), Err::Success);
|
||||||
|
|
||||||
|
/* (3) Exécution */
|
||||||
|
$res = $req->dispatch();
|
||||||
|
|
||||||
|
/* (4) Gestion erreur */
|
||||||
|
$this->assertEquals($res->error->get(), Err::Success);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
Loading…
Reference in New Issue