???????????????????????????????????? login.php ????????????????????? classes????????????? class_login.php ??????? login.php ?????汾??
<?php
class Login {
// ???????PHPUnit???????????????????????????????????
public function login($workNumber = ""??$password = ""??$tableName = "") {
$con = mysqli_connect("localhost"?? "root"?? ""?? "teacher_class_system");
if (!$con) {
die('Could not connect: ' . mysqli_error());
} else {
mysqli_query($con?? "SET NAMES utf8");
$result = mysqli_query($con?? "SELECT * FROM $tableName where workNumber = $workNumber and password = $password");
if (!$result || mysqli_num_rows($result) == 0) {
return "false";
} else {
$result_arr = mysqli_fetch_assoc($result);
return json_encode($result_arr?? JSON_UNESCAPED_UNICODE);
}
}
}
}
?>
?????????????????????? login.php ??????????????£?
<?php
error_reporting(0);
require_once './classes/class_login.php';
$workNumber = $_POST["login-user"];
$password = $_POST["login-password"];
$tableName = $_POST["ident"];
$log = new Login;
$response = $log->login($workNumber??$password??$tableName);
if($response != "false") {
session_start();
$_SESSION['id']=$tableName;
}
echo $response;
?>
???????д???????
????????????????? D: epositoryCourseManagementmobile_api_test ???????????????????? `login_test.php' ????д?????′???
<?php
require_once dirname(__FILE__).'/../mobile_api/classes/class_login.php';
class LoginTest extends PHPUnit_Framework_TestCase {
public function testLoginSuccess() {
$expected = '{"workNumber":"00001"??"password":"00001"??"name":"????"??"sex":"??"??"birthday":"20151201"??"department":"?????"??"telephone":"110"??"email":"git@github.com"}';
$workNumber = '00001';
$password = '00001';
$tableName = 'user_teacher';
$lg = new Login;
$actual = $lg->login($workNumber??$password??$tableName);
$this->assertEquals($expected??$actual);
}
function testLoginFail() {
$expected = 'false';
$workNumber = '11111';
$password = '11111';
$tableName = 'user_teacher';
$lg = new Login;
$actual = $lg->login($workNumber??$password??$tableName);
$this->assertEquals($expected??$actual);
}
}
?>
??????в??????
???????? Win + R ??????cmd???????????ò???????????????? phpunit login_test.php ??в????

?????????????????
????????????????
????????????PHPUnit????? .phar ?????????????????????????????????????????????????????????????????????????……
???????????????????????????????
????'php' ????????????????????????е????
?????????????????
????Google???????????????StackOverFlow???????????????????????????á?
????????????????????????????ú???PHP????????……
?????????????????????? phpunit.cmd ????????????????????????????????????PHP???????????????????cmd?????? php --version ???????
????'php' ????????????????????????е????
?????????????????
?????????????????????????????????????? ;E:softwarewampinphpphp5.5.12 ?????????????С??????? php --version ?????
????PHP 5.5.12 (cli) (built: Apr 30 2014 11:20:58)
????Copyright (c) 1997-2014 The PHP Group
????Zend Engine v2.5.0?? Copyright (c) 1998-2014 Zend Technologies
????with Xdebug v2.2.5?? Copyright (c) 2002-2014?? by Derick Rethans
????????? phpunit.cmd ????????У????? phpunit --version???????
????PHPUnit 4.8.18 by Sebastian Bergmann and contributors.
????????????
??????????ε?????????????"?????xxx"????????????????????????????????á?
??????????????????????磬???????Visual Studio Code??Git??????????????????

??????????????????????????msysgit????
??????????????????????????????????????????????????????С?????? git.exe ????????е?·?????????????Visual Studio Code??????????