JobStatusTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * Gearman Bundle for Symfony2
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. *
  8. * Feel free to edit as you please, and have fun.
  9. *
  10. * @author Marc Morera <yuhu@mmoreram.com>
  11. */
  12. namespace Mmoreram\GearmanBundle\Tests\Module;
  13. use PHPUnit_Framework_TestCase;
  14. use Mmoreram\GearmanBundle\Module\JobStatus;
  15. /**
  16. * Tests JobStatusTest class
  17. */
  18. class JobStatusTest extends PHPUnit_Framework_TestCase
  19. {
  20. /**
  21. * Testing job status
  22. *
  23. * @dataProvider dataJobStatusNonExistant
  24. */
  25. public function testJobStatusNonExistant(
  26. $known,
  27. $running,
  28. $completed,
  29. $completionTotal,
  30. $isKnown,
  31. $isRunning,
  32. $getCompleted,
  33. $getCompletionTotal,
  34. $getCompletionPercent,
  35. $isFinished
  36. )
  37. {
  38. $jobStatus = new JobStatus(array(
  39. $known,
  40. $running,
  41. $completed,
  42. $completionTotal
  43. ));
  44. $this->assertEquals($jobStatus->isKnown(), $isKnown);
  45. $this->assertEquals($jobStatus->isRunning(), $isRunning);
  46. $this->assertEquals($jobStatus->getCompleted(), $getCompleted);
  47. $this->assertEquals($jobStatus->getCompletionTotal(), $getCompletionTotal);
  48. $this->assertEquals($jobStatus->getCompletionPercent(), $getCompletionPercent);
  49. $this->assertEquals($jobStatus->isFinished(), $isFinished);
  50. }
  51. /**
  52. * Data provider for testJobStatusNonExistant
  53. */
  54. public function dataJobStatusNonExistant()
  55. {
  56. return array(
  57. /**
  58. * Testing when job does not exist
  59. */
  60. array(
  61. false,
  62. false,
  63. null,
  64. null,
  65. false,
  66. false,
  67. 0,
  68. 0,
  69. 0,
  70. false
  71. ),
  72. /**
  73. * Testing when job is started
  74. */
  75. array(
  76. true,
  77. true,
  78. 0,
  79. 10,
  80. true,
  81. true,
  82. 0,
  83. 10,
  84. 0,
  85. false
  86. ),
  87. /**
  88. * Testing when job is still running
  89. */
  90. array(
  91. true,
  92. true,
  93. 5,
  94. 10,
  95. true,
  96. true,
  97. 5,
  98. 10,
  99. 0.5,
  100. false
  101. ),
  102. /**
  103. * Testing when job is already finished
  104. */
  105. array(
  106. true,
  107. false,
  108. 10,
  109. 10,
  110. true,
  111. false,
  112. 10,
  113. 10,
  114. 1,
  115. true
  116. ),
  117. );
  118. }
  119. }