Update tests and composer autoload
This commit is contained in:
parent
9000bd6916
commit
0ef92a5565
|
|
@ -61,7 +61,7 @@ class AuthController extends Controller
|
|||
return json(trans('auth.login.success'), 0);
|
||||
} else {
|
||||
// Increase the counter
|
||||
Cache::put($loginFailsCacheKey, ++$loginFails);
|
||||
Cache::put($loginFailsCacheKey, ++$loginFails, 60);
|
||||
|
||||
return json(trans('auth.validation.password'), 1, [
|
||||
'login_fails' => $loginFails
|
||||
|
|
|
|||
|
|
@ -40,9 +40,9 @@
|
|||
]
|
||||
},
|
||||
"autoload-dev": {
|
||||
"classmap": [
|
||||
"tests"
|
||||
]
|
||||
"psr-4": {
|
||||
"Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"preferred-install": "dist"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Player;
|
||||
use App\Models\Texture;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use App\Events;
|
||||
use App\Models\User;
|
||||
use App\Models\Player;
|
||||
use App\Services\Utils;
|
||||
use App\Mail\ForgotPassword;
|
||||
use App\Services\Facades\Option;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
|
|
@ -25,7 +30,7 @@ class AuthControllerTest extends TestCase
|
|||
|
||||
$user = factory(User::class)->create();
|
||||
$user->changePassword('12345678');
|
||||
$player = factory(App\Models\Player::class)->create(
|
||||
$player = factory(Player::class)->create(
|
||||
[
|
||||
'uid' => $user->uid
|
||||
]
|
||||
|
|
@ -90,7 +95,8 @@ class AuthControllerTest extends TestCase
|
|||
'msg' => trans('auth.validation.password'),
|
||||
'login_fails' => 1
|
||||
]
|
||||
); // Unable to assert cache content since array driver has unexpected behaviors
|
||||
);
|
||||
$this->assertCacheHas($loginFailsCacheKey);
|
||||
|
||||
$this->flushSession();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,12 @@
|
|||
<?php
|
||||
|
||||
class BrowserKitTestCase extends Laravel\BrowserKitTesting\TestCase
|
||||
namespace Tests;
|
||||
|
||||
use DB;
|
||||
use Artisan;
|
||||
use Laravel\BrowserKitTesting\TestCase;
|
||||
|
||||
class BrowserKitTestCase extends TestCase
|
||||
{
|
||||
/**
|
||||
* The base URL to use while testing the application.
|
||||
|
|
@ -18,7 +24,7 @@ class BrowserKitTestCase extends Laravel\BrowserKitTesting\TestCase
|
|||
{
|
||||
$app = require __DIR__.'/../bootstrap/app.php';
|
||||
|
||||
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
||||
$app->make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
||||
|
||||
Artisan::call('migrate:refresh');
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Closet;
|
||||
use App\Models\Texture;
|
||||
|
|
|
|||
117
tests/Concerns/InteractsWithCache.php
Normal file
117
tests/Concerns/InteractsWithCache.php
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Concerns;
|
||||
|
||||
/**
|
||||
* Add ability to interact with cache in tests.
|
||||
*
|
||||
* @see \Illuminate\Foundation\Testing\Concerns\InteractsWithSession
|
||||
*/
|
||||
trait InteractsWithCache
|
||||
{
|
||||
/**
|
||||
* Set the cache to the given array.
|
||||
*
|
||||
* @param array $data
|
||||
* @return $this
|
||||
*/
|
||||
public function withCache(array $data, $minutes = 60)
|
||||
{
|
||||
$this->cache($data, $minutes);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cache to the given array.
|
||||
*
|
||||
* @param array $data
|
||||
* @return void
|
||||
*/
|
||||
public function cache(array $data, $minutes = 60)
|
||||
{
|
||||
foreach ($data as $key => $value) {
|
||||
$this->app['cache']->put($key, $value, $minutes);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush all of the current cache data.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flushCache()
|
||||
{
|
||||
$this->app['cache']->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the cache has a given value.
|
||||
*
|
||||
* @param string|array $key
|
||||
* @param mixed $value
|
||||
* @return $this
|
||||
*/
|
||||
public function seeInCache($key, $value = null)
|
||||
{
|
||||
$this->assertCacheHas($key, $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the cache has a given value.
|
||||
*
|
||||
* @param string|array $key
|
||||
* @param mixed $value
|
||||
* @return $this
|
||||
*/
|
||||
public function assertCacheHas($key, $value = null)
|
||||
{
|
||||
if (is_array($key)) {
|
||||
$this->assertCacheHasAll($key);
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (is_null($value)) {
|
||||
$this->assertTrue($this->app['cache.store']->has($key), "Cache missing key: $key");
|
||||
} else {
|
||||
$this->assertEquals($value, $this->app['cache.store']->get($key));
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the cache has a given list of values.
|
||||
*
|
||||
* @param array $bindings
|
||||
* @return void
|
||||
*/
|
||||
public function assertCacheHasAll(array $bindings)
|
||||
{
|
||||
foreach ($bindings as $key => $value) {
|
||||
if (is_int($key)) {
|
||||
$this->assertCacheHas($value);
|
||||
} else {
|
||||
$this->assertCacheHas($key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the cache does not have a given key.
|
||||
*
|
||||
* @param string|array $key
|
||||
* @return void
|
||||
*/
|
||||
public function assertCacheMissing($key)
|
||||
{
|
||||
if (is_array($key)) {
|
||||
foreach ($key as $k) {
|
||||
$this->assertCacheMissing($k);
|
||||
}
|
||||
} else {
|
||||
$this->assertFalse($this->app['cache.store']->has($key), "Cache has unexpected key: $key");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use stdClass;
|
||||
use App\Events\RenderingHeader;
|
||||
use App\Events\RenderingFooter;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\Facades\Option;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
|
@ -27,7 +30,7 @@ class MiddlewareTest extends TestCase
|
|||
->assertStatus(403);
|
||||
|
||||
// Binding email
|
||||
$noEmailUser = factory(App\Models\User::class)->create(['email' => '']);
|
||||
$noEmailUser = factory(\App\Models\User::class)->create(['email' => '']);
|
||||
$this->actingAs($noEmailUser)
|
||||
->get('/user')
|
||||
->assertSee('Bind')
|
||||
|
|
@ -118,7 +121,7 @@ class MiddlewareTest extends TestCase
|
|||
Option::set('return_204_when_notfound', true);
|
||||
$this->getJson('/nope.json')->assertStatus(204);
|
||||
|
||||
$player = factory(App\Models\Player::class)->create();
|
||||
$player = factory(\App\Models\Player::class)->create();
|
||||
$this->getJson("/{$player->player_name}.json")
|
||||
->assertJson(['username' => $player->player_name]); // Default is CSL API
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Closet;
|
||||
use App\Models\Texture;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use App\Models\Player;
|
||||
use App\Models\Texture;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\Utils;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use App\Events;
|
||||
use App\Models\User;
|
||||
use App\Models\Player;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use App\Events;
|
||||
use ZipArchive;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
|
@ -117,7 +121,7 @@ class PluginControllerTest extends TestCase
|
|||
|
||||
// Enable a plugin
|
||||
app('plugins')->getPlugin('avatar-api')->setRequirements([]);
|
||||
$this->expectsEvents(App\Events\PluginWasEnabled::class);
|
||||
$this->expectsEvents(Events\PluginWasEnabled::class);
|
||||
$this->postJson('/admin/plugins/manage', [
|
||||
'name' => 'avatar-api',
|
||||
'action' => 'enable'
|
||||
|
|
@ -140,7 +144,7 @@ class PluginControllerTest extends TestCase
|
|||
['plugin' => plugin('avatar-api')->title]
|
||||
)
|
||||
]);
|
||||
$this->expectsEvents(App\Events\PluginWasDisabled::class);
|
||||
$this->expectsEvents(Events\PluginWasDisabled::class);
|
||||
|
||||
// Delete a plugin
|
||||
$this->postJson('/admin/plugins/manage', [
|
||||
|
|
@ -150,7 +154,7 @@ class PluginControllerTest extends TestCase
|
|||
'errno' => 0,
|
||||
'msg' => trans('admin.plugins.operations.deleted')
|
||||
]);
|
||||
$this->expectsEvents(App\Events\PluginWasDeleted::class);
|
||||
$this->expectsEvents(Events\PluginWasDeleted::class);
|
||||
$this->assertFalse(file_exists(base_path('plugins/avatar-api/')));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use App\Services\Hook;
|
||||
|
||||
class HookTest extends TestCase
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use App\Services\Minecraft;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
use App\Http\Controllers\TextureController;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use App\Services\Repositories\OptionRepository;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use App\Services\Repositories\Repository;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\Repositories\UserRepository;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Mockery;
|
||||
use Exception;
|
||||
use CreateAllTables;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Closet;
|
||||
use App\Models\Player;
|
||||
|
|
@ -7,6 +9,7 @@ use App\Models\Texture;
|
|||
use App\Services\Utils;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,15 @@
|
|||
<?php
|
||||
|
||||
class TestCase extends Illuminate\Foundation\Testing\TestCase
|
||||
namespace Tests;
|
||||
|
||||
use DB;
|
||||
use Artisan;
|
||||
use Tests\Concerns\InteractsWithCache;
|
||||
|
||||
class TestCase extends \Illuminate\Foundation\Testing\TestCase
|
||||
{
|
||||
use InteractsWithCache;
|
||||
|
||||
/**
|
||||
* The base URL to use while testing the application.
|
||||
*
|
||||
|
|
@ -18,7 +26,7 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
|||
{
|
||||
$app = require __DIR__.'/../bootstrap/app.php';
|
||||
|
||||
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
||||
$app->make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
||||
|
||||
Artisan::call('migrate:refresh');
|
||||
|
||||
|
|
@ -43,48 +51,6 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
|||
return $this->actingAs($role);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cache to the given array.
|
||||
*
|
||||
* @param array $data
|
||||
* @param int $minutes
|
||||
* @return $this
|
||||
*/
|
||||
public function withCache(array $data, $minutes = 60)
|
||||
{
|
||||
foreach ($data as $key => $value) {
|
||||
$this->app['cache.store']->put($key, $value, $minutes);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the cache does not have a given key.
|
||||
*
|
||||
* @param string|array $key
|
||||
* @return void
|
||||
*/
|
||||
public function assertCacheMissing($key)
|
||||
{
|
||||
if (is_array($key)) {
|
||||
foreach ($key as $k) {
|
||||
$this->assertCacheMissing($k);
|
||||
}
|
||||
} else {
|
||||
$this->assertFalse($this->app['cache.store']->has($key), "Cache has unexpected key: $key");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush all of the current cache data.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flushCache()
|
||||
{
|
||||
$this->app['cache.store']->flush();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->beforeApplicationDestroyed(function () {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Mockery;
|
||||
use Exception;
|
||||
use App\Models\User;
|
||||
use App\Models\Player;
|
||||
use App\Models\Texture;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Exception;
|
||||
use ZipArchive;
|
||||
use org\bovigo\vfs;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Parsedown;
|
||||
use App\Events;
|
||||
use App\Models\User;
|
||||
use App\Mail\EmailVerification;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user