|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Onlime\LaravelSqlReporter\Tests; |
| 4 | + |
| 5 | +use Illuminate\Contracts\Config\Repository; |
| 6 | +use Onlime\LaravelSqlReporter\Config; |
| 7 | +use Mockery; |
| 8 | + |
| 9 | +class ConfigTest extends UnitTestCase |
| 10 | +{ |
| 11 | + /** |
| 12 | + * @var Repository|\Mockery\Mock |
| 13 | + */ |
| 14 | + protected $repository; |
| 15 | + |
| 16 | + /** |
| 17 | + * @var Config|\Mockery\Mock |
| 18 | + */ |
| 19 | + protected $config; |
| 20 | + |
| 21 | + protected function setUp(): void |
| 22 | + { |
| 23 | + $this->repository = Mockery::mock(Repository::class); |
| 24 | + $this->config = new Config($this->repository); |
| 25 | + } |
| 26 | + |
| 27 | + /** @test */ |
| 28 | + public function it_returns_valid_values_for_queriesEnabled() |
| 29 | + { |
| 30 | + $this->repository->shouldReceive('get')->once()->with('sql-reporter.queries.enabled') |
| 31 | + ->andReturn(1); |
| 32 | + $this->assertTrue($this->config->queriesEnabled()); |
| 33 | + |
| 34 | + $this->repository->shouldReceive('get')->once()->with('sql-reporter.queries.enabled') |
| 35 | + ->andReturn(0); |
| 36 | + $this->assertFalse($this->config->queriesEnabled()); |
| 37 | + } |
| 38 | + |
| 39 | + /** @test */ |
| 40 | + public function it_returns_valid_value_for_slowLogTime() |
| 41 | + { |
| 42 | + $value = 700.0; |
| 43 | + $this->repository->shouldReceive('get')->once()->with('sql-reporter.queries.min_exec_time') |
| 44 | + ->andReturn($value); |
| 45 | + $this->assertSame($value, $this->config->queriesMinExecTime()); |
| 46 | + } |
| 47 | + |
| 48 | + /** @test */ |
| 49 | + public function it_returns_valid_values_for_queriesOverrideLog() |
| 50 | + { |
| 51 | + $this->repository->shouldReceive('get')->once()->with('sql-reporter.queries.override_log') |
| 52 | + ->andReturn(1); |
| 53 | + $this->assertTrue($this->config->queriesOverrideLog()); |
| 54 | + |
| 55 | + $this->repository->shouldReceive('get')->once()->with('sql-reporter.queries.override_log') |
| 56 | + ->andReturn(0); |
| 57 | + $this->assertFalse($this->config->queriesOverrideLog()); |
| 58 | + } |
| 59 | + |
| 60 | + /** @test */ |
| 61 | + public function it_returns_valid_value_for_logDirectory() |
| 62 | + { |
| 63 | + $value = 'sample directory'; |
| 64 | + $this->repository->shouldReceive('get')->once()->with('sql-reporter.general.directory') |
| 65 | + ->andReturn($value); |
| 66 | + $this->assertSame($value, $this->config->logDirectory()); |
| 67 | + } |
| 68 | + |
| 69 | + /** @test */ |
| 70 | + public function it_returns_valid_values_for_useSeconds() |
| 71 | + { |
| 72 | + $this->repository->shouldReceive('get')->once()->with('sql-reporter.general.use_seconds') |
| 73 | + ->andReturn(1); |
| 74 | + $this->assertTrue($this->config->useSeconds()); |
| 75 | + |
| 76 | + $this->repository->shouldReceive('get')->once()->with('sql-reporter.general.use_seconds') |
| 77 | + ->andReturn(0); |
| 78 | + $this->assertFalse($this->config->useSeconds()); |
| 79 | + } |
| 80 | + |
| 81 | + /** @test */ |
| 82 | + public function it_returns_valid_values_for_consoleSuffix() |
| 83 | + { |
| 84 | + $this->repository->shouldReceive('get')->once()->with('sql-reporter.general.console_log_suffix') |
| 85 | + ->andReturn('-artisan'); |
| 86 | + $this->assertSame('-artisan', $this->config->consoleSuffix()); |
| 87 | + |
| 88 | + $this->repository->shouldReceive('get')->once()->with('sql-reporter.general.console_log_suffix') |
| 89 | + ->andReturn(''); |
| 90 | + $this->assertSame('', $this->config->consoleSuffix()); |
| 91 | + } |
| 92 | + |
| 93 | + /** @test */ |
| 94 | + public function it_returns_valid_value_for_queriesPattern() |
| 95 | + { |
| 96 | + $value = 'sample pattern'; |
| 97 | + $this->repository->shouldReceive('get')->once()->with('sql-reporter.queries.pattern') |
| 98 | + ->andReturn($value); |
| 99 | + $this->assertSame($value, $this->config->queriesPattern()); |
| 100 | + } |
| 101 | + |
| 102 | + /** @test */ |
| 103 | + public function it_returns_valid_file_extension() |
| 104 | + { |
| 105 | + $value = '.sql'; |
| 106 | + $this->repository->shouldReceive('get')->once()->with('sql-reporter.general.extension') |
| 107 | + ->andReturn($value); |
| 108 | + $this->assertSame($value, $this->config->fileExtension()); |
| 109 | + } |
| 110 | + |
| 111 | + /** @test */ |
| 112 | + public function it_returns_valid_queries_file_name() |
| 113 | + { |
| 114 | + $value = '[Y-m-d]-sample'; |
| 115 | + $this->repository->shouldReceive('get')->once()->with('sql-reporter.queries.file_name') |
| 116 | + ->andReturn($value); |
| 117 | + $this->assertSame($value, $this->config->queriesFileName()); |
| 118 | + } |
| 119 | + |
| 120 | + /** @test */ |
| 121 | + public function it_returns_valid_value_for_entryFormat() |
| 122 | + { |
| 123 | + $this->repository->shouldReceive('get')->once()->with('sql-reporter.formatting.entry_format') |
| 124 | + ->andReturn('[sample]/[example]/foo'); |
| 125 | + $this->assertSame('[sample]/[example]/foo', $this->config->entryFormat()); |
| 126 | + } |
| 127 | +} |
0 commit comments