From 88db9e0370e08d15b038d7b2651ba6ea0575cdf5 Mon Sep 17 00:00:00 2001 From: laurynas-baltsoft <38224044+laurynas-baltsoft@users.noreply.github.com> Date: Fri, 16 Feb 2024 14:31:26 +0100 Subject: [PATCH 1/5] Upgrade to php 8 (#50) * Enable testing with php8.3 * Update phpunit * Update phpunit * Restrict deprecations * Add docker compose file * Display depreactions --- .github/workflows/main.yml | 6 +++--- .gitignore | 2 ++ composer.json | 4 ++-- docker-compose.yml | 26 +++++++++++++++++++++++ phpunit.xml.dist | 32 ++++++++++++++++++----------- tests/ConvertApi/ConvertApiTest.php | 20 +++++++++--------- 6 files changed, 63 insertions(+), 27 deletions(-) create mode 100644 docker-compose.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 01ee669..784edfb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,9 +6,9 @@ jobs: strategy: matrix: php-version: - - '5.6' - - '7.0' - - '7.4' + - '8.1' + - '8.2' + - '8.3' name: PHP ${{ matrix.php-version }} sample steps: - uses: actions/checkout@v3 diff --git a/.gitignore b/.gitignore index 460a86c..7cda81c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ Icon .Spotlight-V100 .Trashes *.sublime-* +.phpunit.result.cache +.env vendor composer.lock bin \ No newline at end of file diff --git a/composer.json b/composer.json index 9da6e1f..740eba5 100644 --- a/composer.json +++ b/composer.json @@ -12,12 +12,12 @@ } ], "require": { - "php": ">=5.4.0", + "php": ">=8.0", "ext-curl": "*", "ext-json": "*" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "phpunit/phpunit": "~10.0" }, "config": { "bin-dir": "bin" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..192fe03 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,26 @@ +version: '3.8' + +services: + php81: + image: php:8.1-cli + env_file: .env + volumes: + - .:/app + working_dir: /app + command: bin/phpunit + + php82: + image: php:8.2-cli + env_file: .env + volumes: + - .:/app + working_dir: /app + command: bin/phpunit + + php83: + image: php:8.3-cli + env_file: .env + volumes: + - .:/app + working_dir: /app + command: bin/phpunit diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 1010532..0e55e53 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,13 +1,21 @@ - - - - ./tests/ConvertApi/ - - - - - - ./lib/ConvertApi/ - - + + + + + ./tests/ConvertApi/ + + + + + ./lib/ConvertApi/ + + diff --git a/tests/ConvertApi/ConvertApiTest.php b/tests/ConvertApi/ConvertApiTest.php index 3cb76f5..0525798 100644 --- a/tests/ConvertApi/ConvertApiTest.php +++ b/tests/ConvertApi/ConvertApiTest.php @@ -4,11 +4,11 @@ use \ConvertApi\ConvertApi; -class ConvertApiTest extends \PHPUnit_Framework_TestCase +class ConvertApiTest extends \PHPUnit\Framework\TestCase { protected $origApiSecret; - protected function setUp() + protected function setUp(): void { // Save original values so that we can restore them after running tests $this->origApiSecret = ConvertApi::getApiSecret(); @@ -18,7 +18,7 @@ protected function setUp() ConvertApi::setApiSecret(getenv('CONVERT_API_SECRET')); } - protected function tearDown() + protected function tearDown(): void { // Restore original values ConvertApi::setApiSecret($this->origApiSecret); @@ -44,7 +44,7 @@ public function testGetUser() { $user_info = ConvertApi::getUser(); - $this->assertInternalType('array', $user_info); + $this->assertIsArray($user_info); $this->assertArrayHasKey('SecondsLeft', $user_info); } @@ -56,7 +56,7 @@ public function testConvertWithFileUrl() $this->assertInstanceOf('\ConvertApi\Result', $result); - $this->assertInternalType('int', $result->getConversionCost()); + $this->assertIsInt($result->getConversionCost()); $files = $result->saveFiles(sys_get_temp_dir()); @@ -65,7 +65,7 @@ public function testConvertWithFileUrl() foreach ($files as $file) unlink($file); - $this->assertInternalType('string', $result->getFile()->getContents()); + $this->assertIsString($result->getFile()->getContents()); } public function testConvertWithFilePath() @@ -123,7 +123,7 @@ public function testConvertWithSpecifiedSourceFormatAndTimeout() $result = ConvertApi::convert('pdf', $params, 'web', 100); - $this->assertInternalType('int', $result->getFile()->getFileSize()); + $this->assertIsInt($result->getFile()->getFileSize()); } public function testConvertWithMultipleFiles() @@ -143,7 +143,7 @@ public function testConvertWithUrl() $result = ConvertApi::convert('pdf', $params, 'web'); - $this->assertInternalType('int', $result->getFile()->getFileSize()); + $this->assertIsInt($result->getFile()->getFileSize()); } public function testChainedConversion() @@ -180,7 +180,7 @@ public function testApiError() $this->fail('Expected exception has not been raised.'); } catch (\ConvertApi\Error\Api $e) { - $this->assertContains('Parameter validation error.', $e->getMessage()); + $this->assertStringContainsString('Parameter validation error.', $e->getMessage()); $this->assertEquals(4000, $e->getCode()); } } @@ -196,7 +196,7 @@ public function testClientError() $this->fail('Expected exception has not been raised.'); } catch (\ConvertApi\Error\Client $e) { - $this->assertContains('timed out', $e->getMessage()); + $this->assertStringContainsString('timed out', $e->getMessage()); $this->assertEquals(28, $e->getCode()); } } From 34f6d231b8d4ce776f157538e06a82b8e039dcb1 Mon Sep 17 00:00:00 2001 From: laurynas-baltsoft <38224044+laurynas-baltsoft@users.noreply.github.com> Date: Fri, 16 Feb 2024 15:09:57 +0100 Subject: [PATCH 2/5] Fix php8 deprecations (#51) * Fix php8 deprecations * Fix dynamic property depreactions * Update version in readme --- README.md | 2 +- examples/conversions_chaining.php | 4 ++-- lib/ConvertApi/Client.php | 6 +++--- lib/ConvertApi/FileUpload.php | 4 ++++ lib/ConvertApi/FormatDetector.php | 2 ++ lib/ConvertApi/Result.php | 3 ++- lib/ConvertApi/ResultFile.php | 2 ++ lib/ConvertApi/Task.php | 5 +++++ 8 files changed, 21 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7c75549..22561b4 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ ConvertAPI helps in converting various file formats. Creating PDF and Images fro ## Requirements -PHP 5.4.0 and later. +PHP 8.1.0 and later. ## Installation diff --git a/examples/conversions_chaining.php b/examples/conversions_chaining.php index 2e724d6..de4593f 100644 --- a/examples/conversions_chaining.php +++ b/examples/conversions_chaining.php @@ -18,14 +18,14 @@ $cost = $jpgResult->getConversionCost(); $count = count($jpgResult->getFiles()); -echo "Conversions done. Cost: ${cost}. Total files created: ${count}\n"; +echo "Conversions done. Cost: {$cost}. Total files created: {$count}\n"; $zipResult = ConvertApi::convert('zip', ['Files' => $jpgResult->getFiles()], 'any'); $cost = $zipResult->getConversionCost(); $count = count($zipResult->getFiles()); -echo "Conversions done. Cost: ${cost}. Total files created: ${count}\n"; +echo "Conversions done. Cost: {$cost}. Total files created: {$count}\n"; $savedFiles = $zipResult->saveFiles($dir); diff --git a/lib/ConvertApi/Client.php b/lib/ConvertApi/Client.php index ed4513b..2bdef4a 100644 --- a/lib/ConvertApi/Client.php +++ b/lib/ConvertApi/Client.php @@ -44,7 +44,7 @@ public function upload($file_or_resource, $fileName) if (!$fp) { - throw new Error\File("Unable to open file ${file_or_resource}"); + throw new Error\File("Unable to open file {$file_or_resource}"); } curl_setopt($ch, CURLOPT_POST, true); @@ -72,7 +72,7 @@ public function download($url, $path) if (!$fp) { - throw new Error\File("Unable to open file ${path}"); + throw new Error\File("Unable to open file {$path}"); } curl_setopt($ch, CURLOPT_FILE, $fp); @@ -193,7 +193,7 @@ private function buildFormData($params) if (is_array($val)) { foreach ($val as $k => $v) - $data["${key}[${k}]"] = $v; + $data["{$key}[{$k}]"] = $v; } elseif (is_bool($val)) $data[$key] = $val ? 'true' : 'false'; diff --git a/lib/ConvertApi/FileUpload.php b/lib/ConvertApi/FileUpload.php index 5779157..11779c3 100644 --- a/lib/ConvertApi/FileUpload.php +++ b/lib/ConvertApi/FileUpload.php @@ -4,6 +4,10 @@ class FileUpload { + public $filePath; + private string $_fileName; + private array $_result; + function __construct($filePath, $fileName = null) { $this->filePath = $filePath; diff --git a/lib/ConvertApi/FormatDetector.php b/lib/ConvertApi/FormatDetector.php index 41bc458..e93d30d 100644 --- a/lib/ConvertApi/FormatDetector.php +++ b/lib/ConvertApi/FormatDetector.php @@ -4,6 +4,8 @@ class FormatDetector { + private $resource; + function __construct($resource) { $this->resource = $resource; diff --git a/lib/ConvertApi/Result.php b/lib/ConvertApi/Result.php index f719131..571977e 100644 --- a/lib/ConvertApi/Result.php +++ b/lib/ConvertApi/Result.php @@ -4,7 +4,8 @@ class Result { - private $files; + private array $files; + public array $response; function __construct($response) { diff --git a/lib/ConvertApi/ResultFile.php b/lib/ConvertApi/ResultFile.php index e3c9fe9..e84ec62 100644 --- a/lib/ConvertApi/ResultFile.php +++ b/lib/ConvertApi/ResultFile.php @@ -4,6 +4,8 @@ class ResultFile { + public array $fileInfo; + function __construct($fileInfo) { $this->fileInfo = $fileInfo; diff --git a/lib/ConvertApi/Task.php b/lib/ConvertApi/Task.php index fca394e..29baf1d 100644 --- a/lib/ConvertApi/Task.php +++ b/lib/ConvertApi/Task.php @@ -6,6 +6,11 @@ class Task { const DEFAULT_URL_FORMAT = 'url'; + private ?string $fromFormat; + private ?string $toFormat; + private array $params; + private ?int $conversionTimeout; + function __construct($fromFormat, $toFormat, $params, $conversionTimeout = null) { $this->fromFormat = $fromFormat; From 4ade93df088236c7a1056cd239611662293d4b35 Mon Sep 17 00:00:00 2001 From: Laurynas Butkus Date: Fri, 16 Feb 2024 15:14:06 +0100 Subject: [PATCH 3/5] Bump version --- lib/ConvertApi/ConvertApi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ConvertApi/ConvertApi.php b/lib/ConvertApi/ConvertApi.php index ffdc0d8..2e7bf50 100644 --- a/lib/ConvertApi/ConvertApi.php +++ b/lib/ConvertApi/ConvertApi.php @@ -10,7 +10,7 @@ class ConvertApi { // ConvertAPI client version. - const VERSION = '1.6.1'; + const VERSION = '2.0.0'; // @var string The Convert API secret. You can get your secret at https://www.convertapi.com/a public static $apiSecret; From 86de9d0a18543bde03680d04cc3135eaf6cce42e Mon Sep 17 00:00:00 2001 From: laurynas-baltsoft <38224044+laurynas-baltsoft@users.noreply.github.com> Date: Fri, 16 Feb 2024 15:21:48 +0100 Subject: [PATCH 4/5] Fix manual installation example (#52) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 22561b4..5aa4ab2 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ composer require convertapi/convertapi-php If you do not wish to use the Composer, you must require ConvertApi autoloader: ```php -require_once('/path/to/convertapi-php/src/ConvertApi/autoload.php'); +require_once('/path/to/convertapi-php/lib/ConvertApi/autoload.php'); ``` ## Dependencies From a4c67b10a4e300536170ea729248a92de70efd36 Mon Sep 17 00:00:00 2001 From: Michael Henderson Date: Sat, 17 Feb 2024 00:30:01 +1000 Subject: [PATCH 5/5] fix(params): Allow StoreFile param to be overridden (#41) --- lib/ConvertApi/Task.php | 6 +++--- tests/ConvertApi/ConvertApiTest.php | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/ConvertApi/Task.php b/lib/ConvertApi/Task.php index 29baf1d..fc47805 100644 --- a/lib/ConvertApi/Task.php +++ b/lib/ConvertApi/Task.php @@ -21,11 +21,11 @@ function __construct($fromFormat, $toFormat, $params, $conversionTimeout = null) function run() { - $params = array_merge( - $this->normalizedParams(), + $params = array_replace( [ 'StoreFile' => true, - ] + ], + $this->normalizedParams() ); if ($this->conversionTimeout) { diff --git a/tests/ConvertApi/ConvertApiTest.php b/tests/ConvertApi/ConvertApiTest.php index 0525798..3005e86 100644 --- a/tests/ConvertApi/ConvertApiTest.php +++ b/tests/ConvertApi/ConvertApiTest.php @@ -77,6 +77,15 @@ public function testConvertWithFilePath() $this->assertEquals('test.pdf', $result->getFile()->getFileName()); } + public function testConvertWithStoreFileFalse() + { + $params = ['File' => 'examples/files/test.docx', 'StoreFile' => false]; + + $result = ConvertApi::convert('pdf', $params); + + $this->assertEquals('test.pdf', $result->getFile()->getFileName()); + } + public function testConvertWithAltnativeConverter() { $params = ['File' => 'examples/files/test.docx', 'converter' => 'openoffice'];