2019-07-01 09:07:33 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Tests\unit\app;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Filesystem\Filesystem;
|
|
|
|
|
use Illuminate\Support\Facades\File;
|
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
|
|
class CustomizeFormatterTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
private static $directory;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This is executed for each test.
|
|
|
|
|
*/
|
2022-06-09 11:43:56 -04:00
|
|
|
protected function setUp(): void
|
2019-07-01 09:07:33 -04:00
|
|
|
{
|
2019-08-08 09:51:39 -04:00
|
|
|
parent::setUp();
|
2019-10-04 09:45:06 -04:00
|
|
|
self::$directory = PATH_DATA . 'logs/';
|
2019-07-01 09:07:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This is done before the first test.
|
|
|
|
|
*/
|
2022-06-09 11:43:56 -04:00
|
|
|
public static function setUpBeforeClass(): void
|
2019-07-01 09:07:33 -04:00
|
|
|
{
|
|
|
|
|
$file = new Filesystem();
|
|
|
|
|
$file->cleanDirectory(self::$directory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This is done after the last test.
|
|
|
|
|
*/
|
2022-06-09 11:43:56 -04:00
|
|
|
public static function tearDownAfterClass(): void
|
2019-07-01 09:07:33 -04:00
|
|
|
{
|
|
|
|
|
$file = new Filesystem();
|
|
|
|
|
$file->cleanDirectory(self::$directory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return all of the log levels defined in the RFC 5424 specification.
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function levelProviders()
|
|
|
|
|
{
|
|
|
|
|
return [
|
2020-08-10 17:11:55 -04:00
|
|
|
['emergency', 'EMERGENCY'],
|
|
|
|
|
['alert', 'ALERT'],
|
|
|
|
|
['critical', 'CRITICAL'],
|
|
|
|
|
['error', 'ERROR'],
|
|
|
|
|
['warning', 'WARNING'],
|
|
|
|
|
['notice', 'NOTICE'],
|
|
|
|
|
['info', 'INFO'],
|
|
|
|
|
['debug', 'DEBUG'],
|
2019-07-01 09:07:33 -04:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This check the creation of a record with the emergency level.
|
|
|
|
|
* @test
|
|
|
|
|
* @dataProvider levelProviders
|
|
|
|
|
*/
|
|
|
|
|
public function it_should_create_log_file_levels($level, $message)
|
|
|
|
|
{
|
|
|
|
|
Log::{$level}($level);
|
|
|
|
|
$files = File::allFiles(self::$directory);
|
|
|
|
|
$this->assertCount(1, $files);
|
|
|
|
|
|
|
|
|
|
$string = File::get($files[0]);
|
2022-07-21 00:04:21 -04:00
|
|
|
$this->assertMatchesRegularExpression("/{$message}/", $string);
|
2019-07-01 09:07:33 -04:00
|
|
|
}
|
|
|
|
|
}
|