<?php

namespace MP4Box\Tests;

use MP4Box\MP4Box;
use Alchemy\BinaryDriver\BinaryDriverTestCase;
use MP4Box\Exception\InvalidFileArgumentException;

class MP4BoxTest extends BinaryDriverTestCase
{
    public function testProcessOutputWithCustomOutput()
    {
        $input = __DIR__ . '/../../files/Video.mp4';
        $out = 'Output.mp4';

        $mp4box = MP4Box::create();

        $factory = $this->createProcessBuilderFactoryMock();
        $process = $this->createProcessMock(1, true);

        $factory
            ->expects($this->once())
            ->method('create')
            ->with(array(
                $input,
                '-quiet',
                '-inter',
                '500',
                '-out',
                $out,
                '-tmp',
                dirname($input),
            ))
            ->willReturn($process);

        $mp4box->setProcessBuilderFactory($factory);

        $mp4box->process(__DIR__ . '/../../files/Video.mp4', $out);
    }

    /**
     * @expectedException MP4Box\Exception\InvalidFileArgumentException
     */
    public function testProcessOnNonUnexistingFile()
    {
        $mp4box = MP4Box::create();
        $this->expectException(InvalidFileArgumentException::class);
        $mp4box->process(__DIR__ . '/../../files/Unknown');
    }
}
