Skip to content

Instantly share code, notes, and snippets.

@scrubmx
Created September 1, 2017 19:17
Show Gist options
  • Select an option

  • Save scrubmx/315458fe19e749b7317f26280d0b0037 to your computer and use it in GitHub Desktop.

Select an option

Save scrubmx/315458fe19e749b7317f26280d0b0037 to your computer and use it in GitHub Desktop.
Use a stub log driver in your laravel tests
<?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