koel/tests/TestCase.php

71 lines
1.7 KiB
PHP
Raw Normal View History

2015-12-13 04:42:28 +00:00
<?php
2017-02-14 06:53:02 +00:00
namespace Tests;
2015-12-13 04:42:28 +00:00
2020-09-09 16:18:53 +00:00
use App\Models\Album;
use App\Models\Artist;
use App\Models\Song;
use Exception;
2017-08-05 16:56:11 +00:00
use Illuminate\Foundation\Testing\DatabaseTransactions;
2017-02-14 06:53:02 +00:00
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
2020-09-09 16:18:53 +00:00
use ReflectionClass;
2020-06-13 12:19:24 +00:00
use Tests\Traits\CreatesApplication;
2018-08-19 09:05:33 +00:00
use Tests\Traits\InteractsWithIoc;
2020-06-13 12:19:24 +00:00
use Tests\Traits\SandboxesTests;
2015-12-13 04:42:28 +00:00
2017-02-14 06:53:02 +00:00
abstract class TestCase extends BaseTestCase
{
use DatabaseTransactions;
use CreatesApplication;
use InteractsWithIoc;
2020-06-13 12:19:24 +00:00
use SandboxesTests;
2020-01-17 16:46:06 +00:00
2019-07-22 07:03:23 +00:00
public function setUp(): void
2017-06-10 13:25:30 +00:00
{
parent::setUp();
2020-09-09 16:18:53 +00:00
2017-06-10 13:25:30 +00:00
$this->prepareForTests();
2020-06-13 12:19:24 +00:00
self::createSandbox();
2017-06-10 13:25:30 +00:00
}
2019-07-22 07:03:23 +00:00
protected function tearDown(): void
{
2020-06-13 12:19:24 +00:00
self::destroySandbox();
parent::tearDown();
}
2020-09-09 16:18:53 +00:00
/**
* Create a sample media set, with a complete artist+album+song trio.
*
* @throws Exception
*/
protected static function createSampleMediaSet(): void
{
/** @var Artist $artist */
$artist = factory(Artist::class)->create();
// Sample 3 albums
/** @var Album[] $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 static function getNonPublicProperty($object, string $property)
{
$reflection = new ReflectionClass($object);
$property = $reflection->getProperty($property);
$property->setAccessible(true);
return $property->getValue($object);
}
2015-12-13 04:42:28 +00:00
}