Laravel 5.8 (#5)

This commit is contained in:
Pig Fang 2019-02-27 23:44:50 +08:00 committed by GitHub
parent f26f3ccbde
commit e528547b89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 636 additions and 937 deletions

View File

@ -61,7 +61,7 @@ class AuthController extends Controller
return json(trans('auth.login.success'), 0);
} else {
// Increase the counter
Cache::put($loginFailsCacheKey, ++$loginFails, 60);
Cache::put($loginFailsCacheKey, ++$loginFails, 3600);
return json(trans('auth.validation.password'), 1, [
'login_fails' => $loginFails
@ -201,7 +201,7 @@ class AuthController extends Controller
return json(trans('auth.forgot.failed', ['msg' => $e->getMessage()]), 2);
}
Cache::put($lastMailCacheKey, time(), 60);
Cache::put($lastMailCacheKey, time(), 3600);
return json(trans('auth.forgot.success'), 0);
}

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use Exception;
use ZipArchive;
use Illuminate\Support\Arr;
use Illuminate\Http\Request;
use Composer\Semver\Comparator;
use App\Services\PluginManager;
@ -54,7 +55,7 @@ class MarketController extends Controller
$item['installed'] = false;
}
$requirements = array_get($item, 'require', []);
$requirements = Arr::get($item, 'require', []);
unset($item['require']);
$item['dependencies'] = [
@ -93,7 +94,7 @@ class MarketController extends Controller
// Gather plugin distribution URL
$url = $metadata['dist']['url'];
$filename = array_last(explode('/', $url));
$filename = Arr::last(explode('/', $url));
$plugins_dir = $manager->getPluginsDir();
$tmp_path = $plugins_dir.DIRECTORY_SEPARATOR.$filename;
@ -152,6 +153,6 @@ class MarketController extends Controller
$this->registryCache = json_decode($pluginsJson, true);
}
return array_get($this->registryCache, 'packages', []);
return Arr::get($this->registryCache, 'packages', []);
}
}

View File

@ -9,6 +9,7 @@ use Option;
use Storage;
use Exception;
use ZipArchive;
use Illuminate\Support\Arr;
use App\Services\OptionForm;
use Illuminate\Http\Request;
use Composer\Semver\Comparator;
@ -92,7 +93,7 @@ class UpdateController extends Controller
);
if ($detail = $this->getReleaseInfo($info['latest_version'])) {
$info = array_merge($info, array_only($detail, [
$info = array_merge($info, Arr::only($detail, [
'release_note',
'release_url',
'release_time',
@ -104,7 +105,7 @@ class UpdateController extends Controller
}
if (! $info['new_version_available']) {
$info['release_time'] = array_get($this->getReleaseInfo($this->currentVersion), 'release_time');
$info['release_time'] = Arr::get($this->getReleaseInfo($this->currentVersion), 'release_time');
}
}
@ -157,7 +158,7 @@ class UpdateController extends Controller
// Set temporary path for the update package
$tmp_path = $update_cache.'/update_'.time().'.zip';
Cache::put('tmp_path', $tmp_path, 60);
Cache::put('tmp_path', $tmp_path, 3600);
Log::info('[Update Wizard] Prepare to download update package', compact('release_url', 'tmp_path'));
// We won't get remote file size here since HTTP HEAD method is not always reliable
@ -184,7 +185,7 @@ class UpdateController extends Controller
if ($total == $downloaded || floor($downloaded / 102400) > floor($GLOBALS['last_downloaded'] / 102400)) {
$GLOBALS['last_downloaded'] = $downloaded;
Log::info('[Update Wizard] Download progress (in bytes):', [$total, $downloaded]);
Cache::put('download-progress', compact('total', 'downloaded'), 60);
Cache::put('download-progress', compact('total', 'downloaded'), 3600);
}
// @codeCoverageIgnoreEnd
}
@ -278,10 +279,10 @@ class UpdateController extends Controller
}
}
$this->latestVersion = array_get($this->updateInfo, 'latest_version', $this->currentVersion);
$this->latestVersion = Arr::get($this->updateInfo, 'latest_version', $this->currentVersion);
if (! is_null($key)) {
return array_get($this->updateInfo, $key);
return Arr::get($this->updateInfo, $key);
}
return $this->updateInfo;
@ -289,7 +290,7 @@ class UpdateController extends Controller
protected function getReleaseInfo($version)
{
return array_get($this->getUpdateInfo('releases'), $version);
return Arr::get($this->getUpdateInfo('releases'), $version);
}
}

View File

@ -2,6 +2,7 @@
namespace App\Http\Middleware;
use Illuminate\Support\Arr;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
@ -23,7 +24,7 @@ class DetectLanguagePrefer
$locale = $request->input('lang') ?: ($request->cookie('locale') ?: $request->getPreferredLanguage());
// If current locale is an alias of other locale
if (($info = array_get(config('locales'), $locale)) && ($alias = array_get($info, 'alias'))) {
if (($info = Arr::get(config('locales'), $locale)) && ($alias = Arr::get($info, 'alias'))) {
$locale = $alias;
}

View File

@ -221,7 +221,7 @@ class Player extends Model
// Support both CustomSkinLoader API & UniSkinAPI
if ($api_type == self::CSL_API || $api_type == self::USM_API) {
$responses = Event::fire(new GetPlayerJson($this, $api_type));
$responses = Event::dispatch(new GetPlayerJson($this, $api_type));
// If listeners return nothing
if (isset($responses[0]) && $responses[0] !== null) {

View File

@ -4,6 +4,7 @@ namespace App\Models;
use DB;
use Carbon\Carbon;
use Illuminate\Support\Arr;
use App\Events\EncryptUserPassword;
use Illuminate\Foundation\Auth\User as Authenticatable;
@ -101,7 +102,7 @@ class User extends Authenticatable
{
$responses = event(new EncryptUserPassword($rawPasswd, $user));
return array_get($responses, 0);
return Arr::get($responses, 0);
}
/**

View File

@ -8,6 +8,7 @@ use Event;
use App\Events;
use App\Models\User;
use ReflectionException;
use Illuminate\Support\Arr;
use Illuminate\Support\ServiceProvider;
use App\Exceptions\PrettyPageException;
use App\Services\Repositories\OptionRepository;
@ -24,9 +25,13 @@ class AppServiceProvider extends ServiceProvider
// Control the URL generated by url() function
$this->configureUrlGenerator();
Blade::if('admin', function (User $user) {
return $user->isAdmin();
});
Event::listen(Events\RenderingHeader::class, function($event) {
// Provide some application information for javascript
$blessing = array_merge(array_except(config('app'), ['key', 'providers', 'aliases', 'cipher', 'log', 'url']), [
$blessing = array_merge(Arr::except(config('app'), ['key', 'providers', 'aliases', 'cipher', 'log', 'url']), [
'base_url' => url('/'),
'site_name' => option_localized('site_name'),
'route' => request()->path(),
@ -53,10 +58,6 @@ class AppServiceProvider extends ServiceProvider
$this->app->singleton('users', \App\Services\Repositories\UserRepository::class);
$this->app->singleton('options', OptionRepository::class);
Blade::if('admin', function (User $user) {
return $user->isAdmin();
});
if ($this->app->environment() !== 'production') {
$this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
}

View File

@ -4,6 +4,7 @@ namespace App\Providers;
use Event;
use App\Events;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use App\Services\PluginManager;
use Illuminate\Support\ServiceProvider;
@ -75,7 +76,7 @@ class PluginServiceProvider extends ServiceProvider
if (file_exists($filename = $event->plugin->getPath()."/callbacks.php")) {
$callbacks = require $filename;
$callback = array_get($callbacks, get_class($event));
$callback = Arr::get($callbacks, get_class($event));
return $callback ? app()->call($callback, [$event->plugin]) : null;
}

View File

@ -634,7 +634,7 @@ class OptionFormGroup extends OptionFormItem
$rendered[] = view('common.option-form.'.$item['type'])->with([
'id' => $item['id'],
'value' => $item['value'],
'placeholder' => array_get($item, 'placeholder')
'placeholder' => Arr::get($item, 'placeholder')
]);
}

View File

@ -165,7 +165,7 @@ class PluginManager
$plugin->setEnabled(true);
$this->dispatcher->fire(new Events\PluginWasEnabled($plugin));
$this->dispatcher->dispatch(new Events\PluginWasEnabled($plugin));
}
}
@ -191,7 +191,7 @@ class PluginManager
$this->enabled = $rejected;
$this->saveEnabled();
$this->dispatcher->fire(new Events\PluginWasDisabled($plugin));
$this->dispatcher->dispatch(new Events\PluginWasDisabled($plugin));
}
}
@ -206,8 +206,8 @@ class PluginManager
$this->disable($name);
// fire event before deleting plugin files
$this->dispatcher->fire(new Events\PluginWasDeleted($plugin));
// dispatch event before deleting plugin files
$this->dispatcher->dispatch(new Events\PluginWasDeleted($plugin));
$this->filesystem->deleteDirectory($plugin->getPath());

View File

@ -130,7 +130,7 @@ if (! function_exists('bs_footer_extra')) {
{
$extraContents = [];
Event::fire(new App\Events\RenderingFooter($extraContents));
Event::dispatch(new App\Events\RenderingFooter($extraContents));
return implode("\n", $extraContents);
}
@ -142,7 +142,7 @@ if (! function_exists('bs_header_extra')) {
{
$extraContents = [];
Event::fire(new App\Events\RenderingHeader($extraContents));
Event::dispatch(new App\Events\RenderingHeader($extraContents));
return implode("\n", $extraContents);
}
@ -169,7 +169,7 @@ if (! function_exists('bs_menu')) {
{
$menu = config('menu');
Event::fire($type == "user" ? new App\Events\ConfigureUserMenu($menu)
Event::dispatch($type == "user" ? new App\Events\ConfigureUserMenu($menu)
: new App\Events\ConfigureAdminMenu($menu));
if (! isset($menu[$type])) {
@ -345,57 +345,6 @@ if (! function_exists('option_localized')) {
}
}
if (! function_exists('menv')) {
/**
* Gets the value of an environment variable by getenv() or $_ENV.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
function menv($key, $default = null)
{
if (function_exists('putenv') && function_exists('getenv')) {
// try to read by getenv()
$value = getenv($key);
if ($value === false) {
return value($default);
}
} else {
// try to read from $_ENV or $_SERVER
if (isset($_ENV[$key])) {
$value = $_ENV[$key];
} elseif (isset($_SERVER[$key])) {
$value = $_SERVER[$key];
} else {
return value($default);
}
}
switch (strtolower($value)) {
case 'true':
case '(true)':
return true;
case 'false':
case '(false)':
return false;
case 'empty':
case '(empty)':
return '';
case 'null':
case '(null)':
return;
}
if (strlen($value) > 1 && Str::startsWith($value, '"') && Str::endsWith($value, '"')) {
return substr($value, 1, -1);
}
return $value;
}
}
if (! function_exists('validate')) {
function validate($value, $type)
@ -476,19 +425,19 @@ if (! function_exists('get_client_ip')) {
function get_client_ip() {
if (option('ip_get_method') == "0") {
// Use `HTTP_X_FORWARDED_FOR` if available first
$ip = array_get(
$ip = Arr::get(
$_SERVER,
'HTTP_X_FORWARDED_FOR',
// Fallback to `HTTP_CLIENT_IP`
array_get(
Arr::get(
$_SERVER,
'HTTP_CLIENT_IP',
// Fallback to `REMOTE_ADDR`
array_get($_SERVER, 'REMOTE_ADDR')
Arr::get($_SERVER, 'REMOTE_ADDR')
)
);
} else {
$ip = array_get($_SERVER, 'REMOTE_ADDR');
$ip = Arr::get($_SERVER, 'REMOTE_ADDR');
}
return $ip;
@ -524,13 +473,13 @@ if (! function_exists('is_request_secure')) {
*/
function is_request_secure()
{
if (array_get($_SERVER, 'HTTPS') == 'on')
if (Arr::get($_SERVER, 'HTTPS') == 'on')
return true;
if (array_get($_SERVER, 'HTTP_X_FORWARDED_PROTO') == 'https')
if (Arr::get($_SERVER, 'HTTP_X_FORWARDED_PROTO') == 'https')
return true;
if (array_get($_SERVER, 'HTTP_X_FORWARDED_SSL') == 'on')
if (Arr::get($_SERVER, 'HTTP_X_FORWARDED_SSL') == 'on')
return true;
return false;

View File

@ -6,11 +6,10 @@
"php": ">=7.1.3",
"filp/whoops": "^2.1",
"predis/predis": "~1.0",
"erusev/parsedown": "^1.6",
"swiggles/memcache": "^2.0",
"doctrine/inflector": "1.1.0",
"laravel/framework": "5.7.*",
"nesbot/carbon": "^1.32.0",
"laravel/framework": "5.8.*",
"nesbot/carbon": "^2.0",
"devitek/yaml-translation": "^4.1.0",
"composer/semver": "^1.4",
"mews/captcha": "^2.2",
@ -23,8 +22,8 @@
"phpunit/phpunit": "~7.0",
"laravel/browser-kit-testing": "~4.0",
"league/flysystem-memory": "^1.0",
"mikey179/vfsStream": "^1.6.5",
"barryvdh/laravel-ide-helper": "^2.4"
"mikey179/vfsstream": "^1.6.5",
"barryvdh/laravel-ide-helper": "^2.6"
},
"autoload": {
"classmap": [

1211
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -19,7 +19,7 @@ return [
| Where to get information of new versions.
|
*/
'update_source' => menv(
'update_source' => env(
'UPDATE_SOURCE',
'https://work.prinzeugen.net/blessing-skin-server/update.json'
),
@ -35,7 +35,7 @@ return [
|
*/
'env' => menv('APP_ENV', 'production'),
'env' => env('APP_ENV', 'production'),
/*
|--------------------------------------------------------------------------
@ -48,7 +48,7 @@ return [
|
*/
'debug' => menv('APP_DEBUG', false),
'debug' => env('APP_DEBUG', false),
/*
|--------------------------------------------------------------------------
@ -61,7 +61,7 @@ return [
|
*/
'url' => menv('APP_URL', 'http://localhost'),
'url' => env('APP_URL', 'http://localhost'),
/*
|--------------------------------------------------------------------------
@ -113,7 +113,7 @@ return [
|
*/
'key' => menv('APP_KEY', 'base64:MfnScX0W/ViN8bZtRt0P481rWP3igcOK80QstjbXUxI='),
'key' => env('APP_KEY', 'base64:MfnScX0W/ViN8bZtRt0P481rWP3igcOK80QstjbXUxI='),
'cipher' => 'AES-256-CBC',
@ -130,7 +130,7 @@ return [
|
*/
'log' => menv('APP_LOG', 'single'),
'log' => env('APP_LOG', 'single'),
/*
|--------------------------------------------------------------------------

View File

@ -13,7 +13,7 @@ return [
|
*/
'default' => menv('CACHE_DRIVER', 'file'),
'default' => env('CACHE_DRIVER', 'file'),
/*
|--------------------------------------------------------------------------
@ -51,8 +51,8 @@ return [
'driver' => 'memcached',
'servers' => [
[
'host' => menv('MEMCACHED_HOST', '127.0.0.1'),
'port' => menv('MEMCACHED_PORT', 11211),
'host' => env('MEMCACHED_HOST', '127.0.0.1'),
'port' => env('MEMCACHED_PORT', 11211),
'weight' => 100,
],
],

View File

@ -26,7 +26,7 @@ return [
|
*/
'default' => menv('DB_CONNECTION', 'mysql'),
'default' => env('DB_CONNECTION', 'mysql'),
/*
|--------------------------------------------------------------------------
@ -48,33 +48,33 @@ return [
'sqlite' => [
'driver' => 'sqlite',
'database' => menv('DB_DATABASE', database_path('database.sqlite')),
'prefix' => menv('DB_PREFIX', ''),
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => env('DB_PREFIX', ''),
],
'mysql' => [
'driver' => 'mysql',
'host' => menv('DB_HOST', 'localhost'),
'port' => menv('DB_PORT', '3306'),
'database' => menv('DB_DATABASE', 'forge'),
'username' => menv('DB_USERNAME', 'forge'),
'password' => menv('DB_PASSWORD', ''),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => menv('DB_PREFIX', ''),
'prefix' => env('DB_PREFIX', ''),
'strict' => false,
'engine' => null,
],
'pgsql' => [
'driver' => 'pgsql',
'host' => menv('DB_HOST', 'localhost'),
'port' => menv('DB_PORT', '5432'),
'database' => menv('DB_DATABASE', 'forge'),
'username' => menv('DB_USERNAME', 'forge'),
'password' => menv('DB_PASSWORD', ''),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => menv('DB_PREFIX', ''),
'prefix' => env('DB_PREFIX', ''),
'schema' => 'public',
],
@ -109,11 +109,11 @@ return [
'cluster' => false,
'default' => [
'scheme' => menv('REDIS_SCHEME', 'tcp'),
'host' => menv('REDIS_HOST', 'localhost'),
'port' => menv('REDIS_PORT', 6379),
'path' => menv('REDIS_SOCKET_PATH'),
'password' => menv('REDIS_PASSWORD', null),
'scheme' => env('REDIS_SCHEME', 'tcp'),
'host' => env('REDIS_HOST', 'localhost'),
'port' => env('REDIS_PORT', 6379),
'path' => env('REDIS_SOCKET_PATH'),
'password' => env('REDIS_PASSWORD', null),
'database' => 0,
],

View File

@ -54,7 +54,7 @@ return [
],
'textures' => [
'driver' => menv('FS_DRIVER', 'local'),
'driver' => env('FS_DRIVER', 'local'),
'root' => storage_path('textures'),
],

View File

@ -16,7 +16,7 @@ return [
|
*/
'driver' => menv('MAIL_DRIVER'),
'driver' => env('MAIL_DRIVER'),
/*
|--------------------------------------------------------------------------
@ -29,7 +29,7 @@ return [
|
*/
'host' => menv('MAIL_HOST', ''),
'host' => env('MAIL_HOST', ''),
/*
|--------------------------------------------------------------------------
@ -42,7 +42,7 @@ return [
|
*/
'port' => menv('MAIL_PORT', 587),
'port' => env('MAIL_PORT', 587),
/*
|--------------------------------------------------------------------------
@ -68,7 +68,7 @@ return [
|
*/
'encryption' => menv('MAIL_ENCRYPTION', 'tls'),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
/*
|--------------------------------------------------------------------------
@ -81,7 +81,7 @@ return [
|
*/
'username' => menv('MAIL_USERNAME'),
'username' => env('MAIL_USERNAME'),
/*
|--------------------------------------------------------------------------
@ -94,7 +94,7 @@ return [
|
*/
'password' => menv('MAIL_PASSWORD'),
'password' => env('MAIL_PASSWORD'),
/*
|--------------------------------------------------------------------------
@ -107,6 +107,6 @@ return [
|
*/
'sendmail' => menv('SENDMAIL_COMMAND', '/usr/sbin/sendmail -bs'),
'sendmail' => env('SENDMAIL_COMMAND', '/usr/sbin/sendmail -bs'),
];

View File

@ -10,7 +10,7 @@ return [
| Defaults to `base_path()."/plugins"`.
|
*/
'directory' => menv('PLUGINS_DIR'),
'directory' => env('PLUGINS_DIR'),
/*
|--------------------------------------------------------------------------
@ -21,7 +21,7 @@ return [
| Defaults to `http://site_url/plugins`.
|
*/
'url' => menv('PLUGINS_URL'),
'url' => env('PLUGINS_URL'),
/*
|--------------------------------------------------------------------------
@ -31,5 +31,5 @@ return [
| Specify where to get plugins' metadata for plugin market.
|
*/
'registry' => menv('PLUGINS_REGISTRY', 'https://work.prinzeugen.net/blessing-skin-server/plugins.json'),
'registry' => env('PLUGINS_REGISTRY', 'https://work.prinzeugen.net/blessing-skin-server/plugins.json'),
];

View File

@ -15,7 +15,7 @@ return [
|
*/
'default' => menv('QUEUE_DRIVER', 'sync'),
'default' => env('QUEUE_DRIVER', 'sync'),
/*
|--------------------------------------------------------------------------
@ -78,7 +78,7 @@ return [
*/
'failed' => [
'database' => menv('DB_CONNECTION', 'mysql'),
'database' => env('DB_CONNECTION', 'mysql'),
'table' => 'failed_jobs',
],

View File

@ -9,8 +9,8 @@ return [
| Load them from env to config, preventing cache problems
|
*/
'cipher' => menv('PWD_METHOD', 'SALTED2MD5'),
'salt' => menv('SALT', ''),
'cipher' => env('PWD_METHOD', 'SALTED2MD5'),
'salt' => env('SALT', ''),
/*
|--------------------------------------------------------------------------
@ -23,6 +23,6 @@ return [
| See: http://docs.guzzlephp.org/en/stable/request-options.html#verify
|
*/
'certificates' => menv('SSL_CERT', storage_path('patches/ca-bundle.crt')),
'user_agent' => menv('USER_AGENT', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36'),
'certificates' => env('SSL_CERT', storage_path('patches/ca-bundle.crt')),
'user_agent' => env('USER_AGENT', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36'),
];

View File

@ -32,7 +32,7 @@ return [
'ses' => [
'key' => env('SES_KEY'),
'secret' => env('SES_SECRET'),
'region' => menv('SES_REGION'),
'region' => env('SES_REGION'),
'guzzle' => [
'verify' => config('secure.certificates')
],

View File

@ -16,7 +16,7 @@ return [
|
*/
'driver' => menv('SESSION_DRIVER', 'file'),
'driver' => env('SESSION_DRIVER', 'file'),
/*
|--------------------------------------------------------------------------

View File

@ -1,6 +1,7 @@
<?php
use App\Models\User;
use Illuminate\Support\Str;
$factory->define(User::class, function (Faker\Generator $faker) {
return [
@ -8,7 +9,7 @@ $factory->define(User::class, function (Faker\Generator $faker) {
'nickname' => $faker->name,
'score' => 1000,
'avatar' => 0,
'password' => app('cipher')->hash(str_random(10), config('secure.salt')),
'password' => app('cipher')->hash(Str::random(10), config('secure.salt')),
'ip' => '127.0.0.1',
'permission' => 0,
'verified' => true,
@ -23,7 +24,7 @@ $factory->defineAs(User::class, 'admin', function (Faker\Generator $faker) {
'nickname' => $faker->name,
'score' => 1000,
'avatar' => 0,
'password' => app('cipher')->hash(str_random(10), config('secure.salt')),
'password' => app('cipher')->hash(Str::random(10), config('secure.salt')),
'ip' => '127.0.0.1',
'permission' => 1,
'verified' => true,
@ -38,7 +39,7 @@ $factory->defineAs(User::class, 'superAdmin', function (Faker\Generator $faker)
'nickname' => $faker->name,
'score' => 1000,
'avatar' => 0,
'password' => app('cipher')->hash(str_random(10), config('secure.salt')),
'password' => app('cipher')->hash(Str::random(10), config('secure.salt')),
'ip' => '127.0.0.1',
'permission' => 2,
'verified' => true,
@ -53,7 +54,7 @@ $factory->defineAs(User::class, 'banned', function (Faker\Generator $faker) {
'nickname' => $faker->name,
'score' => 1000,
'avatar' => 0,
'password' => app('cipher')->hash(str_random(10), config('secure.salt')),
'password' => app('cipher')->hash(Str::random(10), config('secure.salt')),
'ip' => '127.0.0.1',
'permission' => -1,
'verified' => true,

View File

@ -5,6 +5,7 @@ namespace Tests;
use App\Models\User;
use App\Models\Player;
use App\Models\Texture;
use Illuminate\Support\Str;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
@ -13,11 +14,11 @@ class AdminControllerTest extends BrowserKitTestCase
{
use DatabaseTransactions;
protected function setUp()
protected function setUp(): void
{
// Do not use `WithoutMiddleware` trait
parent::setUp();
return $this->actAs('admin');
$this->actAs('admin');
}
public function testIndex()
@ -358,7 +359,7 @@ class AdminControllerTest extends BrowserKitTestCase
// Set a too long password
$this->postJson(
'/admin/users',
['uid' => $user->uid, 'action' => 'password', 'password' => str_random(17)],
['uid' => $user->uid, 'action' => 'password', 'password' => Str::random(17)],
['Accept' => 'application/json']
)->seeJson([
'errno' => 1,

View File

@ -5,6 +5,7 @@ namespace Tests;
use App\Events;
use App\Models\User;
use App\Models\Player;
use Illuminate\Support\Str;
use App\Mail\ForgotPassword;
use App\Services\Facades\Option;
use Illuminate\Support\Facades\URL;
@ -71,7 +72,7 @@ class AuthControllerTest extends TestCase
$this->postJson(
'/auth/login', [
'identification' => $user->email,
'password' => str_random(80)
'password' => Str::random(80)
], [
'X-Requested-With' => 'XMLHttpRequest'
])->assertJson([
@ -245,7 +246,7 @@ class AuthControllerTest extends TestCase
'/auth/register',
[
'email' => 'a@b.c',
'password' => str_random(33)
'password' => Str::random(33)
]
)->assertJson([
'errno' => 1,
@ -287,7 +288,7 @@ class AuthControllerTest extends TestCase
[
'email' => 'a@b.c',
'password' => '12345678',
'player_name' => str_random(option('player_name_length_max') + 10),
'player_name' => Str::random(option('player_name_length_max') + 10),
'captcha' => 'a'
]
)->assertJson([
@ -350,7 +351,7 @@ class AuthControllerTest extends TestCase
[
'email' => 'a@b.c',
'password' => '12345678',
'nickname' => str_random(256),
'nickname' => Str::random(256),
'captcha' => 'a'
],
['X-Requested-With' => 'XMLHttpRequest']
@ -568,7 +569,7 @@ class AuthControllerTest extends TestCase
// Should return a warning if `password` is too long
$this->postJson(
$url, [
'password' => str_random(33)
'password' => Str::random(33)
], [
'X-Requested-With' => 'XMLHttpRequest'
])->assertJson([

View File

@ -52,7 +52,7 @@ class BrowserKitTestCase extends TestCase
return $this->actingAs($role);
}
protected function tearDown()
protected function tearDown(): void
{
$this->beforeApplicationDestroyed(function () {
DB::disconnect();

View File

@ -18,11 +18,11 @@ class ClosetControllerTest extends TestCase
*/
private $user;
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->user = factory(User::class)->create();
return $this->actAs($this->user);
$this->actAs($this->user);
}
public function testIndex()

View File

@ -3,6 +3,8 @@
namespace Tests\Concerns;
use ZipArchive;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
trait GeneratesFakePlugins
{
@ -15,13 +17,13 @@ trait GeneratesFakePlugins
protected function generateFakePlguinInfo($info = [])
{
return array_replace([
'name' => str_random(10),
'name' => Str::random(10),
'version' => '0.0.'.rand(1, 9),
'title' => str_random(20),
'description' => str_random(60),
'author' => array_get($info, 'author', str_random(10)),
'url' => 'https://'.str_random(10).'.test',
'namespace' => str_random(10),
'title' => Str::random(20),
'description' => Str::random(60),
'author' => Arr::get($info, 'author', Str::random(10)),
'url' => 'https://'.Str::random(10).'.test',
'namespace' => Str::random(10),
'require' => [
'blessing-skin-server' => '^3.4.0 || ^4.0.0'
]
@ -39,8 +41,8 @@ trait GeneratesFakePlugins
return $this->generateFakePlguinInfo(array_replace([
'dist' => [
'type' => 'zip',
'url' => 'https://plugins-registry.test/'.str_random(10).'.zip',
'shasum' => strtolower(str_random(40))
'url' => 'https://plugins-registry.test/'.Str::random(10).'.zip',
'shasum' => strtolower(Str::random(40))
]
], $info));
}
@ -97,14 +99,14 @@ trait GeneratesFakePlugins
}
// Generate fake config view
if ($config = array_get($info, 'config')) {
if ($config = Arr::get($info, 'config')) {
$views_path = "$plugin_dir/views";
if (! is_dir($views_path)) {
mkdir($views_path);
}
file_put_contents("$views_path/$config", str_random(64));
file_put_contents("$views_path/$config", Str::random(64));
}
file_put_contents("$plugin_dir/package.json", json_encode(
@ -122,8 +124,8 @@ trait GeneratesFakePlugins
*/
protected function generateFakePluginArchive($info)
{
$name = array_get($info, 'name');
$version = array_get($info, 'version');
$name = Arr::get($info, 'name');
$version = Arr::get($info, 'version');
$zipPath = storage_path("testing/{$name}_{$version}.zip");
if (file_exists($zipPath)) {

View File

@ -13,11 +13,12 @@ trait InteractsWithCache
* Set the cache to the given array.
*
* @param array $data
* @param int $seconds
* @return $this
*/
public function withCache(array $data, $minutes = 60)
public function withCache(array $data, $seconds = 3600)
{
$this->cache($data, $minutes);
$this->cache($data, $seconds);
return $this;
}
@ -26,12 +27,13 @@ trait InteractsWithCache
* Set the cache to the given array.
*
* @param array $data
* @param int $seconds
* @return void
*/
public function cache(array $data, $minutes = 60)
public function cache(array $data, $seconds = 3600)
{
foreach ($data as $key => $value) {
$this->app['cache']->put($key, $value, $minutes);
$this->app['cache']->put($key, $value, $seconds);
}
}

View File

@ -14,10 +14,10 @@ class MarketControllerTest extends TestCase
use MocksGuzzleClient;
use GeneratesFakePlugins;
protected function setUp()
protected function setUp(): void
{
parent::setUp();
return $this->actAs('superAdmin');
$this->actAs('superAdmin');
}
public function testDownload()
@ -171,7 +171,7 @@ class MarketControllerTest extends TestCase
File::deleteDirectory(base_path('plugins/' . $package['name']));
}
protected function tearDown()
protected function tearDown(): void
{
// Clean fake plugins
File::deleteDirectory(base_path('plugins/fake-test-download'));

View File

@ -14,10 +14,10 @@ class PlayerControllerTest extends TestCase
{
use DatabaseTransactions;
protected function setUp()
protected function setUp(): void
{
parent::setUp();
return $this->actAs('normal');
$this->actAs('normal');
}
public function testIndex()

View File

@ -15,14 +15,14 @@ class PluginControllerTest extends TestCase
use DatabaseTransactions;
use GeneratesFakePlugins;
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->generateFakePlugin(['name' => 'fake-plugin-for-test', 'version' => '1.1.4']);
$this->generateFakePlugin(['name' => 'fake-plugin-with-config-view', 'version' => '5.1.4', 'config' => 'config.blade.php']);
return $this->actAs('superAdmin');
$this->actAs('superAdmin');
}
public function testShowManage()
@ -143,7 +143,7 @@ class PluginControllerTest extends TestCase
]);
}
protected function tearDown()
protected function tearDown(): void
{
// Clean fake plugins
File::deleteDirectory(base_path('plugins/fake-plugin-for-test'));

View File

@ -11,7 +11,7 @@ use Illuminate\Foundation\Testing\DatabaseTransactions;
class MinecraftTest extends TestCase
{
protected function setUp()
protected function setUp(): void
{
parent::setUp();
vfsStream::setup();

View File

@ -5,6 +5,7 @@ namespace Tests;
use Mockery;
use Exception;
use CreateAllTables;
use Illuminate\Support\Str;
use AddVerificationToUsersTable;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Schema;
@ -18,13 +19,13 @@ class SetupControllerTest extends TestCase
{
use DatabaseTransactions;
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->dropAllTables();
}
protected function tearDown()
protected function tearDown(): void
{
$this->dropAllTables();
Mockery::close();
@ -107,7 +108,7 @@ class SetupControllerTest extends TestCase
// Too long nickname
$this->post('/setup/finish', [
'email' => 'a@b.c',
'nickname' => str_random(256)
'nickname' => Str::random(256)
])->assertDontSee(trans('setup.wizard.finish.title'));
// Without `password` field
@ -127,7 +128,7 @@ class SetupControllerTest extends TestCase
$this->post('/setup/finish', [
'email' => 'a@b.c',
'nickname' => 'nickname',
'password' => str_random(17)
'password' => Str::random(17)
])->assertDontSee(trans('setup.wizard.finish.title'));
// Confirmation is not OK

View File

@ -6,6 +6,7 @@ use App\Models\User;
use App\Models\Closet;
use App\Models\Player;
use App\Models\Texture;
use Illuminate\Support\Str;
use org\bovigo\vfs\vfsStream;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
@ -22,7 +23,7 @@ class SkinlibControllerTest extends TestCase
*/
private $vfs_root;
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->vfs_root = vfsStream::setup();
@ -130,11 +131,11 @@ class SkinlibControllerTest extends TestCase
]);
// Search
$keyword = str_limit($skins->random()->name, 1, '');
$keyword = Str::limit($skins->random()->name, 1, '');
$expected = $skins
->filter(function ($texture) use ($keyword) {
return str_contains($texture->name, $keyword) ||
str_contains($texture->name, strtolower($keyword));
return Str::contains($texture->name, $keyword) ||
Str::contains($texture->name, strtolower($keyword));
})
->sortByDesc('upload_at')
->values();
@ -146,11 +147,11 @@ class SkinlibControllerTest extends TestCase
]);
// More than one argument
$keyword = str_limit($skins->random()->name, 1, '');
$keyword = Str::limit($skins->random()->name, 1, '');
$expected = $skins
->filter(function ($texture) use ($keyword) {
return str_contains($texture->name, $keyword) ||
str_contains($texture->name, strtolower($keyword));
return Str::contains($texture->name, $keyword) ||
Str::contains($texture->name, strtolower($keyword));
})
->sortByDesc('likes')
->values();

View File

@ -51,7 +51,7 @@ class TestCase extends \Illuminate\Foundation\Testing\TestCase
return $this->actingAs($role);
}
protected function tearDown()
protected function tearDown(): void
{
$this->beforeApplicationDestroyed(function () {
DB::disconnect();

View File

@ -20,11 +20,11 @@ class UpdateControllerTest extends TestCase
use DatabaseTransactions;
use MocksGuzzleClient;
protected function setUp()
protected function setUp(): void
{
parent::setUp();
return $this->actAs('superAdmin');
$this->actAs('superAdmin');
}
public function testShowUpdatePage()

View File

@ -6,6 +6,7 @@ use Parsedown;
use App\Events;
use Carbon\Carbon;
use App\Models\User;
use Illuminate\Support\Str;
use App\Mail\EmailVerification;
use Illuminate\Support\Facades\Mail;
use Illuminate\Foundation\Testing\WithoutMiddleware;
@ -244,7 +245,7 @@ class UserControllerTest extends TestCase
// Too long nickname
$this->postJson('/user/profile', [
'action' => 'nickname',
'new_nickname' => str_random(256)
'new_nickname' => Str::random(256)
], [
'X-Requested-With' => 'XMLHttpRequest'
])->assertJson([
@ -290,7 +291,7 @@ class UserControllerTest extends TestCase
// Too long current password
$this->postJson('/user/profile', [
'action' => 'password',
'current_password' => str_random(33),
'current_password' => Str::random(33),
'new_password' => '12345678'
], [
'X-Requested-With' => 'XMLHttpRequest'
@ -315,7 +316,7 @@ class UserControllerTest extends TestCase
$this->postJson('/user/profile', [
'action' => 'password',
'current_password' => '12345678',
'new_password' => str_random(33)
'new_password' => Str::random(33)
], [
'X-Requested-With' => 'XMLHttpRequest'
])->assertJson([
@ -390,7 +391,7 @@ class UserControllerTest extends TestCase
$this->postJson('/user/profile', [
'action' => 'email',
'new_email' => 'a@b.c',
'password' => str_random(33)
'password' => Str::random(33)
], [
'X-Requested-With' => 'XMLHttpRequest'
])->assertJson([
@ -466,7 +467,7 @@ class UserControllerTest extends TestCase
// Too long current password
$this->postJson('/user/profile', [
'action' => 'delete',
'password' => str_random(33)
'password' => Str::random(33)
], [
'X-Requested-With' => 'XMLHttpRequest'
])->assertJson([