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/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