CreationTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. use PHPUnit\Framework\TestCase;
  3. use Limen\Redisun\Examples\HashModel;
  4. use Limen\Redisun\Examples\SetModel;
  5. class CreationTest extends TestCase
  6. {
  7. public function testCreate()
  8. {
  9. try {
  10. $hash = new HashModel();
  11. $girl = [
  12. 'name' => 'maria',
  13. 'age' => 18,
  14. ];
  15. $hash->create(1, $girl, 100);
  16. $this->assertFalse($hash->createNotExists(1, $girl, 100));
  17. $this->assertTrue($hash->createExists(1, $girl, 100));
  18. } catch (Exception $e) {
  19. throw $e;
  20. } finally {
  21. $hash->destroy(1);
  22. }
  23. try {
  24. $set = new SetModel();
  25. $girls = [
  26. 'maria',
  27. 'lily',
  28. ];
  29. $set->create(1, $girls, 100);
  30. $this->assertTrue($set->createExists(1, $girl, 100));
  31. $this->assertFalse($set->createNotExists(1, $girl, 100));
  32. } catch (Exception $e) {
  33. throw $e;
  34. } finally {
  35. $set->destroy(1);
  36. }
  37. }
  38. public function testInsert()
  39. {
  40. try {
  41. $string = new \Limen\Redisun\Examples\StringModel();
  42. $bindings = [
  43. 'id' => 1,
  44. 'name' => 'demo',
  45. ];
  46. $string->newQuery()->insert($bindings, 'hello world!', 120);
  47. $this->assertFalse($string->newQuery()->insert($bindings, 'hello world!', 120, false));
  48. $this->assertTrue($string->newQuery()->insert($bindings, 'hello world!', 120, true));
  49. } catch (Exception $e) {
  50. throw $e;
  51. } finally {
  52. $string->newQuery()->where('id', 1)->where('name', 'demo')->delete();
  53. }
  54. try {
  55. $list = new \Limen\Redisun\Examples\ListModel();
  56. $list->newQuery()->insert(['id' => 1], [1,2,3], 120);
  57. $this->assertFalse($list->newQuery()->insertNotExists(['id' => 1], [1,2,3], 120));
  58. $this->assertTrue($list->newQuery()->insertExists(['id' => 1], [1,2,3], 120));
  59. } catch (Exception $e) {
  60. throw $e;
  61. } finally {
  62. $list->destroy(1);
  63. }
  64. }
  65. }