BusBatchableTest.php 964 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace Illuminate\Tests\Bus;
  3. use Illuminate\Bus\Batchable;
  4. use Illuminate\Bus\BatchRepository;
  5. use Illuminate\Container\Container;
  6. use Mockery as m;
  7. use PHPUnit\Framework\TestCase;
  8. class BusBatchableTest extends TestCase
  9. {
  10. protected function tearDown(): void
  11. {
  12. m::close();
  13. }
  14. public function test_batch_may_be_retrieved()
  15. {
  16. $class = new class
  17. {
  18. use Batchable;
  19. };
  20. $this->assertSame($class, $class->withBatchId('test-batch-id'));
  21. $this->assertSame('test-batch-id', $class->batchId);
  22. Container::setInstance($container = new Container);
  23. $repository = m::mock(BatchRepository::class);
  24. $repository->shouldReceive('find')->once()->with('test-batch-id')->andReturn('test-batch');
  25. $container->instance(BatchRepository::class, $repository);
  26. $this->assertSame('test-batch', $class->batch());
  27. Container::setInstance(null);
  28. }
  29. }