PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.5
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.5
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / rosell-dk / webp-convert / tests / Convert / Converters / FFMpegTest.php

FFMpegTest.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.5, at vendor/rosell-dk/webp-convert/tests/Convert/Converters/FFMpegTest.php

72 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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