From 440402701643451b1157baa2377b0e64f4ce7478 Mon Sep 17 00:00:00 2001 From: oldrind <1401019000@qq.com> Date: Tue, 1 Mar 2016 20:42:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0model=E7=B1=BB=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95=E6=96=87=E4=BB=B6=EF=BC=9B=E5=8D=95?= =?UTF-8?q?=E6=9D=A1=E8=A7=84=E5=88=99=E8=BF=94=E5=9B=9E=E5=80=BC=E4=B8=BA?= =?UTF-8?q?=E6=95=B0=E7=BB=84=E6=97=B6=E6=94=B9=E6=88=90=E4=B8=8E$this->er?= =?UTF-8?q?ror=E5=90=88=E5=B9=B6=EF=BC=9B=20=E5=A2=9E=E5=8A=A0=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E8=A7=84=E5=88=99=E6=9D=A1=E4=BB=B6=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E4=B8=BA=E6=AD=A3=E5=88=99=E7=9A=84=E5=88=A4=E6=96=AD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/thinkphp/library/think/modelTest.php | 28 +++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/tests/thinkphp/library/think/modelTest.php b/tests/thinkphp/library/think/modelTest.php index cd0e1caf..50573dd1 100644 --- a/tests/thinkphp/library/think/modelTest.php +++ b/tests/thinkphp/library/think/modelTest.php @@ -19,9 +19,21 @@ use think\Model; class modelTest extends \PHPUnit_Framework_TestCase { + public function getConfig() + { + static $config; + if (!isset($config)) { + $config = \think\Input::get('database'); + $config['database'] = 'test'; + $config['username'] = 'root'; + $config['password'] = ''; + } + return $config; + } + public function testValidate() { - $model = new Model(); + $model = new Model('', $this->getConfig()); $data = [ 'username' => 'username', 'nickname' => 'nickname', @@ -34,7 +46,7 @@ class modelTest extends \PHPUnit_Framework_TestCase 'code' => '1234', ]; - $config = [ + $validate = [ '__pattern__' => [ 'mobile' => '/^1(?:[358]\d|7[6-8])\d{8}$/', 'require' => '/.+/', @@ -61,7 +73,7 @@ class modelTest extends \PHPUnit_Framework_TestCase ], ], ]; - \think\Config::set('validate', $config); + \think\Config::set('validate', $validate); $result = $model->validate('user.add')->create($data); $this->assertEquals('', $model->getError()); @@ -117,7 +129,7 @@ class modelTest extends \PHPUnit_Framework_TestCase public function testFill() { - $model = new Model(); + $model = new Model('', $this->getConfig()); $data = [ 'username' => '', 'nickname' => 'nickname', @@ -125,7 +137,7 @@ class modelTest extends \PHPUnit_Framework_TestCase 'hobby' => ['1', '2'], 'cityid' => '1', ]; - $config = [ + $auto = [ 'user' => [ '__option__' => [ 'value_fill' => ['username', 'password', 'phone'], @@ -143,7 +155,7 @@ class modelTest extends \PHPUnit_Framework_TestCase ['login_time', function($value, $data) {return $data['reg_time'];}], ], ]; - \think\Config::set('auto', $config); + \think\Config::set('auto', $auto); $result = $model->auto('user')->create($data); $data['nickname'] = 'cn_nickname'; $data['phone'] = '123456'; @@ -171,11 +183,11 @@ class modelTest extends \PHPUnit_Framework_TestCase ] ] ]; - $auto = [ + $test = [ 'name.*' => 'name', 'goods.*.*.price' => 100, ]; - $result = $model->auto($auto)->create($data); + $result = $model->auto($test)->create($data); $data['name']['a'] = $data['name']['b'] = 'name'; $data['goods'][0][0]['price'] = 100; $data['goods'][0][1]['price'] = 100;