Migrate everything to latest versions

Use newest symfony version, newest PHP and newest PHPUnit.
Remove prophecy dependency.
This commit is contained in:
Daniel Siepmann 2023-02-07 08:03:10 +01:00
parent 5838745b96
commit 808da86d12
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
6 changed files with 678 additions and 1058 deletions

View file

@ -30,7 +30,7 @@ Installation
Install requirements: Install requirements:
* PHP 7.3 command line * PHP 8.2 command line
* ffmpeg * ffmpeg

View file

@ -15,13 +15,11 @@
} }
}, },
"require": { "require": {
"php": "7.3.*", "php": "8.2.*",
"symfony/console": "^5.1", "symfony/console": "^6.2",
"symfony/process": "^5.1" "symfony/process": "^6.2"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^9.3", "phpunit/phpunit": "^10.0"
"phpspec/prophecy": "^1.12",
"phpspec/prophecy-phpunit": "^2.0"
} }
} }

1543
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,27 +1,23 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<phpunit <phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
backupGlobals="false" backupGlobals="false"
backupStaticAttributes="false"
colors="true" colors="true"
convertErrorsToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
processIsolation="false" processIsolation="false"
stopOnError="false" stopOnError="false"
stopOnFailure="false" stopOnFailure="false"
stopOnIncomplete="false" stopOnIncomplete="false"
stopOnSkipped="false" stopOnSkipped="false"
verbose="false" cacheDirectory=".phpunit.cache"
> backupStaticProperties="false"
requireCoverageMetadata="false"
>
<testsuites> <testsuites>
<testsuite name="unit"> <testsuite name="unit">
<directory>tests/Unit/</directory> <directory>tests/Unit/</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>
<coverage> <coverage>
<include> <include>
<directory suffix=".php">src</directory> <directory suffix=".php">src</directory>

View file

@ -24,7 +24,6 @@ namespace DanielSiepmann\Videcutting\Tests\Unit;
use DanielSiepmann\Videcutting\Cutting; use DanielSiepmann\Videcutting\Cutting;
use DanielSiepmann\Videcutting\VideoInfo; use DanielSiepmann\Videcutting\VideoInfo;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\Process\Process; use Symfony\Component\Process\Process;
/** /**
@ -32,16 +31,14 @@ use Symfony\Component\Process\Process;
*/ */
class CuttingTest extends TestCase class CuttingTest extends TestCase
{ {
use ProphecyTrait;
/** /**
* @test * @test
*/ */
public function instanceCanBeCreated(): void public function instanceCanBeCreated(): void
{ {
$video = $this->prophesize(VideoInfo::class); $video = $this->createStub(VideoInfo::class);
$subject = new Cutting( $subject = new Cutting(
$video->reveal() $video
); );
static::assertInstanceOf(Cutting::class, $subject); static::assertInstanceOf(Cutting::class, $subject);
@ -52,15 +49,15 @@ class CuttingTest extends TestCase
*/ */
public function generatesCommandsForCuttingWithoutAds(): void public function generatesCommandsForCuttingWithoutAds(): void
{ {
$video = $this->prophesize(VideoInfo::class); $video = $this->createStub(VideoInfo::class);
$video->getStart()->willReturn('10.05.20'); $video->method('getStart')->willReturn('10.05.20');
$video->getEnd()->willReturn('13.10.25'); $video->method('getEnd')->willReturn('13.10.25');
$video->getAds()->willReturn([]); $video->method('getAds')->willReturn([]);
$video->getOriginalFilename()->willReturn('Some-Video.mp4'); $video->method('getOriginalFilename')->willReturn('Some-Video.mp4');
$video->getOriginalFilenameWithSuffix('cut-1')->willReturn('Some-Video-cut-1.mp4'); $video->method('getOriginalFilenameWithSuffix')->willReturn('Some-Video-cut-1.mp4');
$subject = new Cutting( $subject = new Cutting(
$video->reveal() $video
); );
$commands = []; $commands = [];
@ -70,7 +67,7 @@ class CuttingTest extends TestCase
static::assertCount(1, $commands); static::assertCount(1, $commands);
static::assertSame( static::assertSame(
"ffmpeg -y -ss '10.05.20' -to '13.10.25' -i 'Some-Video.mp4' -c copy '/tmp/Some-Video-cut-1.mp4'", "ffmpeg -y -ss '10.05.20' -to '13.10.25' -i 'Some-Video.mp4' -c copy '" . sys_get_temp_dir() . "/Some-Video-cut-1.mp4'",
$commands[0]->getCommandLine() $commands[0]->getCommandLine()
); );
} }
@ -80,20 +77,22 @@ class CuttingTest extends TestCase
*/ */
public function generatesCommandsForCuttingWithAds(): void public function generatesCommandsForCuttingWithAds(): void
{ {
$video = $this->prophesize(VideoInfo::class); $video = $this->createStub(VideoInfo::class);
$video->getStart()->willReturn('1:05.20'); $video->method('getStart')->willReturn('1:05.20');
$video->getEnd()->willReturn('13:10.25'); $video->method('getEnd')->willReturn('13:10.25');
$video->getAds()->willReturn([ $video->method('getAds')->willReturn([
['2:10', '3:05'], ['2:10', '3:05'],
['10:07', '11:10'], ['10:07', '11:10'],
]); ]);
$video->getOriginalFilename()->willReturn('Some-Video.mp4'); $video->method('getOriginalFilename')->willReturn('Some-Video.mp4');
$video->getOriginalFilenameWithSuffix('cut-1')->willReturn('Some-Video-cut-1.mp4'); $video->method('getOriginalFilenameWithSuffix')->willReturnOnConsecutiveCalls(
$video->getOriginalFilenameWithSuffix('cut-2')->willReturn('Some-Video-cut-2.mp4'); 'Some-Video-cut-1.mp4',
$video->getOriginalFilenameWithSuffix('cut-3')->willReturn('Some-Video-cut-3.mp4'); 'Some-Video-cut-2.mp4',
'Some-Video-cut-3.mp4',
);
$subject = new Cutting( $subject = new Cutting(
$video->reveal() $video
); );
$commands = []; $commands = [];
@ -103,15 +102,15 @@ class CuttingTest extends TestCase
static::assertCount(3, $commands, 'Did not get expected number of cutting commands'); static::assertCount(3, $commands, 'Did not get expected number of cutting commands');
static::assertSame( static::assertSame(
"ffmpeg -y -ss '1:05.20' -to '2:10' -i 'Some-Video.mp4' -c copy '/tmp/Some-Video-cut-1.mp4'", "ffmpeg -y -ss '1:05.20' -to '2:10' -i 'Some-Video.mp4' -c copy '" . sys_get_temp_dir() . "/Some-Video-cut-1.mp4'",
$commands[0]->getCommandLine() $commands[0]->getCommandLine()
); );
static::assertSame( static::assertSame(
"ffmpeg -y -ss '3:05' -to '10:07' -i 'Some-Video.mp4' -c copy '/tmp/Some-Video-cut-2.mp4'", "ffmpeg -y -ss '3:05' -to '10:07' -i 'Some-Video.mp4' -c copy '" . sys_get_temp_dir() . "/Some-Video-cut-2.mp4'",
$commands[1]->getCommandLine() $commands[1]->getCommandLine()
); );
static::assertSame( static::assertSame(
"ffmpeg -y -ss '11:10' -to '13:10.25' -i 'Some-Video.mp4' -c copy '/tmp/Some-Video-cut-3.mp4'", "ffmpeg -y -ss '11:10' -to '13:10.25' -i 'Some-Video.mp4' -c copy '" . sys_get_temp_dir() . "/Some-Video-cut-3.mp4'",
$commands[2]->getCommandLine() $commands[2]->getCommandLine()
); );
} }
@ -121,18 +120,18 @@ class CuttingTest extends TestCase
*/ */
public function generatesCommandForGeneratingMetadata(): void public function generatesCommandForGeneratingMetadata(): void
{ {
$video = $this->prophesize(VideoInfo::class); $video = $this->createStub(VideoInfo::class);
$video->getOriginalFilename()->willReturn('Some-Video.mp4'); $video->method('getOriginalFilename')->willReturn('Some-Video.mp4');
$video->getOriginalFilenameWithSuffix('metadata')->willReturn('Some-Video-metadata.mp4'); $video->method('getOriginalFilenameWithSuffix')->willReturn('Some-Video-metadata.mp4');
$subject = new Cutting( $subject = new Cutting(
$video->reveal() $video
); );
$command = $subject->getCommandForGeneratingMetadata(); $command = $subject->getCommandForGeneratingMetadata();
static::assertSame( static::assertSame(
"ffmpeg -y -i 'Some-Video.mp4' -f ffmetadata '/tmp/Some-Video-metadata.txt'", "ffmpeg -y -i 'Some-Video.mp4' -f ffmetadata '" . sys_get_temp_dir() . "/Some-Video-metadata.txt'",
$command->getCommandLine() $command->getCommandLine()
); );
} }
@ -142,10 +141,10 @@ class CuttingTest extends TestCase
*/ */
public function throwsExceptionForGeneratingConcatInputFileIfNoConcatIsAvailable(): void public function throwsExceptionForGeneratingConcatInputFileIfNoConcatIsAvailable(): void
{ {
$video = $this->prophesize(VideoInfo::class); $video = $this->createStub(VideoInfo::class);
$subject = new Cutting( $subject = new Cutting(
$video->reveal() $video
); );
$this->expectException(\InvalidArgumentException::class); $this->expectException(\InvalidArgumentException::class);
@ -160,16 +159,18 @@ class CuttingTest extends TestCase
*/ */
public function generatesCommandsForGeneratingConcatInputFileWithNoAds(): void public function generatesCommandsForGeneratingConcatInputFileWithNoAds(): void
{ {
$video = $this->prophesize(VideoInfo::class); $video = $this->createStub(VideoInfo::class);
$video->getStart()->willReturn('10.05.20'); $video->method('getStart')->willReturn('10.05.20');
$video->getEnd()->willReturn('13.10.25'); $video->method('getEnd')->willReturn('13.10.25');
$video->getAds()->willReturn([]); $video->method('getAds')->willReturn([]);
$video->getOriginalFilename()->willReturn('Some-Video.mp4'); $video->method('getOriginalFilename')->willReturn('Some-Video.mp4');
$video->getOriginalFilenameWithSuffix('cut-1')->willReturn('Some-Video-cut-1.mp4'); $video->method('getOriginalFilenameWithSuffix')->willReturnOnConsecutiveCalls(
$video->getOriginalFilenameWithSuffix('concat')->willReturn('Some-Video-concat.mp4'); 'Some-Video-cut-1.mp4',
'Some-Video-concat.mp4'
);
$subject = new Cutting( $subject = new Cutting(
$video->reveal() $video
); );
foreach ($subject->getCommandsForCutting() as $command) { foreach ($subject->getCommandsForCutting() as $command) {
@ -179,7 +180,7 @@ class CuttingTest extends TestCase
$command = $subject->getCommandForGeneratingConcatInputFile(); $command = $subject->getCommandForGeneratingConcatInputFile();
static::assertSame( static::assertSame(
"printf 'file /tmp/Some-Video-cut-1.mp4' > /tmp/Some-Video-concat.txt", "printf 'file " . sys_get_temp_dir() . "/Some-Video-cut-1.mp4' > " . sys_get_temp_dir() . "/Some-Video-concat.txt",
$command->getCommandLine() $command->getCommandLine()
); );
} }
@ -189,21 +190,23 @@ class CuttingTest extends TestCase
*/ */
public function generatesCommandsForGeneratingConcatInputFileWithAds(): void public function generatesCommandsForGeneratingConcatInputFileWithAds(): void
{ {
$video = $this->prophesize(VideoInfo::class); $video = $this->createStub(VideoInfo::class);
$video->getStart()->willReturn('10.05.20'); $video->method('getStart')->willReturn('10.05.20');
$video->getEnd()->willReturn('13.10.25'); $video->method('getEnd')->willReturn('13.10.25');
$video->getAds()->willReturn([ $video->method('getAds')->willReturn([
['2:10', '3:05'], ['2:10', '3:05'],
['10:07', '11:10'], ['10:07', '11:10'],
]); ]);
$video->getOriginalFilename()->willReturn('Some-Video.mp4'); $video->method('getOriginalFilename')->willReturn('Some-Video.mp4');
$video->getOriginalFilenameWithSuffix('cut-1')->willReturn('Some-Video-cut-1.mp4'); $video->method('getOriginalFilenameWithSuffix')->willReturnOnConsecutiveCalls(
$video->getOriginalFilenameWithSuffix('cut-2')->willReturn('Some-Video-cut-2.mp4'); 'Some-Video-cut-1.mp4',
$video->getOriginalFilenameWithSuffix('cut-3')->willReturn('Some-Video-cut-3.mp4'); 'Some-Video-cut-2.mp4',
$video->getOriginalFilenameWithSuffix('concat')->willReturn('Some-Video-concat.mp4'); 'Some-Video-cut-3.mp4',
'Some-Video-concat.mp4'
);
$subject = new Cutting( $subject = new Cutting(
$video->reveal() $video
); );
foreach ($subject->getCommandsForCutting() as $command) { foreach ($subject->getCommandsForCutting() as $command) {
@ -213,8 +216,8 @@ class CuttingTest extends TestCase
$command = $subject->getCommandForGeneratingConcatInputFile(); $command = $subject->getCommandForGeneratingConcatInputFile();
static::assertSame( static::assertSame(
'printf \'file /tmp/Some-Video-cut-1.mp4\nfile /tmp/Some-Video-cut-2.mp4\nfile /tmp/Some-Video-cut-3.mp4\'' 'printf \'file ' . sys_get_temp_dir() . '/Some-Video-cut-1.mp4\nfile ' . sys_get_temp_dir() . '/Some-Video-cut-2.mp4\nfile ' . sys_get_temp_dir() . '/Some-Video-cut-3.mp4\''
. ' > /tmp/Some-Video-concat.txt', . ' > ' . sys_get_temp_dir() . '/Some-Video-concat.txt',
$command->getCommandLine() $command->getCommandLine()
); );
} }
@ -224,21 +227,23 @@ class CuttingTest extends TestCase
*/ */
public function generatesCommandForGeneratingVideoWithCustomTitle(): void public function generatesCommandForGeneratingVideoWithCustomTitle(): void
{ {
$video = $this->prophesize(VideoInfo::class); $video = $this->createStub(VideoInfo::class);
$video->getTargetFilePath()->willReturn('Series-Name/Series-01/10-episode title.mp4'); $video->method('getTargetFilePath')->willReturn('Series-Name/Series-01/10-episode title.mp4');
$video->getOriginalFilenameWithSuffix('concat')->willReturn('Series-Name_Series-01_episode-title-01-concat.mp4'); $video->method('getOriginalFilenameWithSuffix')->willReturnOnConsecutiveCalls(
$video->getOriginalFilenameWithSuffix('metadata')->willReturn('Series-Name_Series-01_episode-title-01-metadata.mp4'); 'Series-Name_Series-01_episode-title-01-concat.mp4',
$video->getTitleForHumans()->willReturn('01 - Episode Title'); 'Series-Name_Series-01_episode-title-01-metadata.mp4'
);
$video->method('getTitleForHumans')->willReturn('01 - Episode Title');
$subject = new Cutting( $subject = new Cutting(
$video->reveal() $video
); );
$command = $subject->getCommandForGeneratingVideo(); $command = $subject->getCommandForGeneratingVideo();
static::assertSame( static::assertSame(
'ffmpeg -y -f concat -safe 0 -i \'/tmp/Series-Name_Series-01_episode-title-01-concat.txt\' -c copy' 'ffmpeg -y -f concat -safe 0 -i \'' . sys_get_temp_dir() . '/Series-Name_Series-01_episode-title-01-concat.txt\' -c copy'
. ' -f ffmetadata -i \'/tmp/Series-Name_Series-01_episode-title-01-metadata.txt\' -c copy -map_metadata 1' . ' -f ffmetadata -i \'' . sys_get_temp_dir() . '/Series-Name_Series-01_episode-title-01-metadata.txt\' -c copy -map_metadata 1'
. ' -metadata Title=\'01 - Episode Title\'' . ' -metadata Title=\'01 - Episode Title\''
. ' \'Series-Name/Series-01/10-episode title.mp4\'', . ' \'Series-Name/Series-01/10-episode title.mp4\'',
$command->getCommandLine() $command->getCommandLine()
@ -250,19 +255,21 @@ class CuttingTest extends TestCase
*/ */
public function generatesCommandForCleanup(): void public function generatesCommandForCleanup(): void
{ {
$video = $this->prophesize(VideoInfo::class); $video = $this->createStub(VideoInfo::class);
$video->getTargetFilePath()->willReturn('Series-Name/Series-01/10-episode title.mp4'); $video->method('getTargetFilePath')->willReturn('Series-Name/Series-01/10-episode title.mp4');
$video->getOriginalFilenameWithSuffix('concat')->willReturn('Series-Name_Series-01_episode-title-01-concat.mp4'); $video->method('getOriginalFilenameWithSuffix')->willReturnOnConsecutiveCalls(
$video->getOriginalFilenameWithSuffix('metadata')->willReturn('Series-Name_Series-01_episode-title-01-metadata.mp4'); 'Series-Name_Series-01_episode-title-01-concat.mp4',
'Series-Name_Series-01_episode-title-01-metadata.mp4'
);
$subject = new Cutting( $subject = new Cutting(
$video->reveal() $video
); );
$command = $subject->getCommandForCleanup(); $command = $subject->getCommandForCleanup();
static::assertSame( static::assertSame(
'rm \'/tmp/Series-Name_Series-01_episode-title-01-concat.txt\' \'/tmp/Series-Name_Series-01_episode-title-01-metadata.txt\'', 'rm \'' . sys_get_temp_dir() . '/Series-Name_Series-01_episode-title-01-concat.txt\' \'' . sys_get_temp_dir() . '/Series-Name_Series-01_episode-title-01-metadata.txt\'',
$command->getCommandLine() $command->getCommandLine()
); );
} }
@ -272,18 +279,20 @@ class CuttingTest extends TestCase
*/ */
public function generatesCommandForCleanupWithSingleTempFile(): void public function generatesCommandForCleanupWithSingleTempFile(): void
{ {
$video = $this->prophesize(VideoInfo::class); $video = $this->createStub(VideoInfo::class);
$video->getStart()->willReturn('10.05.20'); $video->method('getStart')->willReturn('10.05.20');
$video->getEnd()->willReturn('13.10.25'); $video->method('getEnd')->willReturn('13.10.25');
$video->getAds()->willReturn([]); $video->method('getAds')->willReturn([]);
$video->getOriginalFilename()->willReturn('Some-Video.mp4'); $video->method('getOriginalFilename')->willReturn('Some-Video.mp4');
$video->getTargetFilePath()->willReturn('Series-Name/Series-01/10-episode title.mp4'); $video->method('getTargetFilePath')->willReturn('Series-Name/Series-01/10-episode title.mp4');
$video->getOriginalFilenameWithSuffix('cut-1')->willReturn('Some-Video-cut-1.mp4'); $video->method('getOriginalFilenameWithSuffix')->willReturnOnConsecutiveCalls(
$video->getOriginalFilenameWithSuffix('concat')->willReturn('Series-Name_Series-01_episode-title-01-concat.mp4'); 'Some-Video-cut-1.mp4',
$video->getOriginalFilenameWithSuffix('metadata')->willReturn('Series-Name_Series-01_episode-title-01-metadata.mp4'); 'Series-Name_Series-01_episode-title-01-concat.mp4',
'Series-Name_Series-01_episode-title-01-metadata.mp4'
);
$subject = new Cutting( $subject = new Cutting(
$video->reveal() $video
); );
foreach ($subject->getCommandsForCutting() as $command) { foreach ($subject->getCommandsForCutting() as $command) {
@ -293,7 +302,7 @@ class CuttingTest extends TestCase
$command = $subject->getCommandForCleanup(); $command = $subject->getCommandForCleanup();
static::assertSame( static::assertSame(
'rm \'/tmp/Some-Video-cut-1.mp4\' \'/tmp/Series-Name_Series-01_episode-title-01-concat.txt\' \'/tmp/Series-Name_Series-01_episode-title-01-metadata.txt\'', 'rm \'' . sys_get_temp_dir() . '/Some-Video-cut-1.mp4\' \'' . sys_get_temp_dir() . '/Series-Name_Series-01_episode-title-01-concat.txt\' \'' . sys_get_temp_dir() . '/Series-Name_Series-01_episode-title-01-metadata.txt\'',
$command->getCommandLine() $command->getCommandLine()
); );
} }

View file

@ -190,7 +190,7 @@ class VideoInfoTest extends TestCase
); );
} }
public function possibleFilenames(): array public static function possibleFilenames(): array
{ {
return [ return [
'Movie' => [ 'Movie' => [