Files
animethemes-server/tests/Unit/Rules/Wiki/Submission/Video/VideoIndexStreamTest.php
T
paranarimasu 54943c9b2c feat: use process facade for FFmpeg routines (#581)
* feat: use process facade for FFmpeg routines

* style: fix StyleCI findings
2023-05-29 23:33:00 -05:00

106 lines
3.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Rules\Wiki\Submission\Video;
use App\Rules\Wiki\Submission\SubmissionRule;
use App\Rules\Wiki\Submission\Video\VideoIndexStreamRule;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Process;
use Illuminate\Support\Facades\Validator;
use Tests\TestCase;
/**
* Class VideoIndexStreamTest.
*/
class VideoIndexStreamTest extends TestCase
{
use WithFaker;
/**
* The Video Index Stream Rule shall fail if the stream index is not expected.
*
* @return void
*/
public function testFailsWhenIndexIsNotExpected(): void
{
$file = UploadedFile::fake()->create($this->faker->word().'.webm', $this->faker->randomDigitNotNull());
Process::fake([
SubmissionRule::formatLoudnessCommand($file) => Process::result(errorOutput: json_encode([
'input_i' => $this->faker->randomFloat(),
'input_tp' => $this->faker->randomFloat(),
'input_lra' => $this->faker->randomFloat(),
'input_thresh' => $this->faker->randomFloat(),
'output_i' => $this->faker->randomFloat(),
'output_tp' => $this->faker->randomFloat(),
'output_lra' => $this->faker->randomFloat(),
'output_thresh' => $this->faker->randomFloat(),
'normalization_type' => 'dynamic',
'target_offset' => $this->faker->randomFloat(),
])),
SubmissionRule::formatFfprobeCommand($file) => Process::result(json_encode([
'streams' => [
0 => [
'codec_type' => 'video',
'index' => $this->faker->randomDigitNotNull(),
],
],
])),
]);
$validator = Validator::make(
['file' => $file],
['file' => new VideoIndexStreamRule()],
);
static::assertFalse($validator->passes());
Process::assertRan(SubmissionRule::formatFfprobeCommand($file));
}
/**
* The Video Index Stream Rule shall pass if the stream index is expected.
*
* @return void
*/
public function testPassesWhenIndexIsExpected(): void
{
$file = UploadedFile::fake()->create($this->faker->word().'.webm', $this->faker->randomDigitNotNull());
Process::fake([
SubmissionRule::formatLoudnessCommand($file) => Process::result(errorOutput: json_encode([
'input_i' => $this->faker->randomFloat(),
'input_tp' => $this->faker->randomFloat(),
'input_lra' => $this->faker->randomFloat(),
'input_thresh' => $this->faker->randomFloat(),
'output_i' => $this->faker->randomFloat(),
'output_tp' => $this->faker->randomFloat(),
'output_lra' => $this->faker->randomFloat(),
'output_thresh' => $this->faker->randomFloat(),
'normalization_type' => 'dynamic',
'target_offset' => $this->faker->randomFloat(),
])),
SubmissionRule::formatFfprobeCommand($file) => Process::result(json_encode([
'streams' => [
0 => [
'codec_type' => 'video',
'index' => 0,
],
],
])),
]);
$validator = Validator::make(
['file' => $file],
['file' => new VideoIndexStreamRule()],
);
static::assertTrue($validator->passes());
Process::assertRan(SubmissionRule::formatFfprobeCommand($file));
}
}