| 1 |
<?php |
| 2 |
/** |
| 3 |
* WebPConvert - Convert JPEG & PNG to WebP with PHP |
| 4 |
* |
| 5 |
* @link https://github.com/rosell-dk/webp-convert |
| 6 |
* @license MIT |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace WebPConvert\Tests\Convert\Converters; |
| 10 |
|
| 11 |
use WebPConvert\Convert\Converters\FFMpeg; |
| 12 |
use WebPConvert\Convert\Exceptions\ConversionFailed\ConverterNotOperationalException; |
| 13 |
use WebPConvert\Loggers\BufferLogger; |
| 14 |
|
| 15 |
use PHPUnit\Framework\TestCase; |
| 16 |
|
| 17 |
class FFMpegTest extends TestCase |
| 18 |
{ |
| 19 |
|
| 20 |
public static function getImageFolder() |
| 21 |
{ |
| 22 |
return realpath(__DIR__ . '/../../images'); |
| 23 |
} |
| 24 |
|
| 25 |
public static function getImagePath($image) |
| 26 |
{ |
| 27 |
return self::getImageFolder() . '/' . $image; |
| 28 |
} |
| 29 |
|
| 30 |
public function testConvert() |
| 31 |
{ |
| 32 |
ConverterTestHelper::runAllConvertTests($this, 'FFMpeg'); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Try converting. |
| 37 |
* It is ok if converter is not operational. |
| 38 |
* It is not ok if converter thinks it is operational, but fails |
| 39 |
* |
| 40 |
* @return $ok |
| 41 |
* @throws ConversionFailedException if convert throws it |
| 42 |
*/ |
| 43 |
private static function tryThis($test, $source, $options) |
| 44 |
{ |
| 45 |
$bufferLogger = new BufferLogger(); |
| 46 |
|
| 47 |
try { |
| 48 |
FFMpeg::convert($source, $source . '.webp', $options, $bufferLogger); |
| 49 |
} catch (ConversionFailedException $e) { |
| 50 |
// this is not ok |
| 51 |
|
| 52 |
//$bufferLogger->getText() |
| 53 |
throw $e; |
| 54 |
} catch (ConverterNotOperationalException $e) { |
| 55 |
// (SystemRequirementsNotMetException is also a ConverterNotOperationalException) |
| 56 |
// this is ok. |
| 57 |
return true; |
| 58 |
} |
| 59 |
return true; |
| 60 |
} |
| 61 |
|
| 62 |
public function testWithNice() { |
| 63 |
$source = self::getImagePath('test.png'); |
| 64 |
$options = [ |
| 65 |
'use-nice' => true, |
| 66 |
'encoding' => 'lossless', |
| 67 |
]; |
| 68 |
$this->assertTrue(self::tryThis($this, $source, $options)); |
| 69 |
} |
| 70 |
|
| 71 |
} |
| 72 |
|