BatchRepositoryFake.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace Illuminate\Support\Testing\Fakes;
  3. use Carbon\CarbonImmutable;
  4. use Closure;
  5. use Illuminate\Bus\Batch;
  6. use Illuminate\Bus\BatchRepository;
  7. use Illuminate\Bus\PendingBatch;
  8. use Illuminate\Bus\UpdatedBatchJobCounts;
  9. use Illuminate\Support\Facades\Facade;
  10. use Illuminate\Support\Str;
  11. class BatchRepositoryFake implements BatchRepository
  12. {
  13. /**
  14. * Retrieve a list of batches.
  15. *
  16. * @param int $limit
  17. * @param mixed $before
  18. * @return \Illuminate\Bus\Batch[]
  19. */
  20. public function get($limit, $before)
  21. {
  22. return [];
  23. }
  24. /**
  25. * Retrieve information about an existing batch.
  26. *
  27. * @param string $batchId
  28. * @return \Illuminate\Bus\Batch|null
  29. */
  30. public function find(string $batchId)
  31. {
  32. //
  33. }
  34. /**
  35. * Store a new pending batch.
  36. *
  37. * @param \Illuminate\Bus\PendingBatch $batch
  38. * @return \Illuminate\Bus\Batch
  39. */
  40. public function store(PendingBatch $batch)
  41. {
  42. return new Batch(
  43. new QueueFake(Facade::getFacadeApplication()),
  44. $this,
  45. (string) Str::orderedUuid(),
  46. $batch->name,
  47. count($batch->jobs),
  48. count($batch->jobs),
  49. 0,
  50. [],
  51. $batch->options,
  52. CarbonImmutable::now(),
  53. null,
  54. null
  55. );
  56. }
  57. /**
  58. * Increment the total number of jobs within the batch.
  59. *
  60. * @param string $batchId
  61. * @param int $amount
  62. * @return void
  63. */
  64. public function incrementTotalJobs(string $batchId, int $amount)
  65. {
  66. //
  67. }
  68. /**
  69. * Decrement the total number of pending jobs for the batch.
  70. *
  71. * @param string $batchId
  72. * @param string $jobId
  73. * @return \Illuminate\Bus\UpdatedBatchJobCounts
  74. */
  75. public function decrementPendingJobs(string $batchId, string $jobId)
  76. {
  77. return new UpdatedBatchJobCounts;
  78. }
  79. /**
  80. * Increment the total number of failed jobs for the batch.
  81. *
  82. * @param string $batchId
  83. * @param string $jobId
  84. * @return \Illuminate\Bus\UpdatedBatchJobCounts
  85. */
  86. public function incrementFailedJobs(string $batchId, string $jobId)
  87. {
  88. return new UpdatedBatchJobCounts;
  89. }
  90. /**
  91. * Mark the batch that has the given ID as finished.
  92. *
  93. * @param string $batchId
  94. * @return void
  95. */
  96. public function markAsFinished(string $batchId)
  97. {
  98. //
  99. }
  100. /**
  101. * Cancel the batch that has the given ID.
  102. *
  103. * @param string $batchId
  104. * @return void
  105. */
  106. public function cancel(string $batchId)
  107. {
  108. //
  109. }
  110. /**
  111. * Delete the batch that has the given ID.
  112. *
  113. * @param string $batchId
  114. * @return void
  115. */
  116. public function delete(string $batchId)
  117. {
  118. //
  119. }
  120. /**
  121. * Execute the given Closure within a storage specific transaction.
  122. *
  123. * @param \Closure $callback
  124. * @return mixed
  125. */
  126. public function transaction(Closure $callback)
  127. {
  128. return $callback();
  129. }
  130. }