PageRenderTime 36ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/integration/Cache/Cache/DeleteMultipleCest.php

http://github.com/phalcon/cphalcon
PHP | 115 lines | 76 code | 19 blank | 20 comment | 0 complexity | a149716ca44da7df0f083d10a645afbb MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * This file is part of the Phalcon Framework.
  4. *
  5. * (c) Phalcon Team <team@phalcon.io>
  6. *
  7. * For the full copyright and license information, please view the LICENSE.txt
  8. * file that was distributed with this source code.
  9. */
  10. declare(strict_types=1);
  11. namespace Phalcon\Test\Integration\Cache\Cache;
  12. use Phalcon\Cache;
  13. use Phalcon\Cache\AdapterFactory;
  14. use Phalcon\Cache\Exception\InvalidArgumentException;
  15. use Phalcon\Storage\SerializerFactory;
  16. use IntegrationTester;
  17. use function uniqid;
  18. class DeleteMultipleCest
  19. {
  20. /**
  21. * Tests Phalcon\Cache :: deleteMultiple()
  22. *
  23. * @author Phalcon Team <team@phalcon.io>
  24. * @since 2019-05-01
  25. */
  26. public function cacheCacheDeleteMultiple(IntegrationTester $I)
  27. {
  28. $I->wantToTest('Cache\Cache - deleteMultiple()');
  29. $serializer = new SerializerFactory();
  30. $factory = new AdapterFactory($serializer);
  31. $instance = $factory->newInstance('apcu');
  32. $adapter = new Cache($instance);
  33. $key1 = uniqid();
  34. $key2 = uniqid();
  35. $key3 = uniqid();
  36. $key4 = uniqid();
  37. $adapter->setMultiple(
  38. [
  39. $key1 => 'test1',
  40. $key2 => 'test2',
  41. $key3 => 'test3',
  42. $key4 => 'test4',
  43. ]
  44. );
  45. $I->assertTrue($adapter->has($key1));
  46. $I->assertTrue($adapter->has($key2));
  47. $I->assertTrue($adapter->has($key3));
  48. $I->assertTrue($adapter->has($key4));
  49. $I->assertTrue(
  50. $adapter->deleteMultiple(
  51. [
  52. $key1,
  53. $key2,
  54. ]
  55. )
  56. );
  57. $I->assertFalse($adapter->has($key1));
  58. $I->assertFalse($adapter->has($key2));
  59. $I->assertTrue($adapter->has($key3));
  60. $I->assertTrue($adapter->has($key4));
  61. $I->assertTrue($adapter->delete($key3));
  62. $I->assertTrue($adapter->delete($key4));
  63. $I->assertFalse(
  64. $adapter->deleteMultiple(
  65. [
  66. $key3,
  67. $key4,
  68. ]
  69. )
  70. );
  71. $I->assertFalse($adapter->has($key1));
  72. $I->assertFalse($adapter->has($key2));
  73. $I->assertFalse($adapter->has($key3));
  74. $I->assertFalse($adapter->has($key4));
  75. }
  76. /**
  77. * Tests Phalcon\Cache :: deleteMultiple() - exception
  78. *
  79. * @author Phalcon Team <team@phalcon.io>
  80. * @since 2019-05-01
  81. */
  82. public function cacheCacheDeleteMultipleException(IntegrationTester $I)
  83. {
  84. $I->wantToTest('Cache\Cache - deleteMultiple() - exception');
  85. $I->expectThrowable(
  86. new InvalidArgumentException('The keys need to be an array or instance of Traversable'),
  87. function () {
  88. $serializer = new SerializerFactory();
  89. $factory = new AdapterFactory($serializer);
  90. $instance = $factory->newInstance('apcu');
  91. $adapter = new Cache($instance);
  92. $actual = $adapter->deleteMultiple(1234);
  93. }
  94. );
  95. }
  96. }