Created
September 1, 2017 19:17
-
-
Save scrubmx/315458fe19e749b7317f26280d0b0037 to your computer and use it in GitHub Desktop.
Use a stub log driver in your laravel tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace Tests; | |
| use Illuminate\Foundation\Application; | |
| use Illuminate\Contracts\Console\Kernel; | |
| trait CreatesApplication | |
| { | |
| /** | |
| * @var \Illuminate\Log\Writer | |
| */ | |
| protected $logWriter; | |
| public function createApplication() | |
| { | |
| // ... | |
| $this->disableLogWriter($app); | |
| return $app; | |
| } | |
| public function withLogWriter() | |
| { | |
| $this->app['log'] = $this->logWriter; | |
| } | |
| public function withoutLogWriter() | |
| { | |
| $this->app['log'] = new class { | |
| public function __call($method, $arguments) | |
| { | |
| // | |
| } | |
| }; | |
| } | |
| protected function disableLogWriter(Application &$app) | |
| { | |
| $this->logWriter = $this->logWriter ?? $app['log']; | |
| $app['log'] = new class { | |
| public function __call($method, $arguments) | |
| { | |
| // | |
| } | |
| }; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment