mirror of
https://github.com/koel/koel
synced 2024-11-24 05:03:05 +00:00
chore(builds): upgrade to Laravel 8 (#1261)
This commit is contained in:
parent
6130bf7b79
commit
58c00192ad
75 changed files with 2035 additions and 1565 deletions
|
@ -4,6 +4,9 @@ namespace App\Facades;
|
|||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
* @method static string detectUTFEncoding(string $name)
|
||||
*/
|
||||
class Util extends Facade
|
||||
{
|
||||
protected static function getFacadeAccessor()
|
||||
|
|
|
@ -34,10 +34,10 @@ class SongController extends Controller
|
|||
$path = "s3://{$request->bucket}/{$request->key}";
|
||||
|
||||
$tags = $request->tags;
|
||||
$artist = Artist::get(array_get($tags, 'artist'));
|
||||
$artist = Artist::getOrCreate(array_get($tags, 'artist'));
|
||||
|
||||
$compilation = (bool) trim(array_get($tags, 'albumartist'));
|
||||
$album = Album::get($artist, array_get($tags, 'album'), $compilation);
|
||||
$album = Album::getOrCreate($artist, array_get($tags, 'album'), $compilation);
|
||||
|
||||
if ($cover = array_get($tags, 'cover')) {
|
||||
$this->mediaMetadataService->writeAlbumCover($album, base64_decode($cover['data']), $cover['extension']);
|
||||
|
|
|
@ -7,6 +7,7 @@ use function App\Helpers\album_cover_url;
|
|||
use App\Traits\SupportsDeleteWhereIDsNotIn;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
@ -30,9 +31,11 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
|||
* @method static self|null find(int $id)
|
||||
* @method static Builder where(...$params)
|
||||
* @method static self first()
|
||||
* @method static Builder whereArtistIdAndName(int $id, string $name)
|
||||
*/
|
||||
class Album extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use SupportsDeleteWhereIDsNotIn;
|
||||
|
||||
const UNKNOWN_ID = 1;
|
||||
|
@ -63,7 +66,7 @@ class Album extends Model
|
|||
* Get an album using some provided information.
|
||||
* If such is not found, a new album will be created using the information.
|
||||
*/
|
||||
public static function get(Artist $artist, string $name, bool $isCompilation = false): self
|
||||
public static function getOrCreate(Artist $artist, ?string $name = null, bool $isCompilation = false): self
|
||||
{
|
||||
// If this is a compilation album, its artist must be "Various Artists"
|
||||
if ($isCompilation) {
|
||||
|
@ -72,7 +75,7 @@ class Album extends Model
|
|||
|
||||
return static::firstOrCreate([
|
||||
'artist_id' => $artist->id,
|
||||
'name' => $name ?: self::UNKNOWN_NAME,
|
||||
'name' => trim($name) ?: self::UNKNOWN_NAME,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ use function App\Helpers\artist_image_url;
|
|||
use App\Traits\SupportsDeleteWhereIDsNotIn;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
|
@ -26,9 +27,11 @@ use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
|||
* @method static self firstOrCreate(array $where, array $params = [])
|
||||
* @method static Builder where(...$params)
|
||||
* @method static self first()
|
||||
* @method static Builder whereName(string $name)
|
||||
*/
|
||||
class Artist extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use SupportsDeleteWhereIDsNotIn;
|
||||
|
||||
const UNKNOWN_ID = 1;
|
||||
|
@ -81,16 +84,14 @@ class Artist extends Model
|
|||
* Get an Artist object from their name.
|
||||
* If such is not found, a new artist will be created.
|
||||
*/
|
||||
public static function get(string $name): self
|
||||
public static function getOrCreate(?string $name = null): self
|
||||
{
|
||||
// Remove the BOM from UTF-8/16/32, as it will mess up the database constraints.
|
||||
if ($encoding = Util::detectUTFEncoding($name)) {
|
||||
$name = mb_convert_encoding($name, 'UTF-8', $encoding);
|
||||
}
|
||||
|
||||
$name = trim($name) ?: self::UNKNOWN_NAME;
|
||||
|
||||
return static::firstOrCreate(compact('name'));
|
||||
return static::firstOrCreate(['name' => trim($name) ?: self::UNKNOWN_NAME]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
namespace App\Models;
|
||||
|
||||
use App\Traits\CanFilterByUser;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
|
@ -13,11 +15,14 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|||
* @property User $user
|
||||
* @property int $id
|
||||
*
|
||||
* @method self firstOrCreate(array $where, array $params = [])
|
||||
* @method self firstOrCreate(array $where, array $params = [])
|
||||
* @method static self find(int $id)
|
||||
* @method static Builder whereSongIdAndUserId(string $songId, string $userId)
|
||||
*/
|
||||
class Interaction extends Model
|
||||
{
|
||||
use CanFilterByUser;
|
||||
use HasFactory;
|
||||
|
||||
protected $casts = [
|
||||
'liked' => 'boolean',
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace App\Models;
|
|||
use App\Traits\CanFilterByUser;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
@ -23,6 +24,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|||
class Playlist extends Model
|
||||
{
|
||||
use CanFilterByUser;
|
||||
use HasFactory;
|
||||
|
||||
protected $hidden = ['user_id', 'created_at', 'updated_at'];
|
||||
protected $guarded = ['id'];
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
|
@ -13,10 +14,10 @@ use Illuminate\Database\Eloquent\Model;
|
|||
*/
|
||||
class Setting extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $primaryKey = 'key';
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,6 +6,7 @@ use App\Events\LibraryChanged;
|
|||
use App\Traits\SupportsDeleteWhereIDsNotIn;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
@ -38,6 +39,7 @@ use Illuminate\Support\Collection;
|
|||
*/
|
||||
class Song extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use SupportsDeleteWhereIDsNotIn;
|
||||
|
||||
protected $guarded = [];
|
||||
|
@ -156,7 +158,7 @@ class Song extends Model
|
|||
$artistName = Artist::UNKNOWN_NAME;
|
||||
}
|
||||
|
||||
$artist = Artist::get($artistName);
|
||||
$artist = Artist::getOrCreate($artistName);
|
||||
|
||||
switch ($compilationState) {
|
||||
case 1: // ALL, or forcing compilation status to be Yes
|
||||
|
@ -170,7 +172,7 @@ class Song extends Model
|
|||
break;
|
||||
}
|
||||
|
||||
$album = Album::get($artist, $albumName, $isCompilation);
|
||||
$album = Album::getOrCreate($artist, $albumName, $isCompilation);
|
||||
|
||||
$this->artist_id = $artist->id;
|
||||
$this->album_id = $album->id;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
@ -22,8 +23,9 @@ use Laravel\Sanctum\HasApiTokens;
|
|||
*/
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use Notifiable;
|
||||
use HasApiTokens;
|
||||
use HasFactory;
|
||||
use Notifiable;
|
||||
|
||||
/**
|
||||
* The preferences that we don't want to show to the client.
|
||||
|
|
|
@ -186,21 +186,21 @@ class FileSynchronizer
|
|||
|
||||
// If the "artist" tag is specified, use it.
|
||||
// Otherwise, re-use the existing model value.
|
||||
$artist = isset($info['artist']) ? Artist::get($info['artist']) : $this->song->album->artist;
|
||||
$artist = isset($info['artist']) ? Artist::getOrCreate($info['artist']) : $this->song->album->artist;
|
||||
|
||||
// If the "album" tag is specified, use it.
|
||||
// Otherwise, re-use the existing model value.
|
||||
if (isset($info['album'])) {
|
||||
$album = $changeCompilationAlbumOnly
|
||||
? $this->song->album
|
||||
: Album::get($artist, $info['album'], array_get($info, 'compilation'));
|
||||
: Album::getOrCreate($artist, $info['album'], array_get($info, 'compilation'));
|
||||
} else {
|
||||
$album = $this->song->album;
|
||||
}
|
||||
} else {
|
||||
// The file is newly added.
|
||||
$artist = Artist::get($info['artist']);
|
||||
$album = Album::get($artist, $info['album'], array_get($info, 'compilation'));
|
||||
$artist = Artist::getOrCreate($info['artist']);
|
||||
$album = Album::getOrCreate($artist, $info['album'], array_get($info, 'compilation'));
|
||||
}
|
||||
|
||||
if (!$album->has_cover) {
|
||||
|
|
|
@ -6,6 +6,7 @@ use App\Exceptions\MediaPathNotSetException;
|
|||
use App\Exceptions\SongUploadFailedException;
|
||||
use App\Models\Setting;
|
||||
use App\Models\Song;
|
||||
use function Functional\memoize;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
|
||||
class UploadService
|
||||
|
@ -45,19 +46,15 @@ class UploadService
|
|||
*/
|
||||
private function getUploadDirectory(): string
|
||||
{
|
||||
static $uploadDirectory;
|
||||
|
||||
if (!$uploadDirectory) {
|
||||
return memoize(static function (): string {
|
||||
$mediaPath = Setting::get('media_path');
|
||||
|
||||
if (!$mediaPath) {
|
||||
throw new MediaPathNotSetException();
|
||||
}
|
||||
|
||||
$uploadDirectory = $mediaPath.DIRECTORY_SEPARATOR.self::UPLOAD_DIRECTORY.DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
return $uploadDirectory;
|
||||
return $mediaPath.DIRECTORY_SEPARATOR.self::UPLOAD_DIRECTORY.DIRECTORY_SEPARATOR;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,7 +16,7 @@ class Util
|
|||
/**
|
||||
* Detects higher UTF encoded strings.
|
||||
*/
|
||||
public function detectUTFEncoding(string $str): ?string
|
||||
public function detectUTFEncoding(?string $str): ?string
|
||||
{
|
||||
switch (substr($str, 0, 2)) {
|
||||
case UTF16_BIG_ENDIAN_BOM:
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
{
|
||||
"name": "phanan/koel",
|
||||
"description": "Personal audio streaming service that works.",
|
||||
"keywords": ["audio", "stream", "mp3"],
|
||||
"keywords": [
|
||||
"audio",
|
||||
"stream",
|
||||
"mp3"
|
||||
],
|
||||
"license": "MIT",
|
||||
"type": "project",
|
||||
"require": {
|
||||
"php": ">=7.2.5",
|
||||
"laravel/framework": "^7.0",
|
||||
"php": ">=7.3",
|
||||
"laravel/framework": "^8.0",
|
||||
"james-heinrich/getid3": "^1.9",
|
||||
"guzzlehttp/guzzle": "^6.1",
|
||||
"guzzlehttp/guzzle": "^7.0.1",
|
||||
"aws/aws-sdk-php-laravel": "^3.1",
|
||||
"pusher/pusher-php-server": "^4.0",
|
||||
"predis/predis": "~1.0",
|
||||
|
@ -21,16 +25,18 @@
|
|||
"laravel/helpers": "^1.0",
|
||||
"intervention/image": "^2.5",
|
||||
"laravel/sanctum": "^2.6",
|
||||
"doctrine/dbal": "^2.10"
|
||||
"doctrine/dbal": "^2.10",
|
||||
"lstrojny/functional-php": "^1.14"
|
||||
},
|
||||
"require-dev": {
|
||||
"filp/whoops": "~2.0",
|
||||
"fzaninotto/faker": "~1.4",
|
||||
"mockery/mockery": "~1.0",
|
||||
"phpunit/phpunit": "^8.5",
|
||||
"phpunit/phpunit": "^9.0",
|
||||
"laravel/tinker": "^2.0",
|
||||
"php-mock/php-mock-mockery": "^1.3",
|
||||
"friendsofphp/php-cs-fixer": "^2.16"
|
||||
"friendsofphp/php-cs-fixer": "^2.16",
|
||||
"dms/phpunit-arraysubset-asserts": "^0.2.1"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-zip": "Allow downloading multiple songs as Zip archives"
|
||||
|
@ -41,7 +47,9 @@
|
|||
],
|
||||
"psr-4": {
|
||||
"App\\": "app/",
|
||||
"Tests\\": "tests/"
|
||||
"Tests\\": "tests/",
|
||||
"Database\\Factories\\": "database/factories/",
|
||||
"Database\\Seeders\\": "database/seeders/"
|
||||
},
|
||||
"files": [
|
||||
"app/Helpers.php"
|
||||
|
|
2522
composer.lock
generated
2522
composer.lock
generated
File diff suppressed because it is too large
Load diff
21
database/factories/AlbumFactory.php
Normal file
21
database/factories/AlbumFactory.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Album;
|
||||
use App\Models\Artist;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class AlbumFactory extends Factory
|
||||
{
|
||||
protected $model = Album::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'artist_id' => Artist::factory(),
|
||||
'name' => ucwords($this->faker->words(random_int(2, 5), true)),
|
||||
'cover' => md5(uniqid()).'.jpg',
|
||||
];
|
||||
}
|
||||
}
|
19
database/factories/ArtistFactory.php
Normal file
19
database/factories/ArtistFactory.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Artist;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class ArtistFactory extends Factory
|
||||
{
|
||||
protected $model = Artist::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->name,
|
||||
'image' => md5(uniqid()).'.jpg',
|
||||
];
|
||||
}
|
||||
}
|
23
database/factories/InteractionFactory.php
Normal file
23
database/factories/InteractionFactory.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Interaction;
|
||||
use App\Models\Song;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class InteractionFactory extends Factory
|
||||
{
|
||||
protected $model = Interaction::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'song_id' => Song::factory(),
|
||||
'user_id' => User::factory(),
|
||||
'liked' => $this->faker->boolean,
|
||||
'play_count' => $this->faker->randomNumber(),
|
||||
];
|
||||
}
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Album;
|
||||
use App\Models\Artist;
|
||||
use App\Models\Interaction;
|
||||
use App\Models\Playlist;
|
||||
use App\Models\Setting;
|
||||
use App\Models\Song;
|
||||
use App\Models\User;
|
||||
use Faker\Generator as Faker;
|
||||
use Illuminate\Database\Eloquent\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
/* @var Factory $factory */
|
||||
$factory->define(User::class, function ($faker) {
|
||||
return [
|
||||
'name' => $faker->name,
|
||||
'email' => $faker->email,
|
||||
'password' => Hash::make('secret'),
|
||||
'is_admin' => false,
|
||||
'preferences' => [],
|
||||
'remember_token' => str_random(10),
|
||||
];
|
||||
});
|
||||
|
||||
$factory->state(User::class, 'admin', function () use ($factory) {
|
||||
return ['is_admin' => true];
|
||||
});
|
||||
|
||||
$factory->define(Artist::class, function (Faker $faker) {
|
||||
return [
|
||||
'name' => $faker->name,
|
||||
'image' => md5(uniqid()).'.jpg',
|
||||
];
|
||||
});
|
||||
|
||||
$factory->define(Album::class, function (Faker $faker) {
|
||||
return [
|
||||
'artist_id' => static function (): int {
|
||||
return factory(Artist::class)->create()->id;
|
||||
},
|
||||
'name' => ucwords($faker->words(random_int(2, 5), true)),
|
||||
'cover' => md5(uniqid()).'.jpg',
|
||||
];
|
||||
});
|
||||
|
||||
$factory->define(Song::class, function (Faker $faker) {
|
||||
/** @var Album $album */
|
||||
$album = factory(Album::class)->create();
|
||||
|
||||
return [
|
||||
'album_id' => $album->id,
|
||||
'artist_id' => $album->artist->id,
|
||||
'title' => ucwords($faker->words(random_int(2, 5), true)),
|
||||
'length' => $faker->randomFloat(2, 10, 500),
|
||||
'track' => random_int(1, 20),
|
||||
'lyrics' => $faker->paragraph(),
|
||||
'path' => '/tmp/'.uniqid().'.mp3',
|
||||
'mtime' => time(),
|
||||
];
|
||||
});
|
||||
|
||||
$factory->define(Playlist::class, function (Faker $faker) {
|
||||
return [
|
||||
'user_id' => static function (): int {
|
||||
return factory(User::class)->create()->id;
|
||||
},
|
||||
'name' => $faker->name,
|
||||
'rules' => null,
|
||||
];
|
||||
});
|
||||
|
||||
$factory->define(Interaction::class, function (Faker $faker) {
|
||||
return [
|
||||
'song_id' => static function (): string {
|
||||
return factory(Song::class)->create()->id;
|
||||
},
|
||||
'user_id' => static function (): int {
|
||||
return factory(User::class)->create()->id;
|
||||
},
|
||||
'liked' => $faker->boolean,
|
||||
'play_count' => $faker->randomNumber,
|
||||
];
|
||||
});
|
||||
|
||||
$factory->define(Setting::class, function (Faker $faker) {
|
||||
return [
|
||||
'key' => $faker->slug,
|
||||
'value' => $faker->name,
|
||||
];
|
||||
});
|
21
database/factories/PlaylistFactory.php
Normal file
21
database/factories/PlaylistFactory.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Playlist;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class PlaylistFactory extends Factory
|
||||
{
|
||||
protected $model = Playlist::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'user_id' => User::factory(),
|
||||
'name' => $this->faker->name,
|
||||
'rules' => null,
|
||||
];
|
||||
}
|
||||
}
|
19
database/factories/SettingFactory.php
Normal file
19
database/factories/SettingFactory.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class SettingFactory extends Factory
|
||||
{
|
||||
protected $model = Setting::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'key' => $this->faker->slug,
|
||||
'value' => $this->faker->name,
|
||||
];
|
||||
}
|
||||
}
|
29
database/factories/SongFactory.php
Normal file
29
database/factories/SongFactory.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Album;
|
||||
use App\Models\Song;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class SongFactory extends Factory
|
||||
{
|
||||
protected $model = Song::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
/** @var Album $album */
|
||||
$album = Album::factory()->create();
|
||||
|
||||
return [
|
||||
'album_id' => $album->id,
|
||||
'artist_id' => $album->artist->id,
|
||||
'title' => ucwords($this->faker->words(random_int(2, 5), true)),
|
||||
'length' => $this->faker->randomFloat(2, 10, 500),
|
||||
'track' => random_int(1, 20),
|
||||
'lyrics' => $this->faker->paragraph(),
|
||||
'path' => '/tmp/'.uniqid().'.mp3',
|
||||
'mtime' => time(),
|
||||
];
|
||||
}
|
||||
}
|
31
database/factories/UserFactory.php
Normal file
31
database/factories/UserFactory.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
protected $model = User::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->name,
|
||||
'email' => $this->faker->email,
|
||||
'password' => Hash::make('secret'),
|
||||
'is_admin' => false,
|
||||
'preferences' => [],
|
||||
'remember_token' => str_random(10),
|
||||
];
|
||||
}
|
||||
|
||||
public function admin()
|
||||
{
|
||||
return $this->state(function (): array {
|
||||
return ['is_admin' => true];
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Album;
|
||||
use App\Models\Artist;
|
||||
use Illuminate\Database\Seeder;
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Artist;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
|
@ -23,7 +23,7 @@ class AlbumCoverTest extends TestCase
|
|||
$this->expectsEvents(LibraryChanged::class);
|
||||
|
||||
/** @var Album $album */
|
||||
$album = factory(Album::class)->create(['id' => 9999]);
|
||||
$album = Album::factory()->create(['id' => 9999]);
|
||||
|
||||
$this->mediaMetadataService
|
||||
->shouldReceive('writeAlbumCover')
|
||||
|
@ -34,7 +34,7 @@ class AlbumCoverTest extends TestCase
|
|||
|
||||
$response = $this->putAsUser('api/album/'.$album->id.'/cover', [
|
||||
'cover' => 'data:image/jpeg;base64,Rm9v',
|
||||
], factory(User::class)->states('admin')->create());
|
||||
], User::factory()->admin()->create());
|
||||
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ class AlbumCoverTest extends TestCase
|
|||
public function testUpdateNotAllowedForNormalUsers(): void
|
||||
{
|
||||
/** @var Album $album */
|
||||
$album = factory(Album::class)->create();
|
||||
$album = Album::factory()->create();
|
||||
|
||||
$this->mediaMetadataService
|
||||
->shouldReceive('writeAlbumCover')
|
||||
|
@ -50,7 +50,7 @@ class AlbumCoverTest extends TestCase
|
|||
|
||||
$this->putAsUser('api/album/'.$album->id.'/cover', [
|
||||
'cover' => 'data:image/jpeg;base64,Rm9v',
|
||||
], factory(User::class)->create())
|
||||
], User::factory()->create())
|
||||
->assertStatus(403);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ class AlbumThumbnailTest extends TestCase
|
|||
public function testGetAlbumThumbnail(?string $thumbnailUrl): void
|
||||
{
|
||||
/** @var Album $createdAlbum */
|
||||
$createdAlbum = factory(Album::class)->create();
|
||||
$createdAlbum = Album::factory()->create();
|
||||
|
||||
$this->mediaMetadataService
|
||||
->shouldReceive('getAlbumThumbnailUrl')
|
||||
|
|
|
@ -23,7 +23,7 @@ class ArtistImageTest extends TestCase
|
|||
public function testUpdate(): void
|
||||
{
|
||||
$this->expectsEvents(LibraryChanged::class);
|
||||
factory(Artist::class)->create(['id' => 9999]);
|
||||
Artist::factory()->create(['id' => 9999]);
|
||||
|
||||
$this->mediaMetadataService
|
||||
->shouldReceive('writeArtistImage')
|
||||
|
@ -34,13 +34,13 @@ class ArtistImageTest extends TestCase
|
|||
|
||||
$this->putAsUser('api/artist/9999/image', [
|
||||
'image' => 'data:image/jpeg;base64,Rm9v',
|
||||
], factory(User::class)->states('admin')->create())
|
||||
], User::factory()->admin()->create())
|
||||
->assertStatus(200);
|
||||
}
|
||||
|
||||
public function testUpdateNotAllowedForNormalUsers(): void
|
||||
{
|
||||
factory(Artist::class)->create(['id' => 9999]);
|
||||
Artist::factory()->create(['id' => 9999]);
|
||||
|
||||
$this->mediaMetadataService
|
||||
->shouldReceive('writeArtistImage')
|
||||
|
@ -48,7 +48,7 @@ class ArtistImageTest extends TestCase
|
|||
|
||||
$this->putAsUser('api/artist/9999/image', [
|
||||
'image' => 'data:image/jpeg;base64,Rm9v',
|
||||
], factory(User::class)->create())
|
||||
], User::factory()->create())
|
||||
->assertStatus(403);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ class DownloadTest extends TestCase
|
|||
$song = Song::first();
|
||||
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->downloadService
|
||||
->shouldReceive('from')
|
||||
|
@ -67,7 +67,7 @@ class DownloadTest extends TestCase
|
|||
public function testDownloadMultipleSongs(): void
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$songs = Song::take(2)->orderBy('id')->get();
|
||||
|
||||
|
@ -94,7 +94,7 @@ class DownloadTest extends TestCase
|
|||
$album = Album::first();
|
||||
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->downloadService
|
||||
->shouldReceive('from')
|
||||
|
@ -113,7 +113,7 @@ class DownloadTest extends TestCase
|
|||
$artist = Artist::first();
|
||||
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->downloadService
|
||||
->shouldReceive('from')
|
||||
|
@ -130,10 +130,10 @@ class DownloadTest extends TestCase
|
|||
public function testDownloadPlaylist(): void
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
/** @var Playlist $playlist */
|
||||
$playlist = factory(Playlist::class)->create([
|
||||
$playlist = Playlist::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
|
@ -152,10 +152,10 @@ class DownloadTest extends TestCase
|
|||
public function testNonOwnerCannotDownloadPlaylist(): void
|
||||
{
|
||||
/** @var Playlist $playlist */
|
||||
$playlist = factory(Playlist::class)->create();
|
||||
$playlist = Playlist::factory()->create();
|
||||
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->get("download/playlist/{$playlist->id}?api_token=".$user->createToken('Koel')->plainTextToken)
|
||||
->assertStatus(Response::HTTP_FORBIDDEN);
|
||||
|
@ -164,7 +164,7 @@ class DownloadTest extends TestCase
|
|||
public function testDownloadFavorites(): void
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
$favorites = Collection::make();
|
||||
|
||||
static::mockIocDependency(InteractionRepository::class)
|
||||
|
|
|
@ -22,7 +22,7 @@ class InteractionTest extends TestCase
|
|||
public function play_count_is_increased(): void
|
||||
{
|
||||
$this->withoutEvents();
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$song = Song::orderBy('id')->first();
|
||||
$this->postAsUser('api/interaction/play', ['song' => $song->id], $user);
|
||||
|
@ -52,7 +52,7 @@ class InteractionTest extends TestCase
|
|||
{
|
||||
$this->expectsEvents(SongLikeToggled::class);
|
||||
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$song = Song::orderBy('id')->first();
|
||||
$this->postAsUser('api/interaction/like', ['song' => $song->id], $user);
|
||||
|
@ -82,7 +82,7 @@ class InteractionTest extends TestCase
|
|||
{
|
||||
$this->expectsEvents(SongLikeToggled::class);
|
||||
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$songs = Song::orderBy('id')->take(2)->get();
|
||||
$songIds = array_pluck($songs->toArray(), 'id');
|
||||
|
|
|
@ -29,7 +29,7 @@ class LastfmTest extends TestCase
|
|||
public function testSetSessionKey(): void
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
$this->postAsUser('api/lastfm/session-key', ['key' => 'foo'], $user)
|
||||
->assertStatus(204);
|
||||
|
||||
|
@ -39,7 +39,7 @@ class LastfmTest extends TestCase
|
|||
public function testConnectToLastfm(): void
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
$token = $user->createToken('Koel')->plainTextToken;
|
||||
|
||||
$temporaryToken = Mockery::mock(NewAccessToken::class);
|
||||
|
@ -65,7 +65,7 @@ class LastfmTest extends TestCase
|
|||
public function testCallback(): void
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
$token = $user->createToken('Koel')->plainTextToken;
|
||||
|
||||
self::assertNotNull(PersonalAccessToken::findToken($token));
|
||||
|
@ -88,7 +88,7 @@ class LastfmTest extends TestCase
|
|||
public function testRetrieveAndStoreSessionKey(): void
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$lastfm = static::mockIocDependency(LastfmService::class);
|
||||
$lastfm->shouldReceive('getSessionKey')
|
||||
|
@ -110,7 +110,7 @@ class LastfmTest extends TestCase
|
|||
public function testDisconnectUser(): void
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create(['preferences' => ['lastfm_session_key' => 'bar']]);
|
||||
$user = User::factory()->create(['preferences' => ['lastfm_session_key' => 'bar']]);
|
||||
$this->deleteAsUser('api/lastfm/disconnect', [], $user);
|
||||
$user->refresh();
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ use App\Models\Artist;
|
|||
use App\Models\Song;
|
||||
use App\Services\FileSynchronizer;
|
||||
use App\Services\MediaSyncService;
|
||||
use Exception;
|
||||
use getID3;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
|
||||
|
@ -23,15 +22,11 @@ class MediaSyncTest extends TestCase
|
|||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->mediaService = app(MediaSyncService::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function songs_can_be_synced(): void
|
||||
public function testSync(): void
|
||||
{
|
||||
$this->expectsEvents(LibraryChanged::class);
|
||||
|
||||
|
@ -92,12 +87,7 @@ class MediaSyncTest extends TestCase
|
|||
self::assertEquals($currentCover, Album::find($album->id)->cover);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function songs_can_be_force_synced(): void
|
||||
public function testForceSync(): void
|
||||
{
|
||||
$this->expectsEvents(LibraryChanged::class);
|
||||
|
||||
|
@ -130,12 +120,7 @@ class MediaSyncTest extends TestCase
|
|||
self::assertEquals($originalLyrics, $song->lyrics);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function songs_can_be_synced_with_selectively_tags(): void
|
||||
public function testSelectiveSync(): void
|
||||
{
|
||||
$this->expectsEvents(LibraryChanged::class);
|
||||
|
||||
|
@ -159,12 +144,7 @@ class MediaSyncTest extends TestCase
|
|||
self::assertEquals('Booom Wroooom', $song->lyrics);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function all_tags_are_catered_for_if_syncing_new_file(): void
|
||||
public function testSyncAllTagsForNewFiles(): void
|
||||
{
|
||||
// First we sync the test directory to get the data
|
||||
$this->mediaService->sync($this->mediaPath);
|
||||
|
@ -184,28 +164,17 @@ class MediaSyncTest extends TestCase
|
|||
self::assertEquals($song, $addedSong);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function added_song_is_synced_when_watching(): void
|
||||
public function testSyncAddedSongViaWatch(): void
|
||||
{
|
||||
$this->expectsEvents(LibraryChanged::class);
|
||||
|
||||
$path = $this->mediaPath.'/blank.mp3';
|
||||
|
||||
$this->mediaService->syncByWatchRecord(new InotifyWatchRecord("CLOSE_WRITE,CLOSE $path"));
|
||||
|
||||
self::assertDatabaseHas('songs', ['path' => $path]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function deleted_song_is_synced_when_watching(): void
|
||||
public function testSyncDeletedSongViaWatch(): void
|
||||
{
|
||||
$this->expectsEvents(LibraryChanged::class);
|
||||
|
||||
|
@ -217,12 +186,7 @@ class MediaSyncTest extends TestCase
|
|||
self::assertDatabaseMissing('songs', ['id' => $song->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function deleted_directory_is_synced_when_watching(): void
|
||||
public function testSyncDeletedDirectoryViaWatch(): void
|
||||
{
|
||||
$this->expectsEvents(LibraryChanged::class);
|
||||
|
||||
|
@ -235,8 +199,7 @@ class MediaSyncTest extends TestCase
|
|||
self::assertDatabaseMissing('songs', ['path' => $this->mediaPath.'/subdir/back-in-black.mp3']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function html_entities_in_tags_are_recognized_and_saved_properly(): void
|
||||
public function testHtmlEntities(): void
|
||||
{
|
||||
static::mockIocDependency(getID3::class, [
|
||||
'analyze' => [
|
||||
|
@ -261,12 +224,7 @@ class MediaSyncTest extends TestCase
|
|||
self::assertEquals('水谷広実', $info['title']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function hidden_files_can_optionally_be_ignored_when_syncing(): void
|
||||
public function testOptionallyIgnoreHiddenFiles(): void
|
||||
{
|
||||
config(['koel.ignore_dot_files' => false]);
|
||||
$this->mediaService->sync($this->mediaPath);
|
||||
|
|
|
@ -14,6 +14,7 @@ class S3Test extends TestCase
|
|||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->disableMiddlewareForAllTests();
|
||||
}
|
||||
|
||||
|
@ -39,7 +40,7 @@ class S3Test extends TestCase
|
|||
{
|
||||
$this->expectsEvents(LibraryChanged::class);
|
||||
|
||||
factory(Song::class)->create([
|
||||
Song::factory()->create([
|
||||
'path' => 's3://koel/sample.mp3',
|
||||
]);
|
||||
|
||||
|
|
|
@ -11,13 +11,14 @@ class PlaylistTest extends TestCase
|
|||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
static::createSampleMediaSet();
|
||||
}
|
||||
|
||||
public function testCreatingPlaylist(): void
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
$songs = Song::orderBy('id')->take(3)->get();
|
||||
|
||||
$this->postAsUser('api/playlist', [
|
||||
|
@ -44,10 +45,10 @@ class PlaylistTest extends TestCase
|
|||
public function testUpdatePlaylistName(): void
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
/** @var Playlist $playlist */
|
||||
$playlist = factory(Playlist::class)->create([
|
||||
$playlist = Playlist::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
'name' => 'Foo',
|
||||
]);
|
||||
|
@ -60,7 +61,7 @@ class PlaylistTest extends TestCase
|
|||
public function testNonOwnerCannotUpdatePlaylist(): void
|
||||
{
|
||||
/** @var Playlist $playlist */
|
||||
$playlist = factory(Playlist::class)->create([
|
||||
$playlist = Playlist::factory()->create([
|
||||
'name' => 'Foo',
|
||||
]);
|
||||
|
||||
|
@ -71,10 +72,10 @@ class PlaylistTest extends TestCase
|
|||
public function testSyncPlaylist(): void
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
/** @var Playlist $playlist */
|
||||
$playlist = factory(Playlist::class)->create([
|
||||
$playlist = Playlist::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
|
@ -104,10 +105,10 @@ class PlaylistTest extends TestCase
|
|||
public function testDeletePlaylist(): void
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
/** @var Playlist $playlist */
|
||||
$playlist = factory(Playlist::class)->create([
|
||||
$playlist = Playlist::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
|
@ -118,7 +119,7 @@ class PlaylistTest extends TestCase
|
|||
public function testNonOwnerCannotDeletePlaylist(): void
|
||||
{
|
||||
/** @var Playlist $playlist */
|
||||
$playlist = factory(Playlist::class)->create();
|
||||
$playlist = Playlist::factory()->create();
|
||||
|
||||
$this->deleteAsUser("api/playlist/{$playlist->id}")
|
||||
->assertStatus(403);
|
||||
|
@ -127,14 +128,14 @@ class PlaylistTest extends TestCase
|
|||
public function testGetPlaylist(): void
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
/** @var Playlist $playlist */
|
||||
$playlist = factory(Playlist::class)->create([
|
||||
$playlist = Playlist::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$songs = factory(Song::class, 2)->create();
|
||||
$songs = Song::factory(2)->create();
|
||||
$playlist->songs()->saveMany($songs);
|
||||
|
||||
$this->getAsUser("api/playlist/{$playlist->id}/songs", $user)
|
||||
|
|
|
@ -4,11 +4,9 @@ namespace Tests\Feature;
|
|||
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Hashing\Hasher;
|
||||
use Mockery\MockInterface;
|
||||
|
||||
class ProfileTest extends TestCase
|
||||
{
|
||||
/** @var MockInterface */
|
||||
private $hash;
|
||||
|
||||
public function setUp(): void
|
||||
|
@ -20,7 +18,7 @@ class ProfileTest extends TestCase
|
|||
|
||||
public function testUpdateProfileWithoutPassword(): void
|
||||
{
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->hash->shouldReceive('make')->never();
|
||||
|
||||
|
@ -32,7 +30,7 @@ class ProfileTest extends TestCase
|
|||
public function testUpdateProfileWithPassword(): void
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->hash
|
||||
->shouldReceive('make')
|
||||
|
|
|
@ -5,21 +5,17 @@ namespace Tests\Feature;
|
|||
use App\Models\Song;
|
||||
use App\Models\User;
|
||||
use App\Services\LastfmService;
|
||||
use Exception;
|
||||
|
||||
class ScrobbleTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testLastfmScrobble()
|
||||
public function testLastfmScrobble(): void
|
||||
{
|
||||
$this->withoutEvents();
|
||||
static::createSampleMediaSet();
|
||||
|
||||
$song = Song::first();
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
$user->setPreference('lastfm_session_key', 'foo');
|
||||
|
||||
$timestamp = time();
|
||||
|
|
|
@ -13,6 +13,7 @@ class SettingTest extends TestCase
|
|||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->mediaSyncService = static::mockIocDependency(MediaSyncService::class);
|
||||
}
|
||||
|
||||
|
@ -20,7 +21,7 @@ class SettingTest extends TestCase
|
|||
{
|
||||
$this->mediaSyncService->shouldReceive('sync')->once();
|
||||
|
||||
$user = factory(User::class)->states('admin')->create();
|
||||
$user = User::factory()->admin()->create();
|
||||
$this->postAsUser('/api/settings', ['media_path' => __DIR__], $user);
|
||||
|
||||
self::assertEquals(__DIR__, Setting::get('media_path'));
|
||||
|
|
|
@ -7,13 +7,9 @@ use App\Models\Album;
|
|||
use App\Models\Artist;
|
||||
use App\Models\Song;
|
||||
use App\Models\User;
|
||||
use Exception;
|
||||
|
||||
class SongTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
@ -21,15 +17,12 @@ class SongTest extends TestCase
|
|||
static::createSampleMediaSet();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testSingleUpdateAllInfoNoCompilation(): void
|
||||
{
|
||||
$this->expectsEvents(LibraryChanged::class);
|
||||
$song = Song::orderBy('id', 'desc')->first();
|
||||
|
||||
$user = factory(User::class)->states('admin')->create();
|
||||
$user = User::factory()->admin()->create();
|
||||
$this->putAsUser('/api/songs', [
|
||||
'songs' => [$song->id],
|
||||
'data' => [
|
||||
|
@ -62,7 +55,7 @@ class SongTest extends TestCase
|
|||
$song = Song::orderBy('id', 'desc')->first();
|
||||
$originalArtistId = $song->album->artist->id;
|
||||
|
||||
$user = factory(User::class)->states('admin')->create();
|
||||
$user = User::factory()->admin()->create();
|
||||
$this->putAsUser('/api/songs', [
|
||||
'songs' => [$song->id],
|
||||
'data' => [
|
||||
|
@ -87,7 +80,7 @@ class SongTest extends TestCase
|
|||
{
|
||||
$songIds = Song::orderBy('id', 'desc')->take(3)->pluck('id')->toArray();
|
||||
|
||||
$user = factory(User::class)->states('admin')->create();
|
||||
$user = User::factory()->admin()->create();
|
||||
$this->putAsUser('/api/songs', [
|
||||
'songs' => $songIds,
|
||||
'data' => [
|
||||
|
@ -124,7 +117,7 @@ class SongTest extends TestCase
|
|||
$originalSongs = Song::orderBy('id', 'desc')->take(3)->get();
|
||||
$songIds = $originalSongs->pluck('id')->toArray();
|
||||
|
||||
$user = factory(User::class)->states('admin')->create();
|
||||
$user = User::factory()->admin()->create();
|
||||
$this->putAsUser('/api/songs', [
|
||||
'songs' => $songIds,
|
||||
'data' => [
|
||||
|
@ -159,7 +152,7 @@ class SongTest extends TestCase
|
|||
{
|
||||
$song = Song::orderBy('id', 'desc')->first();
|
||||
|
||||
$user = factory(User::class)->states('admin')->create();
|
||||
$user = User::factory()->admin()->create();
|
||||
$this->putAsUser('/api/songs', [
|
||||
'songs' => [$song->id],
|
||||
'data' => [
|
||||
|
|
|
@ -10,7 +10,7 @@ abstract class TestCase extends BaseTestCase
|
|||
{
|
||||
private function jsonAsUser(?User $user, string $method, $uri, array $data = [], array $headers = []): TestResponse
|
||||
{
|
||||
$user = $user ?: factory(User::class)->create();
|
||||
$user = $user ?: User::factory()->create();
|
||||
$headers['X-Requested-With'] = 'XMLHttpRequest';
|
||||
$headers['Authorization'] = 'Bearer '.$user->createToken('koel')->plainTextToken;
|
||||
|
||||
|
|
|
@ -10,18 +10,15 @@ use App\Models\Song;
|
|||
use App\Models\User;
|
||||
use App\Services\UploadService;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Mockery\MockInterface;
|
||||
|
||||
class UploadTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var MockInterface
|
||||
*/
|
||||
private $uploadService;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->uploadService = $this->mockIocDependency(UploadService::class);
|
||||
}
|
||||
|
||||
|
@ -38,7 +35,7 @@ class UploadTest extends TestCase
|
|||
$this->postAsUser(
|
||||
'/api/upload',
|
||||
['file' => $file],
|
||||
factory(User::class)->create()
|
||||
User::factory()->create()
|
||||
)->assertStatus(403);
|
||||
}
|
||||
|
||||
|
@ -50,9 +47,7 @@ class UploadTest extends TestCase
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideUploadExceptions
|
||||
*/
|
||||
/** @dataProvider provideUploadExceptions */
|
||||
public function testPostShouldFail(string $exceptionClass, int $statusCode): void
|
||||
{
|
||||
$this->doesntExpectEvents(MediaCacheObsolete::class);
|
||||
|
@ -67,7 +62,7 @@ class UploadTest extends TestCase
|
|||
$this->postAsUser(
|
||||
'/api/upload',
|
||||
['file' => $file],
|
||||
factory(User::class)->states('admin')->create()
|
||||
User::factory()->admin()->create()
|
||||
)->assertStatus($statusCode);
|
||||
}
|
||||
|
||||
|
@ -77,7 +72,7 @@ class UploadTest extends TestCase
|
|||
$this->expectsEvents(MediaCacheObsolete::class);
|
||||
$file = UploadedFile::fake()->create('foo.mp3', 2048);
|
||||
/** @var Song $song */
|
||||
$song = factory(Song::class)->create();
|
||||
$song = Song::factory()->create();
|
||||
$this->uploadService
|
||||
->shouldReceive('handleUploadedFile')
|
||||
->once()
|
||||
|
@ -87,7 +82,7 @@ class UploadTest extends TestCase
|
|||
$this->postAsUser(
|
||||
'/api/upload',
|
||||
['file' => $file],
|
||||
factory(User::class)->states('admin')->create()
|
||||
User::factory()->admin()->create()
|
||||
)->assertJsonStructure([
|
||||
'album',
|
||||
'artist',
|
||||
|
|
|
@ -4,16 +4,15 @@ namespace Tests\Feature;
|
|||
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Hashing\Hasher;
|
||||
use Mockery\MockInterface;
|
||||
|
||||
class UserTest extends TestCase
|
||||
{
|
||||
/** @var MockInterface */
|
||||
private $hash;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->hash = static::mockIocDependency(Hasher::class);
|
||||
}
|
||||
|
||||
|
@ -40,7 +39,7 @@ class UserTest extends TestCase
|
|||
'email' => 'bar@baz.com',
|
||||
'password' => 'qux',
|
||||
'is_admin' => true,
|
||||
], factory(User::class)->states('admin')->create());
|
||||
], User::factory()->admin()->create());
|
||||
|
||||
self::assertDatabaseHas('users', [
|
||||
'name' => 'Foo',
|
||||
|
@ -53,7 +52,7 @@ class UserTest extends TestCase
|
|||
public function testAdminUpdatesUser(): void
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create([
|
||||
$user = User::factory()->create([
|
||||
'name' => 'John',
|
||||
'email' => 'john@doe.com',
|
||||
'password' => 'nope',
|
||||
|
@ -71,7 +70,7 @@ class UserTest extends TestCase
|
|||
'email' => 'bar@baz.com',
|
||||
'password' => 'qux',
|
||||
'is_admin' => false,
|
||||
], factory(User::class)->states('admin')->create());
|
||||
], User::factory()->admin()->create());
|
||||
|
||||
self::assertDatabaseHas('users', [
|
||||
'id' => $user->id,
|
||||
|
@ -85,8 +84,8 @@ class UserTest extends TestCase
|
|||
public function testAdminDeletesUser(): void
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create();
|
||||
$admin = factory(User::class)->states('admin')->create();
|
||||
$user = User::factory()->create();
|
||||
$admin = User::factory()->admin()->create();
|
||||
|
||||
$this->deleteAsUser("api/user/{$user->id}", [], $admin);
|
||||
self::assertDatabaseMissing('users', ['id' => $user->id]);
|
||||
|
@ -95,7 +94,7 @@ class UserTest extends TestCase
|
|||
public function testSeppukuNotAllowed(): void
|
||||
{
|
||||
/** @var User $admin */
|
||||
$admin = factory(User::class)->states('admin')->create();
|
||||
$admin = User::factory()->admin()->create();
|
||||
|
||||
// A user can't delete himself
|
||||
$this->deleteAsUser("api/user/{$admin->id}", [], $admin)
|
||||
|
@ -106,7 +105,7 @@ class UserTest extends TestCase
|
|||
|
||||
public function testUpdateUserProfile(): void
|
||||
{
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
self::assertNull($user->getPreference('foo'));
|
||||
|
||||
$user->setPreference('foo', 'bar');
|
||||
|
|
|
@ -4,13 +4,10 @@ namespace Tests\Feature;
|
|||
|
||||
use App\Models\Song;
|
||||
use App\Services\YouTubeService;
|
||||
use Exception;
|
||||
use Mockery;
|
||||
use Mockery\MockInterface;
|
||||
|
||||
class YouTubeTest extends TestCase
|
||||
{
|
||||
/** @var MockInterface */
|
||||
private $youTubeService;
|
||||
|
||||
public function setUp(): void
|
||||
|
@ -20,9 +17,6 @@ class YouTubeTest extends TestCase
|
|||
$this->youTubeService = static::mockIocDependency(YouTubeService::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testSearchYouTubeVideos(): void
|
||||
{
|
||||
static::createSampleMediaSet();
|
||||
|
|
|
@ -28,7 +28,7 @@ class StreamerFactoryTest extends TestCase
|
|||
public function testCreateS3Streamer(): void
|
||||
{
|
||||
/** @var Song $song */
|
||||
$song = factory(Song::class)->make(['path' => 's3://bucket/foo.mp3']);
|
||||
$song = Song::factory()->make(['path' => 's3://bucket/foo.mp3']);
|
||||
|
||||
self::assertInstanceOf(S3Streamer::class, $this->streamerFactory->createStreamer($song));
|
||||
}
|
||||
|
@ -41,8 +41,9 @@ class StreamerFactoryTest extends TestCase
|
|||
|
||||
/** @var StreamerFactory $streamerFactory */
|
||||
$streamerFactory = app(StreamerFactory::class);
|
||||
|
||||
/** @var Song $song */
|
||||
$song = factory(Song::class)->make();
|
||||
$song = Song::factory()->make();
|
||||
self::assertInstanceOf(TranscodingStreamer::class, $streamerFactory->createStreamer($song, null));
|
||||
}
|
||||
|
||||
|
@ -55,7 +56,7 @@ class StreamerFactoryTest extends TestCase
|
|||
/** @var StreamerFactory $streamerFactory */
|
||||
$streamerFactory = app(StreamerFactory::class);
|
||||
|
||||
$song = factory(Song::class)->make();
|
||||
$song = Song::factory()->make();
|
||||
self::assertInstanceOf(TranscodingStreamer::class, $streamerFactory->createStreamer($song, true));
|
||||
}
|
||||
|
||||
|
@ -85,7 +86,7 @@ class StreamerFactoryTest extends TestCase
|
|||
/** @var StreamerFactory $streamerFactory */
|
||||
$streamerFactory = app(StreamerFactory::class);
|
||||
|
||||
$song = factory(Song::class)->make();
|
||||
$song = Song::factory()->make();
|
||||
self::assertInstanceOf($expectedClass, $streamerFactory->createStreamer($song));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ class DownloadAlbumCoverTest extends TestCase
|
|||
|
||||
public function testHandle(): void
|
||||
{
|
||||
$album = factory(Album::class)->make(['cover' => null]);
|
||||
$album = Album::factory()->make(['cover' => null]);
|
||||
$event = new AlbumInformationFetched($album, ['image' => 'https://foo.bar/baz.jpg']);
|
||||
|
||||
$this->mediaMetaDataService
|
||||
|
|
|
@ -24,7 +24,7 @@ class DownloadArtistImageTest extends TestCase
|
|||
|
||||
public function testHandle(): void
|
||||
{
|
||||
$artist = factory(Artist::class)->make(['image' => null]);
|
||||
$artist = Artist::factory()->make(['image' => null]);
|
||||
$event = new ArtistInformationFetched($artist, ['image' => 'https://foo.bar/baz.jpg']);
|
||||
|
||||
$this->mediaMetaDataService
|
||||
|
|
|
@ -24,7 +24,7 @@ class LoveTrackOnLastfmTest extends TestCase
|
|||
{
|
||||
static::createSampleMediaSet();
|
||||
|
||||
$user = factory(User::class)->create(['preferences' => ['lastfm_session_key' => 'bar']]);
|
||||
$user = User::factory()->create(['preferences' => ['lastfm_session_key' => 'bar']]);
|
||||
|
||||
$interaction = Interaction::create([
|
||||
'user_id' => $user->id,
|
||||
|
|
|
@ -19,7 +19,7 @@ class UpdateLastfmNowPlayingTest extends TestCase
|
|||
{
|
||||
static::createSampleMediaSet();
|
||||
|
||||
$user = factory(User::class)->create(['preferences' => ['lastfm_session_key' => 'bar']]);
|
||||
$user = User::factory()->create(['preferences' => ['lastfm_session_key' => 'bar']]);
|
||||
$song = Song::first();
|
||||
|
||||
$queue = Queue::fake();
|
||||
|
|
|
@ -8,64 +8,45 @@ use Tests\TestCase;
|
|||
|
||||
class AlbumTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function exist_album_can_be_retrieved_using_artist_and_name()
|
||||
public function testExistingAlbumCanBeRetrievedUsingArtistAndName(): void
|
||||
{
|
||||
// Given there's an existing album from an artist
|
||||
/** @var Artist $artist */
|
||||
$artist = factory(Artist::class)->create();
|
||||
/** @var Album $album */
|
||||
$album = factory(Album::class)->create([
|
||||
'artist_id' => $artist->id,
|
||||
]);
|
||||
$album = Album::factory()->create();
|
||||
|
||||
// When I try to get the album by artist and name
|
||||
$gottenAlbum = Album::get($artist, $album->name);
|
||||
|
||||
// Then I get the album
|
||||
self::assertSame($album->id, $gottenAlbum->id);
|
||||
self::assertTrue(Album::getOrCreate($album->artist, $album->name)->is($album));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function new_album_can_be_created_using_artist_and_name()
|
||||
public function testNewAlbumIsAutomaticallyCreatedWithArtistAndName(): void
|
||||
{
|
||||
// Given an artist and an album name
|
||||
$artist = factory(Artist::class)->create();
|
||||
/** @var Artist $artist */
|
||||
$artist = Artist::factory()->create();
|
||||
$name = 'Foo';
|
||||
|
||||
// And an album with such details doesn't exist yet
|
||||
self::assertNull(Album::whereArtistIdAndName($artist->id, $name)->first());
|
||||
|
||||
// When I try to get the album by such artist and name
|
||||
$album = Album::get($artist, $name);
|
||||
|
||||
// Then I get the new album
|
||||
self::assertNotNull($album);
|
||||
$album = Album::getOrCreate($artist, $name);
|
||||
self::assertSame('Foo', $album->name);
|
||||
self::assertTrue($album->artist->is($artist));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function new_album_without_a_name_is_created_as_unknown_album()
|
||||
public function provideEmptyAlbumNames(): array
|
||||
{
|
||||
// Given an album without a name
|
||||
$name = '';
|
||||
|
||||
// When we create such an album
|
||||
$album = Album::get(factory(Artist::class)->create(), $name);
|
||||
|
||||
// Then the album's name is "Unknown Album"
|
||||
self::assertEquals('Unknown Album', $album->name);
|
||||
return [
|
||||
[''],
|
||||
[' '],
|
||||
[null],
|
||||
[false],
|
||||
];
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function new_album_is_created_with_artist_as_various_if_is_compilation_flag_is_true()
|
||||
/** @dataProvider provideEmptyAlbumNames */
|
||||
public function testNewAlbumWithoutNameIsCreatedAsUnknownAlbum($name): void
|
||||
{
|
||||
// Given we create a new album with $isCompilation flag set to TRUE
|
||||
$isCompilation = true;
|
||||
self::assertEquals('Unknown Album', Album::getOrCreate(Artist::factory()->create(), $name)->name);
|
||||
}
|
||||
|
||||
// When the album is created
|
||||
$album = Album::get(factory(Artist::class)->create(), 'Foo', $isCompilation);
|
||||
|
||||
// Then its artist is Various Artist
|
||||
self::assertTrue($album->artist->is_various);
|
||||
public function testNewAlbumIsCreatedWithArtistAsVariousIfIsCompilationFlagIsTrue(): void
|
||||
{
|
||||
self::assertTrue(Album::getOrCreate(Artist::factory()->create(), 'Foo', true)->artist->is_various);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,60 +7,41 @@ use Tests\TestCase;
|
|||
|
||||
class ArtistTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function existing_artist_can_be_retrieved_using_name()
|
||||
public function testExistingArtistCanBeRetrievedUsingName(): void
|
||||
{
|
||||
// Given an existing artist with a name
|
||||
/** @var Artist $artist */
|
||||
$artist = factory(Artist::class)->create(['name' => 'Foo']);
|
||||
$artist = Artist::factory()->create(['name' => 'Foo']);
|
||||
|
||||
// When I get the artist by name
|
||||
$gottenArtist = Artist::get('Foo');
|
||||
|
||||
// Then I get the artist
|
||||
self::assertEquals($artist->id, $gottenArtist->id);
|
||||
self::assertTrue(Artist::getOrCreate('Foo')->is($artist));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function new_artist_can_be_created_using_name()
|
||||
public function testNewArtistIsCreatedWithName(): void
|
||||
{
|
||||
// Given an artist name
|
||||
$name = 'Foo';
|
||||
|
||||
// And an artist with such a name doesn't exist yet
|
||||
self::assertNull(Artist::whereName($name)->first());
|
||||
|
||||
// When I get the artist by name
|
||||
$artist = Artist::get($name);
|
||||
|
||||
// Then I get the newly created artist
|
||||
self::assertInstanceOf(Artist::class, $artist);
|
||||
self::assertNull(Artist::whereName('Foo')->first());
|
||||
self::assertSame('Foo', Artist::getOrCreate('Foo')->name);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function getting_artist_with_empty_name_returns_unknown_artist()
|
||||
public function provideEmptyNames(): array
|
||||
{
|
||||
// Given an empty name
|
||||
$name = '';
|
||||
|
||||
// When I get the artist by the empty name
|
||||
$artist = Artist::get($name);
|
||||
|
||||
// Then I get the artist as Unknown Artist
|
||||
self::assertTrue($artist->is_unknown);
|
||||
return [
|
||||
[''],
|
||||
[' '],
|
||||
[null],
|
||||
[false],
|
||||
];
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function artists_with_name_in_utf16_encoding_are_retrieved_correctly()
|
||||
/** @dataProvider provideEmptyNames */
|
||||
public function testGettingArtistWithEmptyNameReturnsUnknownArtist($name): void
|
||||
{
|
||||
self::assertTrue(Artist::getOrCreate($name)->is_unknown);
|
||||
}
|
||||
|
||||
public function testArtistsWithNameInUtf16EncodingAreRetrievedCorrectly(): void
|
||||
{
|
||||
// Given there's an artist with name in UTF-16 encoding
|
||||
$name = file_get_contents(__DIR__.'../../../blobs/utf16');
|
||||
$artist = Artist::get($name);
|
||||
$artist = Artist::getOrCreate($name);
|
||||
|
||||
// When I get the artist using the name
|
||||
$retrieved = Artist::get($name);
|
||||
|
||||
// Then I receive the artist
|
||||
self::assertEquals($artist->id, $retrieved->id);
|
||||
self::assertTrue(Artist::getOrCreate($name)->is($artist));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,36 +7,25 @@ use Tests\TestCase;
|
|||
|
||||
class SettingTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function it_sets_a_key_value_pair()
|
||||
public function testSetsKeyValuePair(): void
|
||||
{
|
||||
// Given a key-value pair
|
||||
$key = 'foo';
|
||||
$value = 'bar';
|
||||
Setting::set('foo', 'bar');
|
||||
|
||||
// When I call the method to save the key-value
|
||||
Setting::set($key, $value);
|
||||
|
||||
// Then I see the key and serialized value in the database
|
||||
self::assertDatabaseHas('settings', [
|
||||
'key' => 'foo',
|
||||
'value' => serialize('bar'),
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_supports_associative_arrays_when_saving_settings()
|
||||
public function testSupportAssociativeArray(): void
|
||||
{
|
||||
// Given an associative array of multiple settings
|
||||
$settings = [
|
||||
'foo' => 'bar',
|
||||
'baz' => 'qux',
|
||||
];
|
||||
|
||||
// When I call the method to save the settings
|
||||
Setting::set($settings);
|
||||
|
||||
// Then I see all settings the database
|
||||
self::assertDatabaseHas('settings', [
|
||||
'key' => 'foo',
|
||||
'value' => serialize('bar'),
|
||||
|
@ -46,8 +35,7 @@ class SettingTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function existing_settings_should_be_updated()
|
||||
public function testUpdateSettings(): void
|
||||
{
|
||||
Setting::set('foo', 'bar');
|
||||
Setting::set('foo', 'baz');
|
||||
|
@ -55,19 +43,13 @@ class SettingTest extends TestCase
|
|||
self::assertEquals('baz', Setting::get('foo'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_gets_the_setting_value_in_an_unserialized_format()
|
||||
public function testGetSettings(): void
|
||||
{
|
||||
// Given a setting in the database
|
||||
factory(Setting::class)->create([
|
||||
Setting::factory()->create([
|
||||
'key' => 'foo',
|
||||
'value' => 'bar',
|
||||
]);
|
||||
|
||||
// When I get the setting using the key
|
||||
$value = Setting::get('foo');
|
||||
|
||||
// Then I receive the value in an unserialized format
|
||||
self::assertSame('bar', $value);
|
||||
self::assertSame('bar', Setting::get('foo'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,33 +7,21 @@ use Tests\TestCase;
|
|||
|
||||
class SongTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function its_lyrics_has_all_new_line_characters_replace_by_br_tags()
|
||||
public function testLyricsHaveNewlinesReplacedByBrTags()
|
||||
{
|
||||
// Given a song with lyrics contains new line characters
|
||||
/** @var Song $song */
|
||||
$song = factory(Song::class)->create([
|
||||
$song = Song::factory()->create([
|
||||
'lyrics' => "foo\rbar\nbaz\r\nqux",
|
||||
]);
|
||||
|
||||
// When I retrieve its lyrics
|
||||
$lyrics = $song->lyrics;
|
||||
|
||||
// Then I see the new line characters replaced by <br />
|
||||
self::assertEquals('foo<br />bar<br />baz<br />qux', $lyrics);
|
||||
self::assertEquals('foo<br />bar<br />baz<br />qux', $song->lyrics);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function amazon_s3_parameters_can_be_retrieved_from_s3_hosted_songs()
|
||||
public function testGettingS3HostedSongs(): void
|
||||
{
|
||||
// Given a song hosted on S3
|
||||
/** @var Song $song */
|
||||
$song = factory(Song::class)->create(['path' => 's3://foo/bar']);
|
||||
$song = Song::factory()->create(['path' => 's3://foo/bar']);
|
||||
|
||||
// When I check its S3 parameters
|
||||
$params = $song->s3_params;
|
||||
|
||||
// Then I receive the correct parameters
|
||||
self::assertEquals(['bucket' => 'foo', 'key' => 'bar'], $params);
|
||||
self::assertEquals(['bucket' => 'foo', 'key' => 'bar'], $song->s3_params);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,12 +8,9 @@ use Tests\TestCase;
|
|||
|
||||
class SongZipArchiveTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function a_song_can_be_added_into_an_archive()
|
||||
public function testAddSongIntoArchive(): void
|
||||
{
|
||||
$song = factory(Song::class)->create([
|
||||
'path' => realpath(__DIR__.'/../../songs/full.mp3'),
|
||||
]);
|
||||
$song = Song::factory()->create(['path' => realpath(__DIR__.'/../../songs/full.mp3')]);
|
||||
|
||||
$songZipArchive = new SongZipArchive();
|
||||
$songZipArchive->addSong($song);
|
||||
|
@ -22,16 +19,11 @@ class SongZipArchiveTest extends TestCase
|
|||
self::assertEquals('full.mp3', $songZipArchive->getArchive()->getNameIndex(0));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function multiple_songs_can_be_added_into_an_archive()
|
||||
public function testAddMultipleSongsIntoArchive(): void
|
||||
{
|
||||
$songs = collect([
|
||||
factory(Song::class)->create([
|
||||
'path' => realpath(__DIR__.'/../../songs/full.mp3'),
|
||||
]),
|
||||
factory(Song::class)->create([
|
||||
'path' => realpath(__DIR__.'/../../songs/lorem.mp3'),
|
||||
]),
|
||||
Song::factory()->create(['path' => realpath(__DIR__.'/../../songs/full.mp3')]),
|
||||
Song::factory()->create(['path' => realpath(__DIR__.'/../../songs/lorem.mp3')]),
|
||||
]);
|
||||
|
||||
$songZipArchive = new SongZipArchive();
|
||||
|
|
|
@ -10,7 +10,7 @@ class UserTest extends TestCase
|
|||
public function testSetUserPreferences(): void
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
$user->setPreference('foo', 'bar');
|
||||
|
||||
self::assertSame('bar', $user->preferences['foo']);
|
||||
|
@ -19,7 +19,7 @@ class UserTest extends TestCase
|
|||
public function testGetUserPreferences(): void
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create([
|
||||
$user = User::factory()->create([
|
||||
'preferences' => ['foo' => 'bar'],
|
||||
]);
|
||||
|
||||
|
@ -29,7 +29,7 @@ class UserTest extends TestCase
|
|||
public function testDeleteUserPreferences(): void
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create([
|
||||
$user = User::factory()->create([
|
||||
'preferences' => ['foo' => 'bar'],
|
||||
]);
|
||||
$user->deletePreference('foo');
|
||||
|
@ -40,7 +40,7 @@ class UserTest extends TestCase
|
|||
public function testSensitivePreferencesAreHidden(): void
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create([
|
||||
$user = User::factory()->create([
|
||||
'preferences' => ['lastfm_session_key' => 'foo'],
|
||||
]);
|
||||
|
||||
|
|
|
@ -9,14 +9,7 @@ use Tests\TestCase;
|
|||
|
||||
class SongRepositoryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var HelperService
|
||||
*/
|
||||
private $helperService;
|
||||
|
||||
/**
|
||||
* @var SongRepository
|
||||
*/
|
||||
private $songRepository;
|
||||
|
||||
public function setUp(): void
|
||||
|
@ -29,7 +22,7 @@ class SongRepositoryTest extends TestCase
|
|||
public function testGetOneByPath(): void
|
||||
{
|
||||
/** @var Song $song */
|
||||
$song = factory(Song::class)->create(['path' => 'foo']);
|
||||
$song = Song::factory()->create(['path' => 'foo']);
|
||||
self::assertSame($song->id, $this->songRepository->getOneByPath('foo')->id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
namespace Tests\Integration\Services;
|
||||
|
||||
use App\Services\ApplicationInformationService;
|
||||
use Exception;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
|
@ -14,9 +13,6 @@ use Tests\TestCase;
|
|||
|
||||
class ApplicationInformationServiceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testGetLatestVersionNumber(): void
|
||||
{
|
||||
$latestVersion = 'v1.1.2';
|
||||
|
|
|
@ -13,6 +13,7 @@ class FileSynchronizerTest extends TestCase
|
|||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->fileSynchronizer = app(FileSynchronizer::class);
|
||||
}
|
||||
|
||||
|
@ -48,9 +49,10 @@ class FileSynchronizerTest extends TestCase
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function song_without_a_title_tag_has_file_name_as_the_title(): void
|
||||
public function testSongWithoutTitleHasFileNameAsTitle(): void
|
||||
{
|
||||
$this->fileSynchronizer->setFile(__DIR__.'/../../songs/blank.mp3');
|
||||
|
||||
self::assertSame('blank', $this->fileSynchronizer->getFileInfo()['title']);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,15 +7,11 @@ use App\Models\Interaction;
|
|||
use App\Models\Song;
|
||||
use App\Models\User;
|
||||
use App\Services\InteractionService;
|
||||
use Exception;
|
||||
use Illuminate\Support\Collection;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InteractionServiceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var InteractionService
|
||||
*/
|
||||
private $interactionService;
|
||||
|
||||
public function setUp(): void
|
||||
|
@ -29,25 +25,19 @@ class InteractionServiceTest extends TestCase
|
|||
public function it_increases_a_songs_play_count(): void
|
||||
{
|
||||
/** @var Interaction $interaction */
|
||||
$interaction = factory(Interaction::class)->create();
|
||||
$interaction = Interaction::factory()->create();
|
||||
|
||||
$this->interactionService->increasePlayCount($interaction->song, $interaction->user);
|
||||
|
||||
/** @var Interaction $interaction */
|
||||
$updatedInteraction = Interaction::find($interaction->id);
|
||||
self::assertEquals($interaction->play_count + 1, $updatedInteraction->play_count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function it_toggles_like_status(): void
|
||||
public function testToggleLike(): void
|
||||
{
|
||||
$this->expectsEvents(SongLikeToggled::class);
|
||||
|
||||
$interaction = factory(Interaction::class)->create();
|
||||
$interaction = Interaction::factory()->create();
|
||||
|
||||
$this->interactionService->toggleLike($interaction->song, $interaction->user);
|
||||
|
||||
|
@ -56,45 +46,38 @@ class InteractionServiceTest extends TestCase
|
|||
self::assertNotSame($interaction->liked, $updatedInteraction->liked);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function user_can_like_multiple_songs_at_once(): void
|
||||
public function testLikeMultipleSongs(): void
|
||||
{
|
||||
$this->expectsEvents(SongLikeToggled::class);
|
||||
|
||||
/** @var Collection $songs */
|
||||
$songs = factory(Song::class, 2)->create();
|
||||
$user = factory(User::class)->create();
|
||||
$songs = Song::factory(2)->create();
|
||||
|
||||
/** @var User $user */
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->interactionService->batchLike($songs->pluck('id')->all(), $user);
|
||||
|
||||
$songs->each(static function (Song $song) use ($user) {
|
||||
$songs->each(static function (Song $song) use ($user): void {
|
||||
self::assertTrue(Interaction::whereSongIdAndUserId($song->id, $user->id)->first()->liked);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function user_can_unlike_multiple_songs_at_once(): void
|
||||
public function testUnlikeMultipleSongs(): void
|
||||
{
|
||||
$this->expectsEvents(SongLikeToggled::class);
|
||||
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
/** @var Collection $interactions */
|
||||
$interactions = factory(Interaction::class, 3)->create([
|
||||
$interactions = Interaction::factory(3)->create([
|
||||
'user_id' => $user->id,
|
||||
'liked' => true,
|
||||
]);
|
||||
|
||||
$this->interactionService->batchUnlike($interactions->pluck('song.id')->all(), $user);
|
||||
|
||||
$interactions->each(static function (Interaction $interaction) {
|
||||
$interactions->each(static function (Interaction $interaction): void {
|
||||
self::assertFalse(Interaction::find($interaction->id)->liked);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ namespace Tests\Integration\Services;
|
|||
use App\Models\Album;
|
||||
use App\Models\Artist;
|
||||
use App\Services\LastfmService;
|
||||
use Exception;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Illuminate\Contracts\Cache\Repository as Cache;
|
||||
|
@ -15,13 +14,10 @@ use Tests\TestCase;
|
|||
|
||||
class LastfmServiceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testGetArtistInformation(): void
|
||||
{
|
||||
/** @var Artist $artist */
|
||||
$artist = factory(Artist::class)->make(['name' => 'foo']);
|
||||
$artist = Artist::factory()->make(['name' => 'foo']);
|
||||
|
||||
/** @var Client $client */
|
||||
$client = Mockery::mock(Client::class, [
|
||||
|
@ -46,7 +42,7 @@ class LastfmServiceTest extends TestCase
|
|||
public function testGetArtistInformationForNonExistentArtist(): void
|
||||
{
|
||||
/** @var Artist $artist */
|
||||
$artist = factory(Artist::class)->make();
|
||||
$artist = Artist::factory()->make();
|
||||
|
||||
/** @var Client $client */
|
||||
$client = Mockery::mock(Client::class, [
|
||||
|
@ -58,14 +54,11 @@ class LastfmServiceTest extends TestCase
|
|||
self::assertNull($api->getArtistInformation($artist->name));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testGetAlbumInformation(): void
|
||||
{
|
||||
/** @var Album $album */
|
||||
$album = factory(Album::class)->create([
|
||||
'artist_id' => factory(Artist::class)->create(['name' => 'bar'])->id,
|
||||
$album = Album::factory()->create([
|
||||
'artist_id' => Artist::factory()->create(['name' => 'bar'])->id,
|
||||
'name' => 'foo',
|
||||
]);
|
||||
|
||||
|
@ -105,7 +98,7 @@ class LastfmServiceTest extends TestCase
|
|||
public function testGetAlbumInformationForNonExistentAlbum(): void
|
||||
{
|
||||
/** @var Album $album */
|
||||
$album = factory(Album::class)->create();
|
||||
$album = Album::factory()->create();
|
||||
|
||||
/** @var Client $client */
|
||||
$client = Mockery::mock(Client::class, [
|
||||
|
|
|
@ -8,19 +8,11 @@ use App\Models\Song;
|
|||
use App\Services\MediaCacheService;
|
||||
use Illuminate\Cache\Repository as Cache;
|
||||
use Mockery;
|
||||
use Mockery\MockInterface;
|
||||
use Tests\TestCase;
|
||||
|
||||
class MediaCacheServiceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var MediaCacheService
|
||||
*/
|
||||
private $mediaCacheService;
|
||||
|
||||
/**
|
||||
* @var Cache|MockInterface
|
||||
*/
|
||||
private $cache;
|
||||
|
||||
public function setUp(): void
|
||||
|
@ -33,7 +25,7 @@ class MediaCacheServiceTest extends TestCase
|
|||
|
||||
public function testGetIfCacheIsNotAvailable(): void
|
||||
{
|
||||
factory(Song::class, 5)->create();
|
||||
Song::factory(5)->create();
|
||||
|
||||
$this->cache->shouldReceive('rememberForever')->andReturn([
|
||||
'albums' => Album::orderBy('name')->get(),
|
||||
|
|
|
@ -8,40 +8,28 @@ use App\Models\Album;
|
|||
use App\Models\Artist;
|
||||
use App\Services\LastfmService;
|
||||
use App\Services\MediaInformationService;
|
||||
use Exception;
|
||||
use Mockery as m;
|
||||
use Mockery\MockInterface;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
class MediaInformationServiceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var LastfmService|MockInterface
|
||||
*/
|
||||
private $lastFmService;
|
||||
|
||||
/**
|
||||
* @var MediaInformationService
|
||||
*/
|
||||
private $mediaInformationService;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->lastFmService = m::mock(LastfmService::class);
|
||||
$this->lastFmService = Mockery::mock(LastfmService::class);
|
||||
$this->mediaInformationService = new MediaInformationService($this->lastFmService);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testGetAlbumInformation(): void
|
||||
{
|
||||
$this->expectsEvents(AlbumInformationFetched::class);
|
||||
|
||||
/** @var Album $album */
|
||||
$album = factory(Album::class)->create();
|
||||
$album = Album::factory()->create();
|
||||
|
||||
$this->lastFmService
|
||||
->shouldReceive('getAlbumInformation')
|
||||
|
@ -57,15 +45,12 @@ class MediaInformationServiceTest extends TestCase
|
|||
], $info);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testGetArtistInformation(): void
|
||||
{
|
||||
$this->expectsEvents(ArtistInformationFetched::class);
|
||||
|
||||
/** @var Artist $artist */
|
||||
$artist = factory(Artist::class)->create();
|
||||
$artist = Artist::factory()->create();
|
||||
|
||||
$this->lastFmService
|
||||
->shouldReceive('getArtistInformation')
|
||||
|
|
|
@ -13,6 +13,7 @@ class MediaMetadataServiceTest extends TestCase
|
|||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->cleanUp();
|
||||
}
|
||||
|
||||
|
@ -20,7 +21,7 @@ class MediaMetadataServiceTest extends TestCase
|
|||
{
|
||||
copy(__DIR__.'/../../blobs/cover.png', album_cover_path('album-cover-for-thumbnail-test.jpg'));
|
||||
|
||||
$album = factory(Album::class)->create(['cover' => 'album-cover-for-thumbnail-test.jpg']);
|
||||
$album = Album::factory()->create(['cover' => 'album-cover-for-thumbnail-test.jpg']);
|
||||
|
||||
self::assertSame(
|
||||
album_cover_url('album-cover-for-thumbnail-test_thumb.jpg'),
|
||||
|
@ -32,7 +33,7 @@ class MediaMetadataServiceTest extends TestCase
|
|||
|
||||
public function testGetAlbumThumbnailUrlWithNoCover(): void
|
||||
{
|
||||
$album = factory(Album::class)->create(['cover' => null]);
|
||||
$album = Album::factory()->create(['cover' => null]);
|
||||
self::assertNull(app(MediaMetadataService::class)->getAlbumThumbnailUrl($album));
|
||||
}
|
||||
|
||||
|
@ -40,8 +41,8 @@ class MediaMetadataServiceTest extends TestCase
|
|||
{
|
||||
@unlink(album_cover_path('album-cover-for-thumbnail-test.jpg'));
|
||||
@unlink(album_cover_path('album-cover-for-thumbnail-test_thumb.jpg'));
|
||||
self::assertFileNotExists(album_cover_path('album-cover-for-thumbnail-test.jpg'));
|
||||
self::assertFileNotExists(album_cover_path('album-cover-for-thumbnail-test_thumb.jpg'));
|
||||
self::assertFileDoesNotExist(album_cover_path('album-cover-for-thumbnail-test.jpg'));
|
||||
self::assertFileDoesNotExist(album_cover_path('album-cover-for-thumbnail-test_thumb.jpg'));
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
|
|
|
@ -9,29 +9,18 @@ use Aws\S3\S3ClientInterface;
|
|||
use GuzzleHttp\Psr7\Request;
|
||||
use Illuminate\Cache\Repository as Cache;
|
||||
use Mockery;
|
||||
use Mockery\MockInterface;
|
||||
use Tests\TestCase;
|
||||
|
||||
class S3ServiceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var S3ClientInterface|MockInterface
|
||||
*/
|
||||
private $s3Client;
|
||||
|
||||
/**
|
||||
* @var Cache|MockInterface
|
||||
*/
|
||||
private $cache;
|
||||
|
||||
/**
|
||||
* @var S3Service
|
||||
*/
|
||||
private $s3Service;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->s3Client = Mockery::mock(S3ClientInterface::class);
|
||||
$this->cache = Mockery::mock(Cache::class);
|
||||
$this->s3Service = new S3Service($this->s3Client, $this->cache);
|
||||
|
@ -39,7 +28,7 @@ class S3ServiceTest extends TestCase
|
|||
|
||||
public function testGetSongPublicUrl(): void
|
||||
{
|
||||
$song = factory(Song::class)->create(['path' => 's3://foo/bar']);
|
||||
$song = Song::factory()->create(['path' => 's3://foo/bar']);
|
||||
|
||||
$cmd = Mockery::mock(CommandInterface::class);
|
||||
$this->s3Client->shouldReceive('getCommand')
|
||||
|
|
|
@ -16,14 +16,9 @@ class SmartPlaylistServiceTest extends TestCase
|
|||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->service = $this->app->make(SmartPlaylistService::class);
|
||||
Carbon::setTestNow(new Carbon('2018-07-15'));
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Carbon::setTestNow();
|
||||
parent::tearDown();
|
||||
$this->service = app(SmartPlaylistService::class);
|
||||
Carbon::setTestNow(new Carbon('2018-07-15'));
|
||||
}
|
||||
|
||||
private function readFixtureFile(string $fileName): array
|
||||
|
@ -127,7 +122,7 @@ class SmartPlaylistServiceTest extends TestCase
|
|||
$rules = $this->readFixtureFile('requiresUser.json');
|
||||
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
self::assertEquals([
|
||||
'model' => 'interactions.user_id',
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
namespace Tests\Integration\Services;
|
||||
|
||||
use App\Services\YouTubeService;
|
||||
use Exception;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Illuminate\Contracts\Cache\Repository;
|
||||
|
@ -13,9 +12,6 @@ use Tests\TestCase;
|
|||
|
||||
class YouTubeServiceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testSearch(): void
|
||||
{
|
||||
$this->withoutEvents();
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
namespace Tests\Integration\Services;
|
||||
|
||||
use App\Services\iTunesService;
|
||||
use Exception;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Illuminate\Contracts\Cache\Repository as Cache;
|
||||
|
@ -13,9 +12,6 @@ use Tests\TestCase;
|
|||
|
||||
class iTunesServiceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testGetTrackUrl(): void
|
||||
{
|
||||
$term = 'Foo Bar';
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Tests;
|
|||
use App\Models\Album;
|
||||
use App\Models\Artist;
|
||||
use App\Models\Song;
|
||||
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
||||
use Exception;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||
|
@ -15,8 +16,9 @@ use Tests\Traits\SandboxesTests;
|
|||
|
||||
abstract class TestCase extends BaseTestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
use ArraySubsetAsserts;
|
||||
use CreatesApplication;
|
||||
use DatabaseTransactions;
|
||||
use InteractsWithIoc;
|
||||
use SandboxesTests;
|
||||
|
||||
|
@ -42,17 +44,17 @@ abstract class TestCase extends BaseTestCase
|
|||
protected static function createSampleMediaSet(): void
|
||||
{
|
||||
/** @var Artist $artist */
|
||||
$artist = factory(Artist::class)->create();
|
||||
$artist = Artist::factory()->create();
|
||||
|
||||
// Sample 3 albums
|
||||
/** @var Album[] $albums */
|
||||
$albums = factory(Album::class, 3)->create([
|
||||
$albums = Album::factory(3)->create([
|
||||
'artist_id' => $artist->id,
|
||||
]);
|
||||
|
||||
// 7-15 songs per albums
|
||||
foreach ($albums as $album) {
|
||||
factory(Song::class, random_int(7, 15))->create([
|
||||
Song::factory(random_int(7, 15))->create([
|
||||
'album_id' => $album->id,
|
||||
'artist_id' => $artist->id,
|
||||
]);
|
||||
|
|
|
@ -13,65 +13,35 @@ class ApplicationTest extends TestCase
|
|||
@unlink(public_path('hot'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function static_urls_without_cdn_are_constructed_correctly(): void
|
||||
public function testStaticUrlsWithoutCdnAreConstructedCorrectly(): void
|
||||
{
|
||||
// Given we are not using a CDN
|
||||
config(['koel.cdn.url' => '']);
|
||||
|
||||
// When I get the static URLs for the assets
|
||||
$root = app()->staticUrl();
|
||||
$assetURL = app()->staticUrl('/foo.css ');
|
||||
|
||||
// Then I see they're constructed correctly
|
||||
self::assertEquals('http://localhost/', $root);
|
||||
self::assertEquals('http://localhost/foo.css', $assetURL);
|
||||
self::assertEquals('http://localhost/', app()->staticUrl());
|
||||
self::assertEquals('http://localhost/foo.css', app()->staticUrl('/foo.css '));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function static_urls_with_cdn_are_constructed_correctly(): void
|
||||
public function testStaticUrlsWithCdnAreConstructedCorrectly(): void
|
||||
{
|
||||
// Given we're using a CDN
|
||||
config(['koel.cdn.url' => 'http://cdn.tld']);
|
||||
|
||||
// When I get the static URLs for the assets
|
||||
$root = app()->staticUrl();
|
||||
$assetURL = app()->staticUrl('/foo.css ');
|
||||
|
||||
// Then I see they're constructed correctly
|
||||
self::assertEquals('http://cdn.tld/', $root);
|
||||
self::assertEquals('http://cdn.tld/foo.css', $assetURL);
|
||||
self::assertEquals('http://cdn.tld/', app()->staticUrl());
|
||||
self::assertEquals('http://cdn.tld/foo.css', app()->staticUrl('/foo.css '));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function application_asset_revision_urls_are_constructed_correctly_when_not_using_cdn(): void
|
||||
public function testApplicationAssetRevisionUrlsAreConstructedCorrectlyWhenNotUsingCdn(): void
|
||||
{
|
||||
// Given we have revisioned assets in the manifest file
|
||||
$manifestFile = __DIR__.'../../blobs/rev-manifest.json';
|
||||
|
||||
// and we're not using a CDN
|
||||
config(['koel.cdn.url' => '']);
|
||||
|
||||
// When I get the static URLs for the assets
|
||||
$assetURL = app()->rev('/foo.css', $manifestFile);
|
||||
|
||||
// Then I see they're constructed correctly
|
||||
self::assertEquals('http://localhost/foo00.css', $assetURL);
|
||||
self::assertEquals('http://localhost/foo00.css', app()->rev('/foo.css', $manifestFile));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function application_asset_revision_urls_are_constructed_correctly_when_using_cdn(): void
|
||||
public function testApplicationAssetRevisionUrlsAreConstructedCorrectlyWhenUsingCdn(): void
|
||||
{
|
||||
// Given we have revisioned assets in the manifest file
|
||||
$manifestFile = __DIR__.'../../blobs/rev-manifest.json';
|
||||
|
||||
// and we're using a CDN
|
||||
config(['koel.cdn.url' => 'http://cdn.tld']);
|
||||
|
||||
// When I get the static URLs for the assets
|
||||
$assetURL = app()->rev('/foo.css', $manifestFile);
|
||||
|
||||
// Then I see they're constructed correctly
|
||||
self::assertEquals('http://cdn.tld/foo00.css', $assetURL);
|
||||
self::assertEquals('http://cdn.tld/foo00.css', app()->rev('/foo.css', $manifestFile));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,19 +6,11 @@ use App\Http\Middleware\ForceHttps;
|
|||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\UrlGenerator;
|
||||
use Mockery;
|
||||
use Mockery\MockInterface;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ForceHttpsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var UrlGenerator|MockInterface
|
||||
*/
|
||||
private $url;
|
||||
|
||||
/**
|
||||
* @var ForceHttps
|
||||
*/
|
||||
private $middleware;
|
||||
|
||||
public function setUp(): void
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace App\Tests\Unit\Jobs;
|
||||
namespace Tests\Unit\Jobs;
|
||||
|
||||
use App\Jobs\LoveTrackOnLastfmJob;
|
||||
use App\Models\Interaction;
|
||||
|
@ -11,21 +11,16 @@ use Tests\TestCase;
|
|||
|
||||
class LoveTrackOnLastfmJobTest extends TestCase
|
||||
{
|
||||
/** @var LoveTrackOnLastfmJob */
|
||||
private $job;
|
||||
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/** @var Interaction */
|
||||
private $interaction;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->user = factory(User::class)->create(['preferences' => ['lastfm_session_key' => 'foo']]);
|
||||
$this->interaction = factory(Interaction::class)->make();
|
||||
$this->user = User::factory()->create(['preferences' => ['lastfm_session_key' => 'foo']]);
|
||||
$this->interaction = Interaction::factory()->make();
|
||||
$this->job = new LoveTrackOnLastfmJob($this->user, $this->interaction);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace App\Tests\Unit\Jobs;
|
||||
namespace Tests\Unit\Jobs;
|
||||
|
||||
use App\Jobs\ScrobbleJob;
|
||||
use App\Models\Song;
|
||||
|
@ -11,21 +11,16 @@ use Tests\TestCase;
|
|||
|
||||
class ScrobbleJobTest extends TestCase
|
||||
{
|
||||
/** @var ScrobbleJob */
|
||||
private $job;
|
||||
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/** @var Song */
|
||||
private $song;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->user = factory(User::class)->create(['preferences' => ['lastfm_session_key' => 'foo']]);
|
||||
$this->song = factory(Song::class)->make();
|
||||
$this->user = User::factory()->create(['preferences' => ['lastfm_session_key' => 'foo']]);
|
||||
$this->song = Song::factory()->make();
|
||||
$this->job = new ScrobbleJob($this->user, $this->song, 100);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace App\Tests\Unit\Jobs;
|
||||
namespace Tests\Unit\Jobs;
|
||||
|
||||
use App\Jobs\UpdateLastfmNowPlayingJob;
|
||||
use App\Models\Song;
|
||||
|
@ -11,22 +11,17 @@ use Tests\TestCase;
|
|||
|
||||
class UpdateLastfmNowPlayingJobTest extends TestCase
|
||||
{
|
||||
/** @var UpdateLastfmNowPlayingJob */
|
||||
private $job;
|
||||
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/** @var Song */
|
||||
private $song;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->user = factory(User::class)->create(['preferences' => ['lastfm_session_key' => 'foo']]);
|
||||
$this->song = factory(Song::class)->make();
|
||||
$this->job = new UpdateLastfmNowPlayingJob($this->user, $this->song, 100);
|
||||
$this->user = User::factory()->create(['preferences' => ['lastfm_session_key' => 'foo']]);
|
||||
$this->song = Song::factory()->make();
|
||||
$this->job = new UpdateLastfmNowPlayingJob($this->user, $this->song);
|
||||
}
|
||||
|
||||
public function testHandle(): void
|
||||
|
|
|
@ -8,7 +8,6 @@ use Illuminate\Contracts\Cache\Repository as Cache;
|
|||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Illuminate\Log\Logger;
|
||||
use Mockery;
|
||||
use Mockery\MockInterface;
|
||||
use Tests\TestCase;
|
||||
use Tests\Unit\Stubs\ConcreteApiClient;
|
||||
|
||||
|
@ -16,13 +15,8 @@ class ApiClientTest extends TestCase
|
|||
{
|
||||
use WithoutMiddleware;
|
||||
|
||||
/** @var Cache|MockInterface */
|
||||
private $cache;
|
||||
|
||||
/** @var Client|MockInterface */
|
||||
private $client;
|
||||
|
||||
/** @var Logger|MockInterface */
|
||||
private $logger;
|
||||
|
||||
public function setUp(): void
|
||||
|
|
|
@ -10,15 +10,11 @@ use App\Services\ImageWriter;
|
|||
use App\Services\MediaMetadataService;
|
||||
use Illuminate\Log\Logger;
|
||||
use Mockery;
|
||||
use Mockery\MockInterface;
|
||||
use Tests\TestCase;
|
||||
|
||||
class MediaMetadataServiceTest extends TestCase
|
||||
{
|
||||
/** @var MediaMetadataService */
|
||||
private $mediaMetadataService;
|
||||
|
||||
/** @var ImageWriter|MockInterface */
|
||||
private $imageWriter;
|
||||
|
||||
public function setUp(): void
|
||||
|
@ -32,7 +28,7 @@ class MediaMetadataServiceTest extends TestCase
|
|||
public function testWriteAlbumCover(): void
|
||||
{
|
||||
/** @var Album $album */
|
||||
$album = factory(Album::class)->create();
|
||||
$album = Album::factory()->create();
|
||||
$coverContent = 'dummy';
|
||||
$coverPath = '/koel/public/img/album/foo.jpg';
|
||||
|
||||
|
@ -48,7 +44,7 @@ class MediaMetadataServiceTest extends TestCase
|
|||
public function testWriteArtistImage(): void
|
||||
{
|
||||
/** @var Artist $artist */
|
||||
$artist = factory(Artist::class)->create();
|
||||
$artist = Artist::factory()->create();
|
||||
$imageContent = 'dummy';
|
||||
$imagePath = '/koel/public/img/artist/foo.jpg';
|
||||
|
||||
|
|
|
@ -16,14 +16,7 @@ use Tests\TestCase;
|
|||
|
||||
class UploadServiceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var FileSynchronizer|MockInterface
|
||||
*/
|
||||
private $fileSynchronizer;
|
||||
|
||||
/**
|
||||
* @var UploadService
|
||||
*/
|
||||
private $uploadService;
|
||||
|
||||
public function setUp(): void
|
||||
|
|
Loading…
Reference in a new issue