maestriam /
samurai
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Maestriam\Samurai\Tests\Unit\Foundation\EnvHandler; |
||
| 4 | |||
| 5 | use Maestriam\Samurai\Tests\TestCase; |
||
| 6 | use Maestriam\Samurai\Foundation\EnvHandler; |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Testes de funcionalidades básicas apresentadas no README.md |
||
| 10 | */ |
||
| 11 | class EnvHandlerTestCase extends TestCase |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * Instancia a classe de validação para ser testada |
||
| 15 | * |
||
| 16 | * @return void |
||
| 17 | */ |
||
| 18 | public function setUp() : void |
||
| 19 | { |
||
| 20 | parent::setUp(); |
||
| 21 | } |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Verifica se consegue definir um valor no arquivo de configurações |
||
| 25 | * de ambiente do projeto Laravel |
||
| 26 | * |
||
| 27 | * @return void |
||
| 28 | */ |
||
| 29 | public function testGetAndSetEnvVariable() |
||
| 30 | { |
||
| 31 | $key = 'THEME_CURRENT'; |
||
| 32 | $val = 'bands/kix'; |
||
| 33 | |||
| 34 | $handler = new EnvHandler(); |
||
| 35 | $handler->set($key, $val); |
||
| 36 | |||
| 37 | $this->assertIsString($handler->get($key)); |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Verifica se consegue criar um novo arquivo de configurações |
||
| 42 | * se caso não exista no projeto. |
||
| 43 | * Por padrão, sempre deve ser criado na raíz do projeto (base_path()) |
||
| 44 | * |
||
| 45 | * @return void |
||
| 46 | */ |
||
| 47 | public function testIfCanCreateEnvFile() |
||
| 48 | { |
||
| 49 | $filename = config('samurai.env_file'); |
||
| 50 | $filepath = base_path($filename); |
||
| 51 | |||
| 52 | if (file_exists($filepath)) { |
||
| 53 | unlink($filepath); |
||
| 54 | } |
||
| 55 | |||
| 56 | $handler = new EnvHandler(); |
||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 57 | |||
| 58 | $this->assertFileExists($filepath); |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Verifica se consegue criar um novo arquivo de configuração, |
||
| 63 | * caso não tenha um nome definido na configuração do pacote. |
||
| 64 | * Por padrão, o nome sempre será .env e ficará na raíz do projeto |
||
| 65 | * |
||
| 66 | * @return void |
||
| 67 | */ |
||
| 68 | public function testIfCanCreateEnvFileWithDefaultName() |
||
| 69 | { |
||
| 70 | config(['samurai.env_file' => null]); |
||
| 71 | |||
| 72 | $handler = new EnvHandler(); |
||
| 73 | |||
| 74 | $this->assertFileExists($handler->file()); |
||
| 75 | } |
||
| 76 | |||
| 77 | public function tearDown(): void |
||
| 78 | { |
||
| 79 | $handler = new EnvHandler(); |
||
| 80 | |||
| 81 | $handler->set('THEME_CURRENT', ''); |
||
| 82 | } |
||
| 83 | } |
||
| 84 |