Skip to content

Commit

Permalink
Fix publish views location (#19)
Browse files Browse the repository at this point in the history
* Fix publish views location
* Add tests
  • Loading branch information
GeoSot authored Jan 21, 2022
1 parent 9ae2c0b commit 0ad91b8
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 22 deletions.
7 changes: 5 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
processIsolation="false"
stopOnFailure="true">
<testsuites>
<testsuite name="Env Editor Suite">
<directory suffix="Test.php">./tests/</directory>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<coverage>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public function register()
private function loadResources(): void
{
$this->loadRoutesFrom(__DIR__.'/routes.php');
$this->loadViewsFrom(__DIR__.'/resources/views', $this->package);
$this->loadTranslationsFrom(__DIR__.'/resources/lang', $this->package);
$this->loadViewsFrom(__DIR__.'/../resources/views', $this->package);
$this->loadTranslationsFrom(__DIR__.'/../resources/lang', $this->package);
}

private function publishResources(): void
Expand All @@ -73,11 +73,11 @@ private function publishResources(): void
], 'config');

$this->publishes([
__DIR__.'/resources/views/' => resource_path("views/vendor/{$this->vendor}/{$this->package}"),
__DIR__.'/../resources/views' => resource_path("/views/vendor/{$this->package}"),
], 'views');

$this->publishes([
__DIR__.'/resources/lang/' => resource_path("lang/vendor/{$this->vendor}"),
__DIR__.'/../resources/lang/' => resource_path("lang/vendor/{$this->package}"),
], 'translations');
}
}
54 changes: 54 additions & 0 deletions tests/Feature/UiTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

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
{
/**
* @test
*/
public function can_see_dashboard(): void
{
$response = $this->get($this->makeRoute('index'));
$response->assertStatus(200)
->assertSee(trans('env-editor::env-editor.menuTitle'));
}

/**
* @test
*/
public function can_see_backups(): void
{
$response = $this->get($this->makeRoute('getBackups'));
$response->assertStatus(200)
->assertSee(trans('env-editor::env-editor.views.backup.title'));
}

/**
* @test
*/
public function can_download(): void
{
EnvEditor::shouldReceive('getFilePath')->once()->with('fooBar')->andReturns(self::getTestFile(true));
$response = $this->get($this->makeRoute('download', ['filename' => 'fooBar']));
$response->assertStatus(200);
$response->assertDownload(self::getTestFile());
}


/**
* @param string $route
* @param array<string, string> $parameters
* @return string
*/
protected function makeRoute(string $route, array $parameters = []): string
{
return route(config('env-editor.route.name').'.'.$route, $parameters);
}
}
35 changes: 20 additions & 15 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,23 @@

use GeoSot\EnvEditor\Facades\EnvEditor;
use GeoSot\EnvEditor\ServiceProvider;
use Illuminate\Encryption\Encrypter;
use Orchestra\Testbench\TestCase as OrchestraTestCase;

/**
* Class TestCase.
*/
class TestCase extends OrchestraTestCase

abstract class TestCase extends OrchestraTestCase
{
private $tempDir;

/**
* @inheritdoc
*/
protected function getEnvironmentSetUp($app)
{
// set up database configuration
$app['config']->set('database.default', 'testbench');
$app['config']->set('database.connections.testbench', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);
$key = 'base64:'.base64_encode(
Encrypter::generateKey('AES-256-CBC')
);

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


/**
* @inheritdoc
*/
Expand All @@ -46,4 +40,15 @@ protected function getPackageAliases($app)
'env-editor' => EnvEditor::class,
];
}

protected static function getTestPath(): string
{
return realpath(__DIR__.'/fixtures');
}

protected static function getTestFile(bool $fullPath = false): string
{
$file = '.env.example';
return $fullPath ? static::getTestPath().DIRECTORY_SEPARATOR.$file : $file;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

namespace GeoSot\EnvEditor\Tests;
namespace GeoSot\EnvEditor\Tests\Unit;

use GeoSot\EnvEditor\EnvEditor;
use GeoSot\EnvEditor\Helpers\EnvFilesManager;
use GeoSot\EnvEditor\Tests\TestCase;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Arr;

Expand Down
16 changes: 16 additions & 0 deletions tests/fixtures/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
APP_NAME="Test env"
APP_ENV=local
APP_URL=https://example.test

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306


BROADCAST_DRIVER=
CACHE_DRIVER="file"
FILESYSTEM_DRIVER=local

0 comments on commit 0ad91b8

Please sign in to comment.