mirror of
https://github.com/filegator/filegator.git
synced 2025-01-18 05:08:54 +01:00
refactoring
This commit is contained in:
parent
fa319eda36
commit
b945526c85
@ -12,7 +12,6 @@ before_script:
|
||||
|
||||
script:
|
||||
- vendor/bin/phpunit --coverage-clover=coverage.xml
|
||||
- composer phpstan
|
||||
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
|
@ -65,7 +65,7 @@ Once everything is ready visit: ```http://localhost:8080```
|
||||
### Run tests & static analysis
|
||||
```
|
||||
vendor/bin/phpunit
|
||||
composer phpstan
|
||||
vendor/bin/phpstan analyse ./backend --level=x
|
||||
```
|
||||
|
||||
### Deployment
|
||||
|
@ -67,10 +67,6 @@ class AuthController
|
||||
return $response->json($errors->firstOfAll(), 422);
|
||||
}
|
||||
|
||||
if ($auth->user() === null) {
|
||||
return $response->json(['oldpassword' => 'Wrong password'], 422);
|
||||
}
|
||||
|
||||
if (! $auth->authenticate($auth->user()->getUsername(), $request->input('oldpassword'))) {
|
||||
return $response->json(['oldpassword' => 'Wrong password'], 422);
|
||||
}
|
||||
|
@ -40,25 +40,21 @@ class SessionStorage implements Service, SessionStorageInterface
|
||||
|
||||
public function save()
|
||||
{
|
||||
return $this->getSession() !== null ? $this->getSession()->save() : false;
|
||||
$this->getSession()->save();
|
||||
}
|
||||
|
||||
public function set(string $key, $data)
|
||||
{
|
||||
return $this->getSession() !== null ? $this->getSession()->set($key, $data) : false;
|
||||
return $this->getSession()->set($key, $data);
|
||||
}
|
||||
|
||||
public function get(string $key, $default = null)
|
||||
{
|
||||
return $this->getSession() !== null ? $this->getSession()->get($key, $default) : $default;
|
||||
return $this->getSession() ? $this->getSession()->get($key, $default) : $default;
|
||||
}
|
||||
|
||||
public function invalidate()
|
||||
{
|
||||
if ($this->getSession() === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $this->getSession()->isStarted()) {
|
||||
$this->getSession()->start();
|
||||
}
|
||||
|
@ -36,8 +36,5 @@
|
||||
"symfony/var-dumper": "^4.2",
|
||||
"league/flysystem-memory": "^1.0",
|
||||
"phpstan/phpstan": "^0.11.8"
|
||||
},
|
||||
"scripts": {
|
||||
"phpstan": "phpstan analyse ./backend --level=7"
|
||||
}
|
||||
}
|
||||
|
@ -10,15 +10,29 @@
|
||||
|
||||
namespace Tests\Unit\Auth;
|
||||
|
||||
use Filegator\Kernel\Request;
|
||||
use Filegator\Services\Auth\User;
|
||||
use Filegator\Services\Session\Adapters\SessionStorage;
|
||||
use Tests\TestCase;
|
||||
|
||||
abstract class AuthTest extends TestCase
|
||||
{
|
||||
public $auth;
|
||||
|
||||
protected $session;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->session = new SessionStorage(new Request());
|
||||
$this->session->init([
|
||||
'session_handler' => 'mockfilesession',
|
||||
'available' => [
|
||||
'mockfilesession' => function () {
|
||||
return new \Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage();
|
||||
},
|
||||
],
|
||||
]);
|
||||
|
||||
$this->setAuth();
|
||||
|
||||
parent::setUp();
|
||||
|
@ -10,9 +10,7 @@
|
||||
|
||||
namespace Tests\Unit\Auth;
|
||||
|
||||
use Filegator\Kernel\Request;
|
||||
use Filegator\Services\Auth\Adapters\Database;
|
||||
use Filegator\Services\Session\Adapters\SessionStorage;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@ -23,17 +21,7 @@ class DatabaseAuthTest extends AuthTest
|
||||
|
||||
public function setAuth()
|
||||
{
|
||||
$session = new SessionStorage(new Request());
|
||||
$session->init([
|
||||
'session_handler' => 'mockfilesession',
|
||||
'available' => [
|
||||
'mockfilesession' => function () {
|
||||
return new \Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage();
|
||||
},
|
||||
],
|
||||
]);
|
||||
|
||||
$this->auth = new Database($session);
|
||||
$this->auth = new Database($this->session);
|
||||
$this->auth->init([
|
||||
'driver' => 'pdo',
|
||||
'dsn' => 'sqlite::memory:',
|
||||
|
@ -10,9 +10,7 @@
|
||||
|
||||
namespace Tests\Unit\Auth;
|
||||
|
||||
use Filegator\Kernel\Request;
|
||||
use Filegator\Services\Auth\Adapters\JsonFile;
|
||||
use Filegator\Services\Session\Adapters\SessionStorage;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@ -32,17 +30,7 @@ class JsonFileTest extends AuthTest
|
||||
@unlink($this->mock_file);
|
||||
@touch($this->mock_file.'.blank');
|
||||
|
||||
$session = new SessionStorage(new Request());
|
||||
$session->init([
|
||||
'session_handler' => 'mockfilesession',
|
||||
'available' => [
|
||||
'mockfilesession' => function () {
|
||||
return new \Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage();
|
||||
},
|
||||
],
|
||||
]);
|
||||
|
||||
$this->auth = new JsonFile($session);
|
||||
$this->auth = new JsonFile($this->session);
|
||||
$this->auth->init([
|
||||
'file' => $this->mock_file,
|
||||
]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user