Cache.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Mtf\Util\Command\Cli;
  7. use Magento\Mtf\Util\Command\Cli;
  8. /**
  9. * Handle cache for tests executions.
  10. */
  11. class Cache
  12. {
  13. /**
  14. * Perform bin/magento commands from command line for functional tests executions.
  15. *
  16. * @var Cli
  17. */
  18. private $cli;
  19. /**
  20. * Cache constructor.
  21. * @param Cli $cli
  22. */
  23. public function __construct(Cli $cli)
  24. {
  25. $this->cli = $cli;
  26. }
  27. /**
  28. * Parameter for flush cache command.
  29. */
  30. const PARAM_CACHE_FLUSH = 'cache:flush';
  31. /**
  32. * Parameter for cache disable command.
  33. */
  34. const PARAM_CACHE_DISABLE = 'cache:disable';
  35. /**
  36. * Parameter for cache enable command.
  37. */
  38. const PARAM_CACHE_ENABLE = 'cache:enable';
  39. /**
  40. * Flush Cache.
  41. * If no parameters are set, all cache types are flushed.
  42. *
  43. * @param array $cacheTypes
  44. * @return void
  45. */
  46. public function flush(array $cacheTypes = [])
  47. {
  48. $options = empty($cacheTypes) ? '' : ' ' . implode(' ', $cacheTypes);
  49. $this->cli->execute(Cache::PARAM_CACHE_FLUSH . $options);
  50. }
  51. /**
  52. * Disable all cache or one cache type.
  53. *
  54. * @param string $cacheType [optional]
  55. * @return void
  56. */
  57. public function disableCache($cacheType = null)
  58. {
  59. $this->cli->execute(Cache::PARAM_CACHE_DISABLE . ($cacheType ? " $cacheType" : ''));
  60. }
  61. /**
  62. * Enable all cache or one cache type.
  63. *
  64. * @param string $cacheType [optional]
  65. * @return void
  66. */
  67. public function enableCache($cacheType = null)
  68. {
  69. $this->cli->execute(Cache::PARAM_CACHE_ENABLE . ($cacheType ? " $cacheType" : ''));
  70. }
  71. }