From 5e00131db4146460e6e75097d8551481451f583c Mon Sep 17 00:00:00 2001 From: printempw Date: Fri, 23 Feb 2018 09:51:23 +0800 Subject: [PATCH] Fix tests for SQLite database --- app/Models/Player.php | 13 +++++++++++++ app/Models/Texture.php | 13 +++++++++++++ app/Models/User.php | 18 +++++++++++++++--- tests/SetupControllerTest.php | 13 ++++++++++--- tests/SkinlibControllerTest.php | 6 +++--- 5 files changed, 54 insertions(+), 9 deletions(-) diff --git a/app/Models/Player.php b/app/Models/Player.php index dac60f92..92f203ee 100644 --- a/app/Models/Player.php +++ b/app/Models/Player.php @@ -33,6 +33,19 @@ class Player extends Model public $timestamps = false; protected $fillable = ['uid', 'player_name', 'preference', 'last_modified']; + /** + * The attributes that should be cast to native types. + * + * @var array + */ + protected $casts = [ + 'pid' => 'integer', + 'uid' => 'integer', + 'tid_steve' => 'integer', + 'tid_alex' => 'integer', + 'tid_cape' => 'integer', + ]; + /** * Check if the player is banned. * diff --git a/app/Models/Texture.php b/app/Models/Texture.php index d9c989bd..61ced018 100644 --- a/app/Models/Texture.php +++ b/app/Models/Texture.php @@ -9,6 +9,19 @@ class Texture extends Model public $primaryKey = 'tid'; public $timestamps = false; + /** + * The attributes that should be cast to native types. + * + * @var array + */ + protected $casts = [ + 'tid' => 'integer', + 'likes' => 'integer', + 'size' => 'integer', + 'uploader' => 'integer', + 'public' => 'integer', + ]; + public function setPrivacy($public) { $this->public = $public ? "1" : "0"; diff --git a/app/Models/User.php b/app/Models/User.php index bf08c339..c129fafe 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -22,13 +22,13 @@ class User extends Model * User Token. * @var string */ - private $token; + protected $token; /** * Instance of Closet. - * @var App\Models\Closet + * @var \App\Models\Closet */ - private $closet; + protected $closet; /** * Properties for Eloquent Model. @@ -37,6 +37,18 @@ class User extends Model public $timestamps = false; protected $fillable = ['email', 'nickname', 'permission']; + /** + * The attributes that should be cast to native types. + * + * @var array + */ + protected $casts = [ + 'uid' => 'integer', + 'score' => 'integer', + 'avatar' => 'integer', + 'permission' => 'integer', + ]; + /** * Storage size used by user in KiB. * diff --git a/tests/SetupControllerTest.php b/tests/SetupControllerTest.php index ecb9865a..b7705ad3 100644 --- a/tests/SetupControllerTest.php +++ b/tests/SetupControllerTest.php @@ -37,9 +37,16 @@ class SetupControllerTest extends TestCase public function testWelcome() { - $this->visit('/setup') - ->see(config('database.connections.mysql.username')) - ->see(config('database.connections.mysql.host')); + $type = get_db_type(); + + if ($type === 'SQLite') { + $server = get_db_config()['database']; + } else { + $config = get_db_config(); + $server = "{$config['username']}@{$config['host']}"; + } + + $this->visit('/setup')->see($type)->see($server); } public function testInfo() diff --git a/tests/SkinlibControllerTest.php b/tests/SkinlibControllerTest.php index 35567c0d..a64b7d72 100644 --- a/tests/SkinlibControllerTest.php +++ b/tests/SkinlibControllerTest.php @@ -793,7 +793,7 @@ class SkinlibControllerTest extends TestCase ->seeJson([ 'errno' => 0, 'msg' => trans('skinlib.privacy.success', ['privacy' => trans('general.private')]), - 'public' => '0' + 'public' => 0 ]); $this->assertEquals(0, Texture::find($texture->tid)->public); @@ -818,7 +818,7 @@ class SkinlibControllerTest extends TestCase ->seeJson([ 'errno' => 0, 'msg' => trans('skinlib.privacy.success', ['privacy' => trans('general.private')]), - 'public' => '0' + 'public' => 0 ]); $this->assertEquals(0, User::find($uploader->uid)->score); @@ -833,7 +833,7 @@ class SkinlibControllerTest extends TestCase ->seeJson([ 'errno' => 0, 'msg' => trans('skinlib.privacy.success', ['privacy' => trans('general.private')]), - 'public' => '0' + 'public' => 0 ]); $this->assertEquals(0, Player::find($player->pid)->tid_steve); }