InteractsWithContainerTest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Illuminate\Tests\Foundation\Bootstrap\Testing\Concerns;
  3. use Illuminate\Foundation\Mix;
  4. use Orchestra\Testbench\TestCase;
  5. use stdClass;
  6. class InteractsWithContainerTest extends TestCase
  7. {
  8. public function testWithoutMixBindsEmptyHandlerAndReturnsInstance()
  9. {
  10. $instance = $this->withoutMix();
  11. $this->assertSame('', mix('path/to/asset.png'));
  12. $this->assertSame($this, $instance);
  13. }
  14. public function testWithMixRestoresOriginalHandlerAndReturnsInstance()
  15. {
  16. $handler = new stdClass;
  17. $this->app->instance(Mix::class, $handler);
  18. $this->withoutMix();
  19. $instance = $this->withMix();
  20. $this->assertSame($handler, resolve(Mix::class));
  21. $this->assertSame($this, $instance);
  22. }
  23. public function testForgetMock()
  24. {
  25. $this->mock(IntanceStub::class)
  26. ->shouldReceive('execute')
  27. ->once()
  28. ->andReturn('bar');
  29. $this->assertSame('bar', $this->app->make(IntanceStub::class)->execute());
  30. $this->forgetMock(IntanceStub::class);
  31. $this->assertSame('foo', $this->app->make(IntanceStub::class)->execute());
  32. }
  33. }
  34. class IntanceStub
  35. {
  36. public function execute()
  37. {
  38. return 'foo';
  39. }
  40. }