2015-12-13 12:42:28 +08:00
|
|
|
<?php
|
|
|
|
|
2017-02-14 14:53:02 +08:00
|
|
|
namespace Tests;
|
2015-12-13 12:42:28 +08:00
|
|
|
|
2020-09-09 18:18:53 +02:00
|
|
|
use App\Models\Album;
|
|
|
|
use App\Models\Artist;
|
|
|
|
use App\Models\Song;
|
2020-11-14 17:57:25 +01:00
|
|
|
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
2017-08-05 17:56:11 +01:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2017-02-14 14:53:02 +08:00
|
|
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
2020-09-09 18:18:53 +02:00
|
|
|
use ReflectionClass;
|
2020-06-13 14:19:24 +02:00
|
|
|
use Tests\Traits\CreatesApplication;
|
|
|
|
use Tests\Traits\SandboxesTests;
|
2015-12-13 12:42:28 +08:00
|
|
|
|
2017-02-14 14:53:02 +08:00
|
|
|
abstract class TestCase extends BaseTestCase
|
|
|
|
{
|
2020-11-14 17:57:25 +01:00
|
|
|
use ArraySubsetAsserts;
|
2020-01-17 17:45:45 +01:00
|
|
|
use CreatesApplication;
|
2020-11-14 17:57:25 +01:00
|
|
|
use DatabaseTransactions;
|
2020-06-13 14:19:24 +02:00
|
|
|
use SandboxesTests;
|
2020-01-17 17:46:06 +01:00
|
|
|
|
2019-07-22 09:03:23 +02:00
|
|
|
public function setUp(): void
|
2017-06-10 14:25:30 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
2020-09-09 18:18:53 +02:00
|
|
|
|
2017-06-10 14:25:30 +01:00
|
|
|
$this->prepareForTests();
|
2020-06-13 14:19:24 +02:00
|
|
|
self::createSandbox();
|
2017-06-10 14:25:30 +01:00
|
|
|
}
|
2018-08-19 13:08:16 +02:00
|
|
|
|
2019-07-22 09:03:23 +02:00
|
|
|
protected function tearDown(): void
|
2018-08-19 13:08:16 +02:00
|
|
|
{
|
2020-06-13 14:19:24 +02:00
|
|
|
self::destroySandbox();
|
2020-12-22 21:11:22 +01:00
|
|
|
|
2018-08-19 13:08:16 +02:00
|
|
|
parent::tearDown();
|
|
|
|
}
|
2020-09-09 18:18:53 +02:00
|
|
|
|
|
|
|
protected static function createSampleMediaSet(): void
|
|
|
|
{
|
|
|
|
/** @var Artist $artist */
|
2020-11-14 17:57:25 +01:00
|
|
|
$artist = Artist::factory()->create();
|
2020-09-09 18:18:53 +02:00
|
|
|
|
2020-12-22 21:11:22 +01:00
|
|
|
/** @var array<Album> $albums */
|
2020-11-14 17:57:25 +01:00
|
|
|
$albums = Album::factory(3)->create([
|
2020-09-09 18:18:53 +02:00
|
|
|
'artist_id' => $artist->id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
// 7-15 songs per albums
|
|
|
|
foreach ($albums as $album) {
|
2020-11-14 17:57:25 +01:00
|
|
|
Song::factory(random_int(7, 15))->create([
|
2020-09-09 18:18:53 +02:00
|
|
|
'album_id' => $album->id,
|
|
|
|
'artist_id' => $artist->id,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-05 12:47:56 +02:00
|
|
|
protected static function getNonPublicProperty($object, string $property) // @phpcs:ignore
|
2020-09-09 18:18:53 +02:00
|
|
|
{
|
|
|
|
$reflection = new ReflectionClass($object);
|
|
|
|
$property = $reflection->getProperty($property);
|
|
|
|
$property->setAccessible(true);
|
|
|
|
|
|
|
|
return $property->getValue($object);
|
|
|
|
}
|
2015-12-13 12:42:28 +08:00
|
|
|
}
|