koel/tests/TestCase.php

64 lines
1.5 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 DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
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;
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 ArraySubsetAsserts;
use CreatesApplication;
use DatabaseTransactions;
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
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();
2020-12-22 20:11:22 +00:00
parent::tearDown();
}
2020-09-09 16:18:53 +00:00
protected static function createSampleMediaSet(): void
{
/** @var Artist $artist */
$artist = Artist::factory()->create();
2020-09-09 16:18:53 +00:00
2020-12-22 20:11:22 +00:00
/** @var array<Album> $albums */
$albums = Album::factory(3)->create([
2020-09-09 16:18:53 +00:00
'artist_id' => $artist->id,
]);
// 7-15 songs per albums
foreach ($albums as $album) {
Song::factory(random_int(7, 15))->create([
2020-09-09 16:18:53 +00:00
'album_id' => $album->id,
'artist_id' => $artist->id,
]);
}
}
2021-06-05 10:47:56 +00:00
protected static function getNonPublicProperty($object, string $property) // @phpcs:ignore
2020-09-09 16:18:53 +00:00
{
$reflection = new ReflectionClass($object);
$property = $reflection->getProperty($property);
$property->setAccessible(true);
return $property->getValue($object);
}
2015-12-13 04:42:28 +00:00
}