Skip to content

Commit

Permalink
Add test directories to code quality inspections, change eol
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoSot committed Jan 25, 2022
1 parent b2fedd4 commit d519594
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 28 deletions.
2 changes: 1 addition & 1 deletion ruleset-php_cs.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
__DIR__.'/database',
__DIR__.'/resources',
__DIR__.'/routes',
// __DIR__.'/tests'
__DIR__.'/tests'
];

$finder = Finder::create()
Expand Down
1 change: 1 addition & 0 deletions ruleset-phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ includes:
parameters:
paths:
- src
- tests
# The level 8 is the highest level
level: 6
reportStaticMethodSignatures: true
Expand Down
4 changes: 0 additions & 4 deletions tests/Feature/UiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

namespace GeoSot\EnvEditor\Tests\Feature;


use GeoSot\EnvEditor\Facades\EnvEditor;
use GeoSot\EnvEditor\Tests\TestCase;
use Illuminate\Config\Repository;
use Illuminate\Filesystem\Filesystem;

class UiTest extends TestCase
{
Expand Down Expand Up @@ -41,7 +38,6 @@ public function can_download(): void
$response->assertDownload(self::getTestFile());
}


/**
* @param string $route
* @param array<string, string> $parameters
Expand Down
8 changes: 3 additions & 5 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,17 @@
use Illuminate\Encryption\Encrypter;
use Orchestra\Testbench\TestCase as OrchestraTestCase;


abstract class TestCase extends OrchestraTestCase
{

protected function getEnvironmentSetUp($app)
{
$key = 'base64:'.base64_encode(
Encrypter::generateKey('AES-256-CBC')
);
Encrypter::generateKey('AES-256-CBC')
);

$app['config']->set('app.key', $key);
}


/**
* @inheritdoc
*/
Expand Down Expand Up @@ -49,6 +46,7 @@ protected static function getTestPath(): string
protected static function getTestFile(bool $fullPath = false): string
{
$file = '.env.example';

return $fullPath ? static::getTestPath().DIRECTORY_SEPARATOR.$file : $file;
}
}
11 changes: 5 additions & 6 deletions tests/Unit/Helpers/EnvKeysManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

class EnvKeysManagerTest extends TestCase
{

protected function setUp(): void
{
parent::setUp(); // TODO: Change the autogenerated stub
Expand Down Expand Up @@ -61,7 +60,6 @@ public function deletes_keys(): void
self::assertTrue($this->getEnvKeysManager()->deleteKey('CACHE_DRIVER'));
self::assertStringNotContainsString('CACHE_DRIVER="file"', file_get_contents($fullPath));


self::assertStringNotContainsString('CACHE_DRIVER', file_get_contents($fullPath));
try {
$this->getEnvKeysManager()->deleteKey('CACHE_DRIVER');
Expand All @@ -80,7 +78,6 @@ public function edits_keys(): void
$fullPath = $this->createNewDummyFile($fileName);
$this->app['config']->set('env-editor.envFileName', $fileName);


self::assertStringContainsString('LOG_CHANNEL=stack', file_get_contents($fullPath));
self::assertTrue($this->getEnvKeysManager()->editKey('LOG_CHANNEL', 'foo'));
self::assertStringContainsString('LOG_CHANNEL=foo', file_get_contents($fullPath));
Expand All @@ -95,7 +92,6 @@ public function edits_keys(): void
self::assertTrue($this->getEnvKeysManager()->editKey('CACHE_DRIVER', null));
self::assertStringContainsString('CACHE_DRIVER=', file_get_contents($fullPath));


self::assertStringNotContainsString('WRONG_KEY', file_get_contents($fullPath));
try {
$this->getEnvKeysManager()->editKey('WRONG_KEY', 'fail');
Expand All @@ -105,7 +101,10 @@ public function edits_keys(): void
}
}


/**
* @param array<string, mixed> $config
* @return EnvKeysManager
*/
protected function getEnvKeysManager(array $config = []): EnvKeysManager
{
$envEditor = new EnvEditor(
Expand All @@ -115,6 +114,7 @@ protected function getEnvKeysManager(array $config = []): EnvKeysManager
$this->app->singleton(EnvEditor::class, function () use ($envEditor) {
return $envEditor;
});

return $envEditor->getKeysManager();
}

Expand All @@ -126,5 +126,4 @@ protected function createNewDummyFile(string $name = 'test.tmp'): string

return $dummyFullPath;
}

}
26 changes: 14 additions & 12 deletions tests/Unit/Helpers/FilesManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected function tearDown(): void
* @test
* Test makeBackupsDirectory method
*/
public function constructor_calls_makeBackupsDirectory_method()
public function constructor_calls_makeBackupsDirectory_method(): void
{
$classname = EnvFilesManager::class;

Expand All @@ -51,7 +51,7 @@ public function constructor_calls_makeBackupsDirectory_method()
* @test
* Test makeBackupsDirectory method
*/
public function backupDir_is_created()
public function backupDir_is_created(): void
{
$path = $this->getEnvFilesManager()->getBackupsDir();
$this->createAndTestPath($path);
Expand All @@ -61,7 +61,7 @@ public function backupDir_is_created()
* @test
* Test makeBackupsDirectory method
*/
public function getEnvDir_exists()
public function getEnvDir_exists(): void
{
$path = $this->getEnvFilesManager()->getEnvDir();
$this->createAndTestPath($path);
Expand All @@ -70,7 +70,7 @@ public function getEnvDir_exists()
/**
* @test
*/
public function getBackupsDir_can_return_file()
public function getBackupsDir_can_return_file(): void
{
$path = $this->getEnvFilesManager()->getBackupsDir();
$filename = 'test.tmp';
Expand All @@ -85,7 +85,7 @@ public function getBackupsDir_can_return_file()
/**
* @test
*/
public function getEnvDir_can_return_file()
public function getEnvDir_can_return_file(): void
{
$path = $this->getEnvFilesManager()->getEnvDir();
$filename = 'test.tmp';
Expand All @@ -100,7 +100,7 @@ public function getEnvDir_can_return_file()
/**
* @test
*/
public function getAllBackUps_returns_all_files()
public function getAllBackUps_returns_all_files(): void
{
$manager = $this->getEnvFilesManager();
$file1 = $manager->getBackupsDir('test.tmp');
Expand All @@ -118,7 +118,7 @@ public function getAllBackUps_returns_all_files()
/**
* @test
*/
public function backUpCurrentEnv_works_and_returns_bool()
public function backUpCurrentEnv_works_and_returns_bool(): void
{
$fileName = 'test.tmp';
$this->app['config']->set('env-editor.envFileName', $fileName);
Expand Down Expand Up @@ -147,7 +147,7 @@ public function backUpCurrentEnv_works_and_returns_bool()
/**
* @test
*/
public function restoreBackup_works_and_returns_bool()
public function restoreBackup_works_and_returns_bool(): void
{
$manager = $this->getEnvFilesManager();
//place a dummy env file
Expand All @@ -170,7 +170,7 @@ public function restoreBackup_works_and_returns_bool()
/**
* @test
*/
public function deleteBackup_works_and_returns_bool()
public function deleteBackup_works_and_returns_bool(): void
{
$fileName = time().'_test.tmp';
$manager = $this->getEnvFilesManager();
Expand All @@ -195,20 +195,22 @@ private function createAndTestPath(string $path): void
unlink($filename);
}

/**
* @return mixed
*/
private function cleanBackUpDir(): void
{
(new Filesystem())->cleanDirectory($this->getEnvFilesManager()->getBackupsDir());
}

/**
* @param array<string, mixed> $config
* @return EnvFilesManager
*/
protected function getEnvFilesManager(array $config = []): EnvFilesManager
{
$envEditor = new EnvEditor(
new Repository($config ?: $this->app['config']->get('env-editor')),
new Filesystem()
);

return $envEditor->getFilesManager();
}
}

0 comments on commit d519594

Please sign in to comment.