JobDispatchingTest.php 1015 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Illuminate\Tests\Integration\Queue;
  3. use Illuminate\Bus\Queueable;
  4. use Illuminate\Contracts\Queue\ShouldQueue;
  5. use Illuminate\Foundation\Bus\Dispatchable;
  6. use Orchestra\Testbench\TestCase;
  7. class JobDispatchingTest extends TestCase
  8. {
  9. protected function tearDown(): void
  10. {
  11. Job::$ran = false;
  12. }
  13. public function testJobCanUseCustomMethodsAfterDispatch()
  14. {
  15. Job::dispatch('test')->replaceValue('new-test');
  16. $this->assertTrue(Job::$ran);
  17. $this->assertSame('new-test', Job::$value);
  18. }
  19. }
  20. class Job implements ShouldQueue
  21. {
  22. use Dispatchable, Queueable;
  23. public static $ran = false;
  24. public static $usedQueue = null;
  25. public static $usedConnection = null;
  26. public static $value = null;
  27. public function __construct($value)
  28. {
  29. static::$value = $value;
  30. }
  31. public function handle()
  32. {
  33. static::$ran = true;
  34. }
  35. public function replaceValue($value)
  36. {
  37. static::$value = $value;
  38. }
  39. }