DbTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Cron\Test\Unit\Model\Config\Converter;
  7. class DbTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Cron\Model\Config\Converter\Db
  11. */
  12. protected $_converter;
  13. /**
  14. * Prepare parameters
  15. */
  16. protected function setUp()
  17. {
  18. $this->_converter = new \Magento\Cron\Model\Config\Converter\Db();
  19. }
  20. /**
  21. * Testing not existed list of jobs
  22. */
  23. public function testConvertNoJobs()
  24. {
  25. $source = [];
  26. $result = $this->_converter->convert($source);
  27. $this->assertEmpty($result);
  28. }
  29. /**
  30. * Testing parameters in 'schedule' container
  31. */
  32. public function testConvertConfigParams()
  33. {
  34. $fullJob = ['schedule' => ['config_path' => 'config/path', 'cron_expr' => '* * * * *']];
  35. $nullJob = ['schedule' => ['config_path' => null, 'cron_expr' => null]];
  36. $notFullJob = ['schedule' => ''];
  37. $source = [
  38. 'crontab' => [
  39. 'default' => [
  40. 'jobs' => [
  41. 'job_name_1' => $fullJob,
  42. 'job_name_2' => $nullJob,
  43. 'job_name_3' => $notFullJob,
  44. 'job_name_4' => [],
  45. ],
  46. ],
  47. ],
  48. ];
  49. $expected = [
  50. 'default' => [
  51. 'job_name_1' => ['config_path' => 'config/path', 'schedule' => '* * * * *'],
  52. 'job_name_2' => ['config_path' => null, 'schedule' => null],
  53. 'job_name_3' => ['schedule' => ''],
  54. 'job_name_4' => [''],
  55. ],
  56. ];
  57. $result = $this->_converter->convert($source);
  58. $this->assertEquals(
  59. $expected['default']['job_name_1']['config_path'],
  60. $result['default']['job_name_1']['config_path']
  61. );
  62. $this->assertEquals(
  63. $expected['default']['job_name_1']['schedule'],
  64. $result['default']['job_name_1']['schedule']
  65. );
  66. $this->assertEquals(
  67. $expected['default']['job_name_2']['config_path'],
  68. $result['default']['job_name_2']['config_path']
  69. );
  70. $this->assertEquals(
  71. $expected['default']['job_name_2']['schedule'],
  72. $result['default']['job_name_2']['schedule']
  73. );
  74. $this->assertArrayHasKey('schedule', $result['default']['job_name_3']);
  75. $this->assertEmpty($result['default']['job_name_3']['schedule']);
  76. $this->assertEmpty($result['default']['job_name_4']);
  77. }
  78. /**
  79. * Testing 'run' container
  80. */
  81. public function testConvertRunConfig()
  82. {
  83. $runFullJob = ['run' => ['model' => 'Model1::method1']];
  84. $runNoMethodJob = ['run' => ['model' => 'Model2']];
  85. $runEmptyMethodJob = ['run' => ['model' => 'Model3::']];
  86. $runNoModelJob = ['run' => ['model' => '::method1']];
  87. $source = [
  88. 'crontab' => [
  89. 'default' => [
  90. 'jobs' => [
  91. 'job_name_1' => $runFullJob,
  92. 'job_name_2' => $runNoMethodJob,
  93. 'job_name_3' => $runEmptyMethodJob,
  94. 'job_name_4' => $runNoModelJob,
  95. ],
  96. ],
  97. ],
  98. ];
  99. $expected = [
  100. 'default' => [
  101. 'job_name_1' => ['instance' => 'Model1', 'method' => 'method1'],
  102. 'job_name_2' => [],
  103. 'job_name_3' => [],
  104. 'job_name_4' => [],
  105. ],
  106. ];
  107. $result = $this->_converter->convert($source);
  108. $this->assertEquals(
  109. $expected['default']['job_name_1']['instance'],
  110. $result['default']['job_name_1']['instance']
  111. );
  112. $this->assertEquals($expected['default']['job_name_1']['method'], $result['default']['job_name_1']['method']);
  113. $this->assertEmpty($result['default']['job_name_2']);
  114. $this->assertEmpty($result['default']['job_name_3']);
  115. $this->assertEmpty($result['default']['job_name_4']);
  116. }
  117. }