From 8aafcbfdcfc197399a4256ccb631d7c413e5f196 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Fri, 12 May 2017 23:52:21 +0200 Subject: [PATCH] [phpunit::update] api first tests --- grumphp.yml | 1 + phpunit/bootstrap.php | 5 +- phpunit/coverage/index.html | 102 +++++++++++++-------------- phpunit/phpunit.xml | 6 +- phpunit/tests/apiconfig.php | 24 ------- phpunit/tests/user/create.php | 127 ++++++++++++++++++++++++++++++++++ 6 files changed, 186 insertions(+), 79 deletions(-) delete mode 100644 phpunit/tests/apiconfig.php create mode 100644 phpunit/tests/user/create.php diff --git a/grumphp.yml b/grumphp.yml index eefbeca..c143648 100644 --- a/grumphp.yml +++ b/grumphp.yml @@ -5,5 +5,6 @@ parameters: phplint: ~ phpunit: config_file: phpunit/phpunit.xml + always_execute: true jsonlint: detect_key_conflicts: true diff --git a/phpunit/bootstrap.php b/phpunit/bootstrap.php index 23aa452..024d29b 100644 --- a/phpunit/bootstrap.php +++ b/phpunit/bootstrap.php @@ -1,5 +1,4 @@ \ No newline at end of file diff --git a/phpunit/coverage/index.html b/phpunit/coverage/index.html index 94c704a..ea24a94 100644 --- a/phpunit/coverage/index.html +++ b/phpunit/coverage/index.html @@ -43,49 +43,49 @@ Total
-
- 0.00% covered (danger) +
+ 23.47% covered (danger)
-
0.00%
-
0 / 3248
+
23.47%
+
667 / 2842
-
- 0.00% covered (danger) +
+ 10.14% covered (danger)
-
0.00%
-
0 / 219
+
10.14%
+
21 / 207
-
- 0.00% covered (danger) +
+ 2.44% covered (danger)
-
0.00%
-
0 / 41
+
2.44%
+
1 / 41
api
-
- 0.00% covered (danger) +
+ 17.55% covered (danger)
-
0.00%
-
0 / 1139
+
17.55%
+
179 / 1020
-
- 0.00% covered (danger) +
+ 5.56% covered (danger)
-
0.00%
-
0 / 72
+
5.56%
+
4 / 72
0.00% covered (danger) @@ -99,49 +99,49 @@ database
-
- 0.00% covered (danger) +
+ 18.46% covered (danger)
-
0.00%
-
0 / 952
+
18.46%
+
141 / 764
-
- 0.00% covered (danger) +
+ 11.11% covered (danger)
-
0.00%
-
0 / 84
+
11.11%
+
8 / 72
-
- 0.00% covered (danger) +
+ 7.69% covered (danger)
-
0.00%
-
0 / 13
+
7.69%
+
1 / 13
error
-
- 0.00% covered (danger) +
+ 5.68% covered (danger)
-
0.00%
-
0 / 99
+
5.68%
+
5 / 88
-
- 0.00% covered (danger) +
+ 40.00% covered (danger)
-
0.00%
-
0 / 5
+
40.00%
+
2 / 5
0.00% covered (danger) @@ -181,23 +181,23 @@ - orm -
-
- 0.00% covered (danger) + orm +
+
+ 69.23% covered (warning)
-
0.00%
-
0 / 582
+
69.23%
+
342 / 494
-
- 0.00% covered (danger) +
+ 28.00% covered (danger)
-
0.00%
-
0 / 25
+
28.00%
+
7 / 25
0.00% covered (danger) @@ -276,7 +276,7 @@ High: 90% to 100%

- Generated by php-code-coverage 5.2.1 using PHP 7.0.15-0ubuntu0.16.04.4 with Xdebug 2.4.0 and PHPUnit 6.1.3 at Fri May 12 16:15:58 UTC 2017. + Generated by php-code-coverage 5.2.1 using PHP 7.0.15-0ubuntu0.16.04.4 with Xdebug 2.4.0 and PHPUnit 6.1.3 at Fri May 12 21:51:59 UTC 2017.

diff --git a/phpunit/phpunit.xml b/phpunit/phpunit.xml index df22e01..7edda87 100755 --- a/phpunit/phpunit.xml +++ b/phpunit/phpunit.xml @@ -1,9 +1,9 @@ - + - - ./tests + + ./tests/user/create.php diff --git a/phpunit/tests/apiconfig.php b/phpunit/tests/apiconfig.php deleted file mode 100644 index 218ffba..0000000 --- a/phpunit/tests/apiconfig.php +++ /dev/null @@ -1,24 +0,0 @@ -assertFileExists($path); - - /* (2) Checks json */ - $config = json_decode( file_get_contents($path), true ); - $this->assertNotNull($config); - - } - - - } - -?> \ No newline at end of file diff --git a/phpunit/tests/user/create.php b/phpunit/tests/user/create.php new file mode 100644 index 0000000..9c59b9d --- /dev/null +++ b/phpunit/tests/user/create.php @@ -0,0 +1,127 @@ +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); + + + } + + + } + +?> \ No newline at end of file