Beispiel #1
0
 /**
  * 混合测试
  */
 public function testMixed()
 {
     $a = new Shuiguang\FormHash();
     $hash = $a->get();
     // 对象————静态测试
     $this->assertEquals(true, Shuiguang\FormHash::verify($hash));
     $b = new Shuiguang\FormHash();
     // 静态————对象测试
     $this->assertEquals(true, $b->verify(Shuiguang\FormHash::get()));
 }
Beispiel #2
0
 /**
  * 混合测试
  */
 public function testTimemixed()
 {
     // 在a页面($a对象)设置过期时间单位为秒: 最短有效时间为1s, 最长有效期为(1+1)s
     $a = new Shuiguang\FormHash();
     $a->format('s');
     $hash = $a->get();
     // 延时0.999999秒
     usleep(999999);
     // 在b页面($b对象)设置过期时间单位为秒: 最短有效时间为1s, 最长有效期为(1+1)s
     $b = new Shuiguang\FormHash();
     $b->format('s');
     // 未超时, 断言返回值为true
     $this->assertEquals(true, $b->verify($hash));
     // 再延时1.000002秒, 共2.000001s
     usleep(1000002);
     // 必然超时, 断言返回值为false
     $this->assertEquals(false, $b->verify($hash));
 }
Beispiel #3
0
 /**
  * 使用回调函数设置样本特征, 测试不同样本特征之间的formhash校验
  */
 public function testFeatureNotSame()
 {
     // 实例化一个a页面($a对象)
     $a = new Shuiguang\FormHash();
     // 设置a页面($a对象)的样本特征
     $a->attach(function ($password) {
         // 样本ID=1
         $id = 1;
         return $password . $id;
     });
     // 实例化一个b页面($b对象)对象, 样本特征与$a对象不一致
     $b = new Shuiguang\FormHash();
     // 设置b页面($b对象)对象的样本特征
     $b->attach(function ($password) {
         // 样本ID=2
         $id = 2;
         return $password . $id;
     });
     // 对$a对象和$b对象之间的formhash进行测试
     $this->assertEquals(true, $a->verify($b->get()));
     $this->assertEquals(true, $b->verify($a->get()));
 }