mirror of
https://github.com/koel/koel
synced 2024-11-24 13:13:05 +00:00
0fff66ece8
* chore(deps-dev): bump filp/whoops from 2.7.0 to 2.7.1 Bumps [filp/whoops](https://github.com/filp/whoops) from 2.7.0 to 2.7.1. - [Release notes](https://github.com/filp/whoops/releases) - [Changelog](https://github.com/filp/whoops/blob/master/CHANGELOG.md) - [Commits](https://github.com/filp/whoops/compare/2.7.0...2.7.1) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> * Apply fixes from StyleCI (#1172) Co-authored-by: Phan An <me@phanan.net>
97 lines
2.4 KiB
PHP
97 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Album;
|
|
use App\Models\Artist;
|
|
use App\Models\Song;
|
|
use App\Models\User;
|
|
use Exception;
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use Laravel\BrowserKitTesting\TestCase as BaseTestCase;
|
|
use Mockery;
|
|
use Tests\CreatesApplication;
|
|
use Tests\Traits\InteractsWithIoc;
|
|
use Tymon\JWTAuth\JWTAuth;
|
|
|
|
abstract class TestCase extends BaseTestCase
|
|
{
|
|
use CreatesApplication;
|
|
use DatabaseTransactions;
|
|
use InteractsWithIoc;
|
|
/** @var JWTAuth */
|
|
private $auth;
|
|
|
|
public function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->auth = app(JWTAuth::class);
|
|
|
|
$this->prepareForTests();
|
|
}
|
|
|
|
/**
|
|
* Create a sample media set, with a complete artist+album+song trio.
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
protected function createSampleMediaSet(): void
|
|
{
|
|
$artist = factory(Artist::class)->create();
|
|
|
|
// Sample 3 albums
|
|
$albums = factory(Album::class, 3)->create([
|
|
'artist_id' => $artist->id,
|
|
]);
|
|
|
|
// 7-15 songs per albums
|
|
foreach ($albums as $album) {
|
|
factory(Song::class, random_int(7, 15))->create([
|
|
'album_id' => $album->id,
|
|
'artist_id' => $artist->id,
|
|
]);
|
|
}
|
|
}
|
|
|
|
protected function getAsUser($url, $user = null): self
|
|
{
|
|
return $this->get($url, [
|
|
'Authorization' => 'Bearer '.$this->generateJwtToken($user),
|
|
]);
|
|
}
|
|
|
|
protected function deleteAsUser($url, $data = [], $user = null): self
|
|
{
|
|
return $this->delete($url, $data, [
|
|
'Authorization' => 'Bearer '.$this->generateJwtToken($user),
|
|
]);
|
|
}
|
|
|
|
protected function postAsUser($url, $data, $user = null): self
|
|
{
|
|
return $this->post($url, $data, [
|
|
'Authorization' => 'Bearer '.$this->generateJwtToken($user),
|
|
]);
|
|
}
|
|
|
|
protected function putAsUser($url, $data, $user = null): self
|
|
{
|
|
return $this->put($url, $data, [
|
|
'Authorization' => 'Bearer '.$this->generateJwtToken($user),
|
|
]);
|
|
}
|
|
|
|
private function generateJwtToken(?User $user): string
|
|
{
|
|
return $this->auth->fromUser($user ?: factory(User::class)->create());
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
$this->addToAssertionCount(Mockery::getContainer()->mockery_getExpectationCount());
|
|
|
|
Mockery::close();
|
|
parent::tearDown();
|
|
}
|
|
}
|