ApplicationTrait.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: yunwuxin <448901948@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace think\testing;
  12. use think\Db;
  13. use think\facade\Session;
  14. trait ApplicationTrait
  15. {
  16. public function withSession(array $data)
  17. {
  18. foreach ($data as $key => $value) {
  19. Session::set($key, $value);
  20. }
  21. return $this;
  22. }
  23. public function clearSession()
  24. {
  25. Session::clear();
  26. }
  27. protected function seeInDatabase($table, array $data)
  28. {
  29. $count = Db::name($table)->where($data)->count();
  30. $this->assertGreaterThan(0, $count, sprintf(
  31. 'Unable to find row in database table [%s] that matched attributes [%s].', $table, json_encode($data)
  32. ));
  33. return $this;
  34. }
  35. protected function notSeeInDatabase($table, array $data)
  36. {
  37. $count = Db::name($table)->where($data)->count();
  38. $this->assertEquals(0, $count, sprintf(
  39. 'Found unexpected records in database table [%s] that matched attributes [%s].', $table, json_encode($data)
  40. ));
  41. return $this;
  42. }
  43. }