├── .gitattributes ├── .github ├── FUNDING.yml ├── assets │ └── icon.png └── workflows │ └── main.yml ├── .gitignore ├── .styleci.yml ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── composer.json ├── config └── config.php ├── phpunit.xml ├── src ├── Contracts │ ├── ConversionStrategy.php │ └── ConvertibleFormat.php ├── ConversionCleanup.php ├── ConversionResult.php ├── Doxswap.php ├── DoxswapServiceProvider.php ├── Exceptions │ ├── ConversionFailedException.php │ ├── InputFileNotFoundException.php │ ├── UnsupportedConversionException.php │ └── UnsupportedMimeTypeException.php ├── Facades │ └── Doxswap.php ├── Filename.php ├── FormatRegistry.php ├── Formats │ ├── BmpFormat.php │ ├── CsvFormat.php │ ├── DocFormat.php │ ├── DocxFormat.php │ ├── GifFormat.php │ ├── HtmlFormat.php │ ├── JpgFormat.php │ ├── OdpFormat.php │ ├── OdsFormat.php │ ├── OdtFormat.php │ ├── PngFormat.php │ ├── PptFormat.php │ ├── PptxFormat.php │ ├── RtfFormat.php │ ├── SvgFormat.php │ ├── TiffFormat.php │ ├── TxtFormat.php │ ├── WebpFormat.php │ ├── XlsFormat.php │ ├── XlsxFormat.php │ └── XmlFormat.php └── Strategies │ ├── ImageMagick.php │ └── LibreOffice.php └── tests ├── Integration ├── BmpConversionTest.php ├── CsvConversionTest.php ├── DocConversionTest.php ├── DocxConversionTest.php ├── GifConversionTest.php ├── HtmlConversionTest.php ├── JpgConversionTest.php ├── OdpConversionTest.php ├── OdsConversionTest.php ├── OdtConversionTest.php ├── PngConversionTest.php ├── PptConversionTest.php ├── PptxConversionTest.php ├── RtfConversionTest.php ├── SvgConversionTest.php ├── TiffConversionTest.php ├── TxtConversionTest.php ├── WebpConversionTest.php ├── XlsConversionTest.php ├── XlsxConversionTest.php └── XmlConversionTest.php ├── Stubs ├── sample.bmp ├── sample.csv ├── sample.doc ├── sample.docx ├── sample.gif ├── sample.html ├── sample.jpg ├── sample.odp ├── sample.ods ├── sample.odt ├── sample.png ├── sample.ppt ├── sample.pptx ├── sample.rtf ├── sample.svg ├── sample.tiff ├── sample.txt ├── sample.webp ├── sample.xls ├── sample.xlsx └── sample.xml ├── TestCase.php └── Unit ├── ConversionCleanupTest.php ├── FilenameTest.php └── FormatRegistryTest.php /.gitattributes: -------------------------------------------------------------------------------- 1 | tests/Stubs/*.docx filter=lfs diff=lfs merge=lfs -text 2 | sample.bmp filter=lfs diff=lfs merge=lfs -text 3 | sample.csv filter=lfs diff=lfs merge=lfs -text 4 | sample.doc filter=lfs diff=lfs merge=lfs -text 5 | sample.html filter=lfs diff=lfs merge=lfs -text 6 | sample.jpg filter=lfs diff=lfs merge=lfs -text 7 | sample.odp filter=lfs diff=lfs merge=lfs -text 8 | sample.ods filter=lfs diff=lfs merge=lfs -text 9 | sample.odt filter=lfs diff=lfs merge=lfs -text 10 | sample.png filter=lfs diff=lfs merge=lfs -text 11 | sample.ppt filter=lfs diff=lfs merge=lfs -text 12 | sample.pptx filter=lfs diff=lfs merge=lfs -text 13 | sample.rtf filter=lfs diff=lfs merge=lfs -text 14 | sample.svg filter=lfs diff=lfs merge=lfs -text 15 | sample.tiff filter=lfs diff=lfs merge=lfs -text 16 | sample.txt filter=lfs diff=lfs merge=lfs -text 17 | sample.xls filter=lfs diff=lfs merge=lfs -text 18 | sample.xlsx filter=lfs diff=lfs merge=lfs -text 19 | sample.xml filter=lfs diff=lfs merge=lfs -text 20 | sample.gif filter=lfs diff=lfs merge=lfs -text 21 | sample.webp filter=lfs diff=lfs merge=lfs -text 22 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [Blaspsoft] 2 | -------------------------------------------------------------------------------- /.github/assets/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blaspsoft/doxswap/b073fbccc945ad1d6e26ee1812d43347b0bc86a0/.github/assets/icon.png -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Run Tests 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | test: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | # Step 1: Check out the repository 11 | - name: Checkout code 12 | uses: actions/checkout@v4 13 | with: 14 | lfs: true 15 | 16 | # Step 2: Set up PHP 17 | - name: Set up PHP 18 | uses: shivammathur/setup-php@v2 19 | with: 20 | php-version: "8.2" 21 | extensions: mbstring, dom, zip, fileinfo, imagick 22 | 23 | # Step 3: Set up Git LFS 24 | - name: Set up Git LFS 25 | run: | 26 | git lfs install 27 | git lfs pull 28 | 29 | # Step 4: List files in the repository 30 | - name: List files 31 | run: | 32 | ls -lh tests/Stubs/ 33 | file --mime-type tests/Stubs/* 34 | 35 | # Step 5: Install LibreOffice (Required for Conversion) 36 | - name: Install LibreOffice 37 | run: sudo apt-get update && sudo apt-get install -y libreoffice 38 | 39 | # Step 6: Install Potrace (Required for BMP to SVG conversion) 40 | - name: Install Potrace 41 | run: sudo apt-get install -y potrace 42 | 43 | # Step 7: Install Composer dependencies 44 | - name: Install dependencies 45 | run: composer install --no-interaction --prefer-dist 46 | 47 | # Step 8: Set up Laravel environment (if needed) 48 | - name: Set up Laravel environment 49 | run: | 50 | echo "APP_KEY=$(php artisan key:generate --show)" > .env 51 | echo "APP_ENV=testing" >> .env 52 | echo "DB_CONNECTION=sqlite" >> .env 53 | echo "LIBREOFFICE_PATH=/usr/bin/soffice" >> .env 54 | 55 | # Step 9: Run Unit tests 56 | - name: Run Unit tests 57 | run: php ./vendor/bin/phpunit --testsuite=Unit 58 | 59 | # Step 10: Run Integration tests (requires LibreOffice) 60 | - name: Run Integration tests 61 | run: php ./vendor/bin/phpunit --testsuite=Integration --testdox 62 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.lock 3 | .phpunit.result.cache 4 | /.idea 5 | .DS_Store -------------------------------------------------------------------------------- /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: laravel 2 | 3 | disabled: 4 | - single_class_element_per_statement 5 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | Please read and understand the contribution guide before creating an issue or pull request. 6 | 7 | ## Etiquette 8 | 9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code 10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be 11 | extremely unfair for them to suffer abuse or anger for their hard work. 12 | 13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the 14 | world that developers are civilized and selfless people. 15 | 16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient 17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. 18 | 19 | ## Viability 20 | 21 | When requesting or submitting new features, first consider whether it might be useful to others. Open 22 | source projects are used by many developers, who may have entirely different needs to your own. Think about 23 | whether or not your feature is likely to be used by other users of the project. 24 | 25 | ## Procedure 26 | 27 | Before filing an issue: 28 | 29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. 30 | - Check to make sure your feature suggestion isn't already present within the project. 31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. 32 | - Check the pull requests tab to ensure that the feature isn't already in progress. 33 | 34 | Before submitting a pull request: 35 | 36 | - Check the codebase to ensure that your feature doesn't already exist. 37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. 38 | 39 | ## Requirements 40 | 41 | If the project maintainer has any additional requirements, you will find them listed here. 42 | 43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer). 44 | 45 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 46 | 47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 48 | 49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option. 50 | 51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 52 | 53 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 54 | 55 | **Happy coding**! 56 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Michael Deeming 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | Onym Icon 3 |

4 | GitHub Workflow Status (main) 5 | Total Downloads 6 | Latest Version 7 | License 8 |

9 |

10 | 11 | # Doxswap 12 | 13 | A Laravel package for seamless document and image format conversions. Transform between various formats like DOCX -> PDF, HTML -> PDF, PNG -> WEBP, and more popular formats using a simple, elegant API. Powered by LibreOffice for documents and ImageMagick for image processing. 14 | 15 | ## 🚀 Features 16 | 17 | - 📄 **Multiple Format Support** – Convert between documents (DOCX, XLSX, ODT) and images (PNG, JPG, WEBP) with ease 18 | - 🚀 **Simple API** – Easy-to-use interface for all conversion operations 19 | - 💾 **Laravel Storage Integration** – Works seamlessly with Laravel's filesystem drivers 20 | - ⚡ **Efficient Processing** – Optimized conversion using LibreOffice and ImageMagick engines 21 | - 🔍 **Conversion Tracking** – Detailed results including duration and file paths 22 | - 🔒 **Secure File Handling** – Safe and secure file processing with proper cleanup 23 | - ⚙️ **Configurable Settings** – Customize paths, storage disks, and conversion options 24 | - 🛡️ **Error Handling** – Robust exception handling for unsupported formats and conversions 25 | 26 | ## Installation 27 | 28 | You can install the package via composer: 29 | 30 | ```bash 31 | composer require blaspsoft/doxswap 32 | ``` 33 | 34 | You can publish the config file with: 35 | 36 | ```bash 37 | php artisan vendor:publish --tag="doxswap-config" 38 | ``` 39 | 40 | ### Overview 41 | 42 | The `config/doxswap.php` file includes: 43 | 44 | #### 💾 Storage & Cleanup 45 | 46 | - `input_disk`: Where to read files from (default: 'public') 47 | - `output_disk`: Where to save converted files (default: 'public') 48 | - `perform_cleanup`: Delete input files after conversion (default: false) 49 | 50 | #### 📝 File Naming 51 | 52 | Configure how output files are named using different strategies: 53 | 54 | ```php 55 | 'filename' => [ 56 | // Strategy: 'original', 'random', or 'timestamp' 57 | 'strategy' => 'original', 58 | 59 | // Naming options 60 | 'options' => [ 61 | 'length' => 24, // Length for random names 62 | 'prefix' => '', // Add prefix to filename 63 | 'suffix' => '', // Add suffix to filename 64 | 'separator' => '_', // Separator for components 65 | 'format' => 'YmdHis', // Format for timestamp strategy 66 | ], 67 | ] 68 | ``` 69 | 70 | #### 🛠️ Conversion Drivers 71 | 72 | Configure paths for conversion tools: 73 | 74 | ```php 75 | 'drivers' => [ 76 | 'libreoffice_path' => env('LIBRE_OFFICE_PATH', '/usr/bin/soffice'), 77 | ] 78 | ``` 79 | 80 | Default LibreOffice paths by OS: 81 | 82 | - 🐧 Linux: `/usr/bin/soffice` 83 | - 🍎 macOS: `/Applications/LibreOffice.app/Contents/MacOS/soffice` 84 | - 🪟 Windows: `C:\Program Files\LibreOffice\program\soffice.exe` 85 | 86 | #### 📄 File Types 87 | 88 | Supports various document formats including: 89 | 90 | - Documents: DOC, DOCX, ODT, RTF, TXT 91 | - Spreadsheets: XLS, XLSX, ODS, CSV 92 | - Presentations: PPT, PPTX, ODP 93 | - Images: JPG, PNG, SVG, BMP, TIFF, WEBP, GIF 94 | - Web: HTML, XML 95 | - Other: PDF 96 | 97 | ### Usage 98 | 99 | ```php 100 | $result = Doxswap::convert('sample.docx', 'pdf'); 101 | 102 | /** 103 | * Returns a ConversionResult object with the following properties: 104 | * 105 | * @property string $inputFilename The original input filename 106 | * @property string $inputFilePath The full path to the input file 107 | * @property string $outputFilename The converted output filename 108 | * @property string $outputFilePath The full path to the converted output file 109 | * @property string $toFormat The format the file was converted to (e.g. 'pdf') 110 | * @property string $duration The time taken for conversion (e.g. "2.21 sec") 111 | * @property float $startTime Unix timestamp of when conversion started 112 | * @property float $endTime Unix timestamp of when conversion completed 113 | * @property string $inputDisk The Laravel storage disk used for input 114 | * @property string $outputDisk The Laravel storage disk used for output 115 | */ 116 | 117 | ``` 118 | 119 | ## Requirements 120 | 121 | ### LibreOffice & ImageMagick 122 | 123 | This package requires LibreOffice, ImageMagick, and Potrace to be installed on your system. Here's how to install them: 124 | 125 | #### Ubuntu/Debian 126 | 127 | ```bash 128 | sudo apt update 129 | sudo apt install libreoffice imagemagick potrace 130 | ``` 131 | 132 | #### macOS 133 | 134 | ```bash 135 | brew install libreoffice imagemagick potrace 136 | ``` 137 | 138 | #### Windows 139 | 140 | ```bash 141 | choco install libreoffice imagemagick potrace 142 | ``` 143 | 144 | #### Docker 145 | 146 | If you're using Docker, you can add the required dependencies to your container: 147 | 148 | ```dockerfile 149 | # Ubuntu/Debian based 150 | RUN apt-get update && apt-get install -y libreoffice imagemagick potrace 151 | 152 | # Alpine based 153 | RUN apk add --no-cache libreoffice imagemagick potrace 154 | ``` 155 | 156 | ### PHP Requirements 157 | 158 | - PHP >= 8.1 159 | - ext-fileinfo 160 | - ext-imagick 161 | - Laravel >= 9.0 162 | 163 | ## 🔁 Supported Conversions by Category 164 | 165 | ### 📝 Documents 166 | 167 | | From | Supported Conversions | 168 | | ---- | ---------------------------------------------- | 169 | | DOCX | PDF ✅✅, ODT, RTF, TXT, HTML, XML, EPUB | 170 | | DOC | PDF ✅✅, DOCX, ODT, RTF, TXT, HTML, XML, EPUB | 171 | | ODT | PDF, DOCX, RTF, TXT, HTML, XML | 172 | | RTF | PDF, DOCX, ODT, TXT, HTML, XML | 173 | | TXT | PDF, DOCX, ODT, HTML, XML | 174 | | HTML | PDF, ODT, TXT | 175 | | XML | PDF, DOCX, ODT, TXT, HTML | 176 | 177 | ### 📊 Spreadsheets 178 | 179 | | From | Supported Conversions | 180 | | ---- | --------------------- | 181 | | XLSX | PDF ✅✅, ODS, CSV | 182 | | XLS | PDF, XLSX, ODS, CSV | 183 | | ODS | PDF, XLSX, CSV | 184 | | CSV | PDF, XLSX, ODS | 185 | 186 | ### 🎯 Presentations 187 | 188 | | From | Supported Conversions | 189 | | ---- | --------------------- | 190 | | PPTX | PDF ✅✅, ODP | 191 | | PPT | PDF, PPTX, ODP | 192 | | ODP | PDF, PPTX | 193 | 194 | ### 🖼️ Images 195 | 196 | | From | Supported Conversions | 197 | | ---- | -------------------------------------- | 198 | | PNG | PDF ✅, JPG, SVG, TIFF, WEBP, GIF, BMP | 199 | | JPG | PDF ✅, PNG, SVG, TIFF, WEBP, GIF, BMP | 200 | | SVG | PDF, PNG, JPG, TIFF, WEBP, GIF, BMP | 201 | | BMP | PDF, PNG, JPG, SVG, TIFF, WEBP, GIF | 202 | | TIFF | PDF, PNG, JPG, SVG, WEBP, GIF, BMP | 203 | | WEBP | PDF, PNG, JPG, SVG, TIFF, GIF, BMP | 204 | | GIF | PDF, PNG, JPG, SVG, TIFF, WEBP, BMP | 205 | 206 | ### Legend 🔍 207 | 208 | - ✅✅ = Common high-priority conversion 209 | - ✅ = Popular supported format 210 | - (unlisted) = Conversion not supported 211 | 212 | > **Note**: Document conversions are performed using LibreOffice in headless mode, while image format conversions utilize ImageMagick 🚀 213 | 214 | ## 🤝 Sponsors 215 | 216 | If you find this package helpful, please consider sponsoring the development: 217 | 218 | > 🚀 [Become a GitHub Sponsor](https://github.com/sponsors/Blaspsoft) 219 | 220 | ## License 221 | 222 | Blasp is open-sourced software licensed under the [MIT license](LICENSE). 223 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "blaspsoft/doxswap", 3 | "description": "Doxswap is a simple document conversion package for Laravel which uses LibreOffice to convert documents to a variety of formats.", 4 | "version": "dev-main", 5 | "keywords": [ 6 | "blaspsoft", 7 | "doxswap" 8 | ], 9 | "homepage": "https://github.com/blaspsoft/doxswap", 10 | "license": "MIT", 11 | "type": "library", 12 | "authors": [ 13 | { 14 | "name": "Michael Deeming", 15 | "email": "mike.deeming@blaspsoft.com", 16 | "role": "Developer" 17 | } 18 | ], 19 | "require": { 20 | "php": "^8.2", 21 | "blaspsoft/onym": "dev-main", 22 | "illuminate/support": "^8.0|^9.0|^10.0|^11.0|^12.0" 23 | }, 24 | "require-dev": { 25 | "orchestra/testbench": "^10.0", 26 | "phpunit/phpunit": "^11.0" 27 | }, 28 | "autoload": { 29 | "psr-4": { 30 | "Blaspsoft\\Doxswap\\": "src" 31 | } 32 | }, 33 | "autoload-dev": { 34 | "psr-4": { 35 | "Blaspsoft\\Doxswap\\Tests\\": "tests" 36 | } 37 | }, 38 | "scripts": { 39 | "test": "vendor/bin/phpunit", 40 | "test-coverage": "vendor/bin/phpunit --coverage-html coverage" 41 | }, 42 | "config": { 43 | "sort-packages": true 44 | }, 45 | "extra": { 46 | "laravel": { 47 | "providers": [ 48 | "Blaspsoft\\Doxswap\\DoxswapServiceProvider" 49 | ], 50 | "aliases": { 51 | "Doxswap": "Blaspsoft\\Doxswap\\Facades\\Doxswap" 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /config/config.php: -------------------------------------------------------------------------------- 1 | 'public', 14 | 15 | /* 16 | |-------------------------------------------------------------------------- 17 | | Output Disk 18 | |-------------------------------------------------------------------------- 19 | | 20 | | Here you may specify the disk to use for storing the converted files. 21 | | 22 | */ 23 | 'output_disk' => 'public', 24 | 25 | /* 26 | |-------------------------------------------------------------------------- 27 | | Cleanup 28 | |-------------------------------------------------------------------------- 29 | | 30 | | Here you may specify if the input file should be deleted after the conversion. 31 | | 32 | */ 33 | 'perform_cleanup' => false, 34 | 35 | /* 36 | |-------------------------------------------------------------------------- 37 | | File Naming Strategy 38 | |-------------------------------------------------------------------------- 39 | | 40 | | Here you may specify the file naming strategy to use. 41 | | This strategy is used to rename the output file. 42 | | 43 | */ 44 | 'filename' => [ 45 | 46 | /* 47 | |-------------------------------------------------------------------------- 48 | | Strategy 49 | |-------------------------------------------------------------------------- 50 | | 51 | | The strategy to use for the file naming. 52 | | 53 | | Supported strategies: 54 | | - original: The original file name is used. 55 | | - random: A random file name is generated. 56 | | - timestamp: A timestamp is generated. 57 | | 58 | */ 59 | 'strategy' => 'original', 60 | 61 | /* 62 | |-------------------------------------------------------------------------- 63 | | Options 64 | |-------------------------------------------------------------------------- 65 | | 66 | | The options to use for the file naming. 67 | | 68 | | Supported options: 69 | | - length: The length of the random file name. 70 | | - prefix: The prefix of the file name. 71 | | - suffix: The suffix of the file name. 72 | | - separator: The separator of the file name. 73 | | - format: The format of the timestamp. 74 | | 75 | */ 76 | 'options' => [ 77 | 'length' => 24, 78 | 'prefix' => '', 79 | 'suffix' => '', 80 | 'separator' => '_', 81 | 'format' => 'YmdHis', 82 | ], 83 | ], 84 | 85 | 86 | /* 87 | |-------------------------------------------------------------------------- 88 | | Drivers 89 | |-------------------------------------------------------------------------- 90 | | 91 | | Here you may specify the drivers to use for the conversion. 92 | | 93 | | Supported drivers: 94 | | - libreoffice: The LibreOffice driver. 95 | | 96 | */ 97 | 'drivers' => [ 98 | 'libreoffice_path' => env('LIBRE_OFFICE_PATH', '/usr/bin/soffice'), 99 | ], 100 | ]; 101 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | ./tests/Unit 11 | 12 | 13 | ./tests/Integration 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/Contracts/ConversionStrategy.php: -------------------------------------------------------------------------------- 1 | inputDisk = config('doxswap.input_disk'); 31 | 32 | $this->performCleanup = config('doxswap.perform_cleanup'); 33 | } 34 | 35 | /** 36 | * Cleanup the input file and output files based on the strategy. 37 | * 38 | * @param string $inputFile 39 | * @return void 40 | */ 41 | public function cleanup(string $inputFile): void 42 | { 43 | if ($this->performCleanup) { 44 | Storage::disk($this->inputDisk)->delete($inputFile); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /src/ConversionResult.php: -------------------------------------------------------------------------------- 1 | inputDisk = config('doxswap.input_disk'); 94 | $this->outputDisk = config('doxswap.output_disk'); 95 | $this->inputFilename = basename($inputFilePath); 96 | $this->inputFilePath = $inputFilePath; 97 | $this->outputFilename = basename($outputFilePath); 98 | $this->outputFilePath = $outputFilePath; 99 | $this->toFormat = $toFormat; 100 | $this->startTime = $startTime; 101 | $this->endTime = $endTime; 102 | $this->duration = $this->formatDuration($endTime - $startTime); 103 | } 104 | 105 | /** 106 | * Format the duration of the conversion. 107 | * 108 | * @param float $seconds 109 | * @return string 110 | */ 111 | protected function formatDuration(float $seconds): string 112 | { 113 | if ($seconds < 1) { 114 | return round($seconds * 1000) . ' ms'; 115 | } 116 | 117 | return round($seconds, 2) . ' sec'; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /src/Doxswap.php: -------------------------------------------------------------------------------- 1 | formatRegistry = new FormatRegistry(); 39 | 40 | $this->cleanup = new ConversionCleanup(); 41 | } 42 | 43 | /** 44 | * Convert a file to a different format 45 | * 46 | * @param string $file The absolute path to the file to convert 47 | * @param string $toFormat The format to convert the file to 48 | * @return \Blaspsoft\Doxswap\ConversionResult 49 | */ 50 | public function convert(string $file, string $toFormat): ConversionResult 51 | { 52 | $this->result = $this->formatRegistry->convert($file, $toFormat); 53 | 54 | $this->cleanup->cleanup($this->result->inputFilename); 55 | 56 | return $this->result; 57 | } 58 | } 59 | 60 | -------------------------------------------------------------------------------- /src/DoxswapServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->runningInConsole()) { 17 | $this->publishes([ 18 | __DIR__.'/../config/config.php' => config_path('doxswap.php'), 19 | ], 'doxswap-config'); 20 | } 21 | } 22 | 23 | /** 24 | * Register the application services. 25 | */ 26 | public function register() 27 | { 28 | $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'doxswap'); 29 | 30 | $this->app->bind('doxswap', function () { 31 | return new Doxswap(); 32 | }); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Exceptions/ConversionFailedException.php: -------------------------------------------------------------------------------- 1 | strategy = config('doxswap.filename.strategy'); 40 | 41 | $this->options = config('doxswap.filename.options'); 42 | 43 | $this->outputDisk = config('doxswap.output_disk'); 44 | } 45 | 46 | /** 47 | * Generate a file name based on the strategy. 48 | * 49 | * @param string $filePath 50 | * @return string 51 | */ 52 | protected function generateFileName(string $filePath): string 53 | { 54 | $extension = pathinfo($filePath, PATHINFO_EXTENSION); 55 | 56 | return match ($this->strategy) { 57 | 'original' => basename($filePath), 58 | 'random' => Onym::make(strategy: 'random', extension: $extension, options: $this->options), 59 | 'timestamp' => Onym::make(strategy: 'timestamp', extension: $extension, options: $this->options), 60 | }; 61 | } 62 | 63 | /** 64 | * Rename the file. 65 | * 66 | * @param string $filePath 67 | * @return string 68 | */ 69 | public static function rename(string $filePath): string 70 | { 71 | $instance = new self(); 72 | 73 | $filename = $instance->generateFileName($filePath); 74 | 75 | $newOutputFilePath = Storage::disk($instance->outputDisk)->path($filename); 76 | 77 | File::move($filePath, $newOutputFilePath); 78 | 79 | return $newOutputFilePath; 80 | } 81 | } -------------------------------------------------------------------------------- /src/FormatRegistry.php: -------------------------------------------------------------------------------- 1 | inputDisk = config('doxswap.input_disk'); 57 | 58 | $this->register(new DocFormat()); 59 | 60 | $this->register(new DocxFormat()); 61 | 62 | $this->register(new OdtFormat()); 63 | 64 | $this->register(new RtfFormat()); 65 | 66 | $this->register(new TxtFormat()); 67 | 68 | $this->register(new HtmlFormat()); 69 | 70 | $this->register(new XmlFormat()); 71 | 72 | $this->register(new XlsFormat()); 73 | 74 | $this->register(new XlsxFormat()); 75 | 76 | $this->register(new OdsFormat()); 77 | 78 | $this->register(new PptxFormat()); 79 | 80 | $this->register(new PptFormat()); 81 | 82 | $this->register(new OdpFormat()); 83 | 84 | $this->register(new SvgFormat()); 85 | 86 | $this->register(new JpgFormat()); 87 | 88 | $this->register(new PngFormat()); 89 | 90 | $this->register(new BmpFormat()); 91 | 92 | $this->register(new CsvFormat()); 93 | 94 | $this->register(new TiffFormat()); 95 | 96 | $this->register(new GifFormat()); 97 | 98 | $this->register(new WebpFormat()); 99 | } 100 | 101 | /** 102 | * Register a format. 103 | * 104 | * @param \Blaspsoft\Doxswap\Contracts\ConvertibleFormat $format 105 | * @return void 106 | */ 107 | public function register(ConvertibleFormat $format): void 108 | { 109 | $this->formats[$format->getName()] = $format; 110 | } 111 | 112 | /** 113 | * Get a format by name. 114 | * 115 | * @param string $name 116 | * @return \Blaspsoft\Doxswap\Contracts\ConvertibleFormat 117 | */ 118 | public function getFormat(string $name): ConvertibleFormat 119 | { 120 | return $this->formats[$name]; 121 | } 122 | 123 | /** 124 | * Get all formats. 125 | * 126 | * @return array 127 | */ 128 | public function getAllFormats(): array 129 | { 130 | return $this->formats; 131 | } 132 | 133 | /** 134 | * Check if a conversion is supported. 135 | * 136 | * @param \Blaspsoft\Doxswap\Contracts\ConvertibleFormat $inputFormat 137 | * @param string $outputFormat 138 | * @return bool 139 | */ 140 | public function isSupportedConversion(ConvertibleFormat $inputFormat, string $outputFormat): bool 141 | { 142 | return in_array($outputFormat, $inputFormat->getSupportedConversions()); 143 | } 144 | 145 | /** 146 | * Check if a mime type is supported. 147 | * 148 | * @param \Blaspsoft\Doxswap\Contracts\ConvertibleFormat $format 149 | * @param string $mimeType 150 | * @return bool 151 | */ 152 | public function isSupportedMimeType(ConvertibleFormat $format, string $mimeType): bool 153 | { 154 | return in_array($mimeType, $format->getMimeTypes()); 155 | } 156 | 157 | /** 158 | * Detect the mime type of a zip file. 159 | * 160 | * @param string $inputFile 161 | * @return string 162 | */ 163 | protected function detectZipBasedMimeType(string $inputFile): string 164 | { 165 | $zip = new \ZipArchive(); 166 | 167 | if ($zip->open($inputFile) === TRUE) { 168 | $mimetype = $zip->getFromName('mimetype'); 169 | $zip->close(); 170 | 171 | if ($mimetype !== false) { 172 | return trim($mimetype); 173 | } 174 | } 175 | 176 | return "application/zip"; 177 | } 178 | 179 | /** 180 | * Convert a file to a new format. 181 | * 182 | * @param string $inputFile 183 | * @param string $toFormat 184 | * @return \Blaspsoft\Doxswap\ConversionResult 185 | * @throws \Blaspsoft\Doxswap\Exceptions\InputFileNotFoundException 186 | * @throws \Blaspsoft\Doxswap\Exceptions\UnsupportedConversionException 187 | * @throws \Blaspsoft\Doxswap\Exceptions\UnsupportedMimeTypeException 188 | */ 189 | public function convert(string $inputFile, string $toFormat): ConversionResult 190 | { 191 | if (!Storage::disk($this->inputDisk)->exists($inputFile)) { 192 | throw new InputFileNotFoundException($inputFile); 193 | } 194 | 195 | $inputFile = Storage::disk($this->inputDisk)->path($inputFile); 196 | 197 | $inputFormat = $this->getFormat(pathinfo($inputFile, PATHINFO_EXTENSION)); 198 | 199 | if (!$this->isSupportedConversion($inputFormat, $toFormat)) { 200 | throw new UnsupportedConversionException($inputFormat->getName(), $toFormat); 201 | } 202 | 203 | $mimeType = File::mimeType($inputFile); 204 | 205 | if ($mimeType === 'application/zip') { 206 | $mimeType = $this->detectZipBasedMimeType($inputFile); 207 | } 208 | 209 | if (!$this->isSupportedMimeType($inputFormat, $mimeType)) { 210 | throw new UnsupportedMimeTypeException($inputFormat->getName(), $toFormat); 211 | } 212 | 213 | return $inputFormat->convert($inputFile, $toFormat); 214 | } 215 | } 216 | -------------------------------------------------------------------------------- /src/Formats/BmpFormat.php: -------------------------------------------------------------------------------- 1 | getDriver($toFormat)->convert($inputFile, $this->getName(), $toFormat); 65 | } 66 | } -------------------------------------------------------------------------------- /src/Formats/CsvFormat.php: -------------------------------------------------------------------------------- 1 | getDriver()->convert($inputFile, $this->getName(), $toFormat); 62 | } 63 | } -------------------------------------------------------------------------------- /src/Formats/DocFormat.php: -------------------------------------------------------------------------------- 1 | getDriver()->convert($inputFile, $this->getName(), $toFormat); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Formats/DocxFormat.php: -------------------------------------------------------------------------------- 1 | getDriver()->convert($inputFile, $this->getName(), $toFormat); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Formats/GifFormat.php: -------------------------------------------------------------------------------- 1 | getDriver($toFormat)->convert($inputFile, $this->getName(), $toFormat); 65 | } 66 | } -------------------------------------------------------------------------------- /src/Formats/HtmlFormat.php: -------------------------------------------------------------------------------- 1 | getDriver()->convert($inputFile, $this->getName(), $toFormat); 62 | } 63 | } -------------------------------------------------------------------------------- /src/Formats/JpgFormat.php: -------------------------------------------------------------------------------- 1 | getDriver($toFormat)->convert($inputFile, $this->getName(), $toFormat); 65 | } 66 | } -------------------------------------------------------------------------------- /src/Formats/OdpFormat.php: -------------------------------------------------------------------------------- 1 | getDriver()->convert($inputFile, $this->getName(), $toFormat); 62 | } 63 | } -------------------------------------------------------------------------------- /src/Formats/OdsFormat.php: -------------------------------------------------------------------------------- 1 | getDriver()->convert($inputFile, $this->getName(), $toFormat); 62 | } 63 | } -------------------------------------------------------------------------------- /src/Formats/OdtFormat.php: -------------------------------------------------------------------------------- 1 | getDriver()->convert($inputFile, $this->getName(), $toFormat); 62 | } 63 | } -------------------------------------------------------------------------------- /src/Formats/PngFormat.php: -------------------------------------------------------------------------------- 1 | getDriver($toFormat)->convert($inputFile, $this->getName(), $toFormat); 65 | } 66 | } -------------------------------------------------------------------------------- /src/Formats/PptFormat.php: -------------------------------------------------------------------------------- 1 | getDriver()->convert($inputFile, $this->getName(), $toFormat); 62 | } 63 | } -------------------------------------------------------------------------------- /src/Formats/PptxFormat.php: -------------------------------------------------------------------------------- 1 | getDriver()->convert($inputFile, $this->getName(), $toFormat); 62 | } 63 | } -------------------------------------------------------------------------------- /src/Formats/RtfFormat.php: -------------------------------------------------------------------------------- 1 | getDriver()->convert($inputFile, $this->getName(), $toFormat); 62 | } 63 | } -------------------------------------------------------------------------------- /src/Formats/SvgFormat.php: -------------------------------------------------------------------------------- 1 | getDriver($toFormat)->convert($inputFile, $this->getName(), $toFormat); 65 | } 66 | } -------------------------------------------------------------------------------- /src/Formats/TiffFormat.php: -------------------------------------------------------------------------------- 1 | getDriver($toFormat)->convert($inputFile, $this->getName(), $toFormat); 65 | } 66 | } -------------------------------------------------------------------------------- /src/Formats/TxtFormat.php: -------------------------------------------------------------------------------- 1 | getDriver()->convert($inputFile, $this->getName(), $toFormat); 62 | } 63 | } -------------------------------------------------------------------------------- /src/Formats/WebpFormat.php: -------------------------------------------------------------------------------- 1 | getDriver($toFormat)->convert($inputFile, $this->getName(), $toFormat); 65 | } 66 | } -------------------------------------------------------------------------------- /src/Formats/XlsFormat.php: -------------------------------------------------------------------------------- 1 | getDriver()->convert($inputFile, $this->getName(), $toFormat); 62 | } 63 | } -------------------------------------------------------------------------------- /src/Formats/XlsxFormat.php: -------------------------------------------------------------------------------- 1 | getDriver()->convert($inputFile, $this->getName(), $toFormat); 62 | } 63 | } -------------------------------------------------------------------------------- /src/Formats/XmlFormat.php: -------------------------------------------------------------------------------- 1 | getDriver()->convert($inputFile, $this->getName(), $toFormat); 62 | } 63 | } -------------------------------------------------------------------------------- /src/Strategies/ImageMagick.php: -------------------------------------------------------------------------------- 1 | inputDisk = config('doxswap.input_disk'); 42 | $this->outputDisk = config('doxswap.output_disk'); 43 | } 44 | 45 | /** 46 | * Convert a file to a new format using Imagick. 47 | * 48 | * @param string $inputFile 49 | * @param string $fromFormat 50 | * @param string $toFormat 51 | * @return \Blaspsoft\Doxswap\ConversionResult 52 | * 53 | * @throws \Exception 54 | */ 55 | public function convert(string $inputFile, string $fromFormat, string $toFormat): ConversionResult 56 | { 57 | if (!extension_loaded('imagick')) { 58 | throw new Exception('Imagick extension is not installed or enabled.'); 59 | } 60 | 61 | if (!in_array(strtolower($fromFormat), $this->supportedFormats) || !in_array(strtolower($toFormat), $this->supportedFormats)) { 62 | throw new Exception("Conversion from $fromFormat to $toFormat is not supported by ImageMagick."); 63 | } 64 | 65 | $outputFile = Storage::disk($this->outputDisk)->path(str_replace($fromFormat, $toFormat, basename($inputFile))); 66 | 67 | $startTime = (float) microtime(true); 68 | 69 | try { 70 | $imagick = new Imagick(); 71 | $imagick->readImage($inputFile); 72 | $imagick->setImageFormat($toFormat); 73 | $imagick->writeImage($outputFile); 74 | $imagick->clear(); 75 | $imagick->destroy(); 76 | } catch (Exception $e) { 77 | throw new ConversionFailedException("ImageMagick conversion failed: " . $e->getMessage()); 78 | } 79 | 80 | $endTime = (float) microtime(true); 81 | 82 | if (!Storage::disk($this->outputDisk)->exists(basename($outputFile))) { 83 | throw new ConversionFailedException("Converted file was not created."); 84 | } 85 | 86 | $outputFile = Filename::rename($outputFile); 87 | 88 | return new ConversionResult( 89 | inputFilePath: $inputFile, 90 | outputFilePath: $outputFile, 91 | toFormat: $toFormat, 92 | startTime: $startTime, 93 | endTime: $endTime 94 | ); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/Strategies/LibreOffice.php: -------------------------------------------------------------------------------- 1 | path = config('doxswap.drivers.libreoffice_path'); 44 | 45 | $this->inputDisk = config('doxswap.input_disk'); 46 | 47 | $this->outputDisk = config('doxswap.output_disk'); 48 | } 49 | 50 | /** 51 | * Convert a file to a new format. 52 | * 53 | * @param string $inputFile 54 | * @param string $fromFormat 55 | * @param string $toFormat 56 | * @return \Blaspsoft\Doxswap\ConversionResult 57 | */ 58 | public function convert(string $inputFile, string $fromFormat, string $toFormat): ConversionResult 59 | { 60 | $outputFile = Storage::disk($this->outputDisk)->path(str_replace($fromFormat, $toFormat, basename($inputFile))); 61 | 62 | $startTime = (float) microtime(true); 63 | 64 | $command = [ 65 | $this->path, // Path to the LibreOffice binary 66 | '--headless', // Run in headless mode 67 | '--convert-to', $toFormat , // Convert to the specified format 68 | '--outdir', Storage::disk($this->outputDisk)->path(''), // Output directory 69 | $inputFile, // Input file 70 | ]; 71 | 72 | $process = new Process($command); 73 | $process->run(); 74 | 75 | $endTime = (float) microtime(true); 76 | 77 | if (!$process->isSuccessful()) { 78 | throw new ProcessFailedException($process); 79 | } 80 | 81 | if (!Storage::disk($this->outputDisk)->exists(basename($outputFile))) { 82 | throw new ConversionFailedException(); 83 | } 84 | 85 | $outputFile = Filename::rename($outputFile); 86 | 87 | return new ConversionResult( 88 | inputFilePath: $inputFile, 89 | outputFilePath: $outputFile, 90 | toFormat: $toFormat, 91 | startTime: $startTime, 92 | endTime: $endTime 93 | ); 94 | } 95 | } -------------------------------------------------------------------------------- /tests/Integration/BmpConversionTest.php: -------------------------------------------------------------------------------- 1 | doxswap = new Doxswap(); 20 | } 21 | 22 | public function testBmpToPdfConversion() 23 | { 24 | Storage::disk('local')->put('test.bmp', file_get_contents(__DIR__ . '/../Stubs/sample.bmp')); 25 | $this->doxswap->convert('test.bmp', 'pdf'); 26 | $this->assertTrue(Storage::disk('local')->exists('test.pdf')); 27 | } 28 | 29 | public function testBmpToJpgConversion() 30 | { 31 | Storage::disk('local')->put('test.bmp', file_get_contents(__DIR__ . '/../Stubs/sample.bmp')); 32 | $this->doxswap->convert('test.bmp', 'jpg'); 33 | $this->assertTrue(Storage::disk('local')->exists('test.jpg')); 34 | } 35 | 36 | public function testBmpToPngConversion() 37 | { 38 | Storage::disk('local')->put('test.bmp', file_get_contents(__DIR__ . '/../Stubs/sample.bmp')); 39 | $this->doxswap->convert('test.bmp', 'png'); 40 | $this->assertTrue(Storage::disk('local')->exists('test.png')); 41 | } 42 | 43 | public function testBmpToSvgConversion() 44 | { 45 | Storage::disk('local')->put('test.bmp', file_get_contents(__DIR__ . '/../Stubs/sample.bmp')); 46 | $this->doxswap->convert('test.bmp', 'svg'); 47 | $this->assertTrue(Storage::disk('local')->exists('test.svg')); 48 | } 49 | 50 | public function testBmpToTiffConversion() 51 | { 52 | Storage::disk('local')->put('test.bmp', file_get_contents(__DIR__ . '/../Stubs/sample.bmp')); 53 | $this->doxswap->convert('test.bmp', 'tiff'); 54 | $this->assertTrue(Storage::disk('local')->exists('test.tiff')); 55 | } 56 | 57 | public function testBmpToWebpConversion() 58 | { 59 | Storage::disk('local')->put('test.bmp', file_get_contents(__DIR__ . '/../Stubs/sample.bmp')); 60 | $this->doxswap->convert('test.bmp', 'webp'); 61 | $this->assertTrue(Storage::disk('local')->exists('test.webp')); 62 | } 63 | 64 | public function testBmpToGifConversion() 65 | { 66 | Storage::disk('local')->put('test.bmp', file_get_contents(__DIR__ . '/../Stubs/sample.bmp')); 67 | $this->doxswap->convert('test.bmp', 'gif'); 68 | $this->assertTrue(Storage::disk('local')->exists('test.gif')); 69 | } 70 | } -------------------------------------------------------------------------------- /tests/Integration/CsvConversionTest.php: -------------------------------------------------------------------------------- 1 | doxswap = new Doxswap(); 20 | } 21 | 22 | public function testCsvToPdfConversion() 23 | { 24 | Storage::disk('local')->put('test.csv', file_get_contents(__DIR__ . '/../Stubs/sample.csv')); 25 | 26 | $this->doxswap->convert('test.csv', 'pdf'); 27 | $this->assertTrue(Storage::disk('local')->exists('test.pdf')); 28 | } 29 | 30 | public function testCsvToXlsxConversion() 31 | { 32 | Storage::disk('local')->put('test.csv', file_get_contents(__DIR__ . '/../Stubs/sample.csv')); 33 | $this->doxswap->convert('test.csv', 'xlsx'); 34 | $this->assertTrue(Storage::disk('local')->exists('test.xlsx')); 35 | } 36 | 37 | public function testCsvToOdsConversion() 38 | { 39 | Storage::disk('local')->put('test.csv', file_get_contents(__DIR__ . '/../Stubs/sample.csv')); 40 | $this->doxswap->convert('test.csv', 'ods'); 41 | $this->assertTrue(Storage::disk('local')->exists('test.ods')); 42 | } 43 | 44 | public function testCsvToHtmlConversion() 45 | { 46 | Storage::disk('local')->put('test.csv', file_get_contents(__DIR__ . '/../Stubs/sample.csv')); 47 | $this->doxswap->convert('test.csv', 'html'); 48 | $this->assertTrue(Storage::disk('local')->exists('test.html')); 49 | } 50 | } -------------------------------------------------------------------------------- /tests/Integration/DocConversionTest.php: -------------------------------------------------------------------------------- 1 | doxswap = new Doxswap(); 20 | } 21 | 22 | public function testDocToPdfConversion() 23 | { 24 | Storage::disk('local')->put('test.doc', file_get_contents(__DIR__ . '/../Stubs/sample.doc')); 25 | $this->doxswap->convert('test.doc', 'pdf'); 26 | $this->assertTrue(Storage::disk('local')->exists('test.pdf')); 27 | } 28 | 29 | public function testDocToDocxConversion() 30 | { 31 | Storage::disk('local')->put('test.doc', file_get_contents(__DIR__ . '/../Stubs/sample.doc')); 32 | $this->doxswap->convert('test.doc', 'docx'); 33 | $this->assertTrue(Storage::disk('local')->exists('test.docx')); 34 | } 35 | 36 | public function testDocToOdtConversion() 37 | { 38 | Storage::disk('local')->put('test.doc', file_get_contents(__DIR__ . '/../Stubs/sample.doc')); 39 | $this->doxswap->convert('test.doc', 'odt'); 40 | $this->assertTrue(Storage::disk('local')->exists('test.odt')); 41 | } 42 | 43 | public function testDocToRtfConversion() 44 | { 45 | Storage::disk('local')->put('test.doc', file_get_contents(__DIR__ . '/../Stubs/sample.doc')); 46 | $this->doxswap->convert('test.doc', 'rtf'); 47 | $this->assertTrue(Storage::disk('local')->exists('test.rtf')); 48 | } 49 | 50 | public function testDocToTxtConversion() 51 | { 52 | Storage::disk('local')->put('test.doc', file_get_contents(__DIR__ . '/../Stubs/sample.doc')); 53 | $this->doxswap->convert('test.doc', 'txt'); 54 | $this->assertTrue(Storage::disk('local')->exists('test.txt')); 55 | } 56 | 57 | public function testDocToHtmlConversion() 58 | { 59 | Storage::disk('local')->put('test.doc', file_get_contents(__DIR__ . '/../Stubs/sample.doc')); 60 | $this->doxswap->convert('test.doc', 'html'); 61 | $this->assertTrue(Storage::disk('local')->exists('test.html')); 62 | } 63 | 64 | public function testDocToEpubConversion() 65 | { 66 | Storage::disk('local')->put('test.doc', file_get_contents(__DIR__ . '/../Stubs/sample.doc')); 67 | $this->doxswap->convert('test.doc', 'epub'); 68 | $this->assertTrue(Storage::disk('local')->exists('test.epub')); 69 | } 70 | 71 | public function testDocToXmlConversion() 72 | { 73 | Storage::disk('local')->put('test.doc', file_get_contents(__DIR__ . '/../Stubs/sample.doc')); 74 | $this->doxswap->convert('test.doc', 'xml'); 75 | $this->assertTrue(Storage::disk('local')->exists('test.xml')); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /tests/Integration/DocxConversionTest.php: -------------------------------------------------------------------------------- 1 | doxswap = new Doxswap(); 20 | } 21 | 22 | public function testDocxToPdfConversion() 23 | { 24 | Storage::disk('local')->put('test.docx', file_get_contents(__DIR__ . '/../Stubs/sample.docx')); 25 | $this->doxswap->convert('test.docx', 'pdf'); 26 | 27 | $this->assertTrue(Storage::disk('local')->exists('test.pdf')); 28 | } 29 | 30 | public function testDocxToOdtConversion() 31 | { 32 | Storage::disk('local')->put('test.docx', file_get_contents(__DIR__ . '/../Stubs/sample.docx')); 33 | $this->doxswap->convert('test.docx', 'odt'); 34 | 35 | $this->assertTrue(Storage::disk('local')->exists('test.odt')); 36 | } 37 | 38 | public function testDocxToRtfConversion() 39 | { 40 | Storage::disk('local')->put('test.docx', file_get_contents(__DIR__ . '/../Stubs/sample.docx')); 41 | $this->doxswap->convert('test.docx', 'rtf'); 42 | 43 | $this->assertTrue(Storage::disk('local')->exists('test.rtf')); 44 | } 45 | 46 | public function testDocxToTxtConversion() 47 | { 48 | Storage::disk('local')->put('test.docx', file_get_contents(__DIR__ . '/../Stubs/sample.docx')); 49 | $this->doxswap->convert('test.docx', 'txt'); 50 | 51 | $this->assertTrue(Storage::disk('local')->exists('test.txt')); 52 | } 53 | 54 | public function testDocxToHtmlConversion() 55 | { 56 | Storage::disk('local')->put('test.docx', file_get_contents(__DIR__ . '/../Stubs/sample.docx')); 57 | $this->doxswap->convert('test.docx', 'html'); 58 | 59 | $this->assertTrue(Storage::disk('local')->exists('test.html')); 60 | } 61 | 62 | public function testDocxToEpubConversion() 63 | { 64 | Storage::disk('local')->put('test.docx', file_get_contents(__DIR__ . '/../Stubs/sample.docx')); 65 | $this->doxswap->convert('test.docx', 'epub'); 66 | 67 | $this->assertTrue(Storage::disk('local')->exists('test.epub')); 68 | } 69 | 70 | public function testDocxToXmlConversion() 71 | { 72 | Storage::disk('local')->put('test.docx', file_get_contents(__DIR__ . '/../Stubs/sample.docx')); 73 | $this->doxswap->convert('test.docx', 'xml'); 74 | 75 | $this->assertTrue(Storage::disk('local')->exists('test.xml')); 76 | } 77 | } -------------------------------------------------------------------------------- /tests/Integration/GifConversionTest.php: -------------------------------------------------------------------------------- 1 | doxswap = new Doxswap(); 20 | } 21 | 22 | public function testGifToPdfConversion() 23 | { 24 | Storage::disk('local')->put('test.gif', file_get_contents(__DIR__ . '/../Stubs/sample.gif')); 25 | $this->doxswap->convert('test.gif', 'pdf'); 26 | $this->assertTrue(Storage::disk('local')->exists('test.pdf')); 27 | } 28 | 29 | public function testGifToPngConversion() 30 | { 31 | Storage::disk('local')->put('test.gif', file_get_contents(__DIR__ . '/../Stubs/sample.gif')); 32 | $this->doxswap->convert('test.gif', 'png'); 33 | $this->assertTrue(Storage::disk('local')->exists('test.png')); 34 | } 35 | 36 | public function testGifToJpgConversion() 37 | { 38 | Storage::disk('local')->put('test.gif', file_get_contents(__DIR__ . '/../Stubs/sample.gif')); 39 | $this->doxswap->convert('test.gif', 'jpg'); 40 | $this->assertTrue(Storage::disk('local')->exists('test.jpg')); 41 | } 42 | 43 | public function testGifToTiffConversion() 44 | { 45 | Storage::disk('local')->put('test.gif', file_get_contents(__DIR__ . '/../Stubs/sample.gif')); 46 | $this->doxswap->convert('test.gif', 'tiff'); 47 | $this->assertTrue(Storage::disk('local')->exists('test.tiff')); 48 | } 49 | 50 | public function testGifToBmpConversion() 51 | { 52 | Storage::disk('local')->put('test.gif', file_get_contents(__DIR__ . '/../Stubs/sample.gif')); 53 | $this->doxswap->convert('test.gif', 'bmp'); 54 | $this->assertTrue(Storage::disk('local')->exists('test.bmp')); 55 | } 56 | 57 | public function testGifToWebpConversion() 58 | { 59 | Storage::disk('local')->put('test.gif', file_get_contents(__DIR__ . '/../Stubs/sample.gif')); 60 | $this->doxswap->convert('test.gif', 'webp'); 61 | $this->assertTrue(Storage::disk('local')->exists('test.webp')); 62 | } 63 | 64 | public function testGifToSvgConversion() 65 | { 66 | Storage::disk('local')->put('test.gif', file_get_contents(__DIR__ . '/../Stubs/sample.gif')); 67 | $this->doxswap->convert('test.gif', 'svg'); 68 | $this->assertTrue(Storage::disk('local')->exists('test.svg')); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /tests/Integration/HtmlConversionTest.php: -------------------------------------------------------------------------------- 1 | doxswap = new Doxswap(); 20 | } 21 | 22 | public function testHtmlToPdfConversion() 23 | { 24 | Storage::disk('local')->put('test.html', file_get_contents(__DIR__ . '/../Stubs/sample.html')); 25 | $this->doxswap->convert('test.html', 'pdf'); 26 | $this->assertTrue(Storage::disk('local')->exists('test.pdf')); 27 | } 28 | 29 | public function testHtmlToOdtConversion() 30 | { 31 | Storage::disk('local')->put('test.html', file_get_contents(__DIR__ . '/../Stubs/sample.html')); 32 | $this->doxswap->convert('test.html', 'odt'); 33 | $this->assertTrue(Storage::disk('local')->exists('test.odt')); 34 | } 35 | 36 | public function testHtmlToTxtConversion() 37 | { 38 | Storage::disk('local')->put('test.html', file_get_contents(__DIR__ . '/../Stubs/sample.html')); 39 | $this->doxswap->convert('test.html', 'txt'); 40 | $this->assertTrue(Storage::disk('local')->exists('test.txt')); 41 | } 42 | } -------------------------------------------------------------------------------- /tests/Integration/JpgConversionTest.php: -------------------------------------------------------------------------------- 1 | doxswap = new Doxswap(); 20 | } 21 | 22 | public function testJpgToPdfConversion() 23 | { 24 | Storage::disk('local')->put('test.jpg', file_get_contents(__DIR__ . '/../Stubs/sample.jpg')); 25 | $this->doxswap->convert('test.jpg', 'pdf'); 26 | $this->assertTrue(Storage::disk('local')->exists('test.pdf')); 27 | } 28 | 29 | public function testJpgToPngConversion() 30 | { 31 | Storage::disk('local')->put('test.jpg', file_get_contents(__DIR__ . '/../Stubs/sample.jpg')); 32 | $this->doxswap->convert('test.jpg', 'png'); 33 | $this->assertTrue(Storage::disk('local')->exists('test.png')); 34 | } 35 | 36 | public function testJpgToSvgConversion() 37 | { 38 | Storage::disk('local')->put('test.jpg', file_get_contents(__DIR__ . '/../Stubs/sample.jpg')); 39 | $this->doxswap->convert('test.jpg', 'svg'); 40 | $this->assertTrue(Storage::disk('local')->exists('test.svg')); 41 | } 42 | 43 | public function testJpgToTiffConversion() 44 | { 45 | Storage::disk('local')->put('test.jpg', file_get_contents(__DIR__ . '/../Stubs/sample.jpg')); 46 | $this->doxswap->convert('test.jpg', 'tiff'); 47 | $this->assertTrue(Storage::disk('local')->exists('test.tiff')); 48 | } 49 | 50 | public function testJpgToBmpConversion() 51 | { 52 | Storage::disk('local')->put('test.jpg', file_get_contents(__DIR__ . '/../Stubs/sample.jpg')); 53 | $this->doxswap->convert('test.jpg', 'bmp'); 54 | $this->assertTrue(Storage::disk('local')->exists('test.bmp')); 55 | } 56 | 57 | public function testJpgToWebpConversion() 58 | { 59 | Storage::disk('local')->put('test.jpg', file_get_contents(__DIR__ . '/../Stubs/sample.jpg')); 60 | $this->doxswap->convert('test.jpg', 'webp'); 61 | $this->assertTrue(Storage::disk('local')->exists('test.webp')); 62 | } 63 | 64 | public function testJpgToGifConversion() 65 | { 66 | Storage::disk('local')->put('test.jpg', file_get_contents(__DIR__ . '/../Stubs/sample.jpg')); 67 | $this->doxswap->convert('test.jpg', 'gif'); 68 | $this->assertTrue(Storage::disk('local')->exists('test.gif')); 69 | } 70 | } -------------------------------------------------------------------------------- /tests/Integration/OdpConversionTest.php: -------------------------------------------------------------------------------- 1 | doxswap = new Doxswap(); 20 | } 21 | 22 | public function testOdpToPdfConversion() 23 | { 24 | Storage::disk('local')->put('test.odp', file_get_contents(__DIR__ . '/../Stubs/sample.odp')); 25 | $this->doxswap->convert('test.odp', 'pdf'); 26 | $this->assertTrue(Storage::disk('local')->exists('test.pdf')); 27 | } 28 | 29 | public function testOdpToPptxConversion() 30 | { 31 | Storage::disk('local')->put('test.odp', file_get_contents(__DIR__ . '/../Stubs/sample.odp')); 32 | $this->doxswap->convert('test.odp', 'pptx'); 33 | $this->assertTrue(Storage::disk('local')->exists('test.pptx')); 34 | } 35 | 36 | public function testOdpToPptConversion() 37 | { 38 | Storage::disk('local')->put('test.odp', file_get_contents(__DIR__ . '/../Stubs/sample.odp')); 39 | $this->doxswap->convert('test.odp', 'ppt'); 40 | $this->assertTrue(Storage::disk('local')->exists('test.ppt')); 41 | } 42 | } -------------------------------------------------------------------------------- /tests/Integration/OdsConversionTest.php: -------------------------------------------------------------------------------- 1 | doxswap = new Doxswap(); 20 | } 21 | 22 | public function testOdsToPdfConversion() 23 | { 24 | Storage::disk('local')->put('test.ods', file_get_contents(__DIR__ . '/../Stubs/sample.ods')); 25 | $this->doxswap->convert('test.ods', 'pdf'); 26 | $this->assertTrue(Storage::disk('local')->exists('test.pdf')); 27 | } 28 | 29 | public function testOdsToXlsxConversion() 30 | { 31 | Storage::disk('local')->put('test.ods', file_get_contents(__DIR__ . '/../Stubs/sample.ods')); 32 | $this->doxswap->convert('test.ods', 'xlsx'); 33 | $this->assertTrue(Storage::disk('local')->exists('test.xlsx')); 34 | } 35 | 36 | public function testOdsToXlsConversion() 37 | { 38 | Storage::disk('local')->put('test.ods', file_get_contents(__DIR__ . '/../Stubs/sample.ods')); 39 | $this->doxswap->convert('test.ods', 'xls'); 40 | $this->assertTrue(Storage::disk('local')->exists('test.xls')); 41 | } 42 | 43 | public function testOdsToCsvConversion() 44 | { 45 | Storage::disk('local')->put('test.ods', file_get_contents(__DIR__ . '/../Stubs/sample.ods')); 46 | $this->doxswap->convert('test.ods', 'csv'); 47 | $this->assertTrue(Storage::disk('local')->exists('test.csv')); 48 | } 49 | 50 | public function testOdsToHtmlConversion() 51 | { 52 | Storage::disk('local')->put('test.ods', file_get_contents(__DIR__ . '/../Stubs/sample.ods')); 53 | $this->doxswap->convert('test.ods', 'html'); 54 | $this->assertTrue(Storage::disk('local')->exists('test.html')); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /tests/Integration/OdtConversionTest.php: -------------------------------------------------------------------------------- 1 | doxswap = new Doxswap(); 20 | } 21 | 22 | public function testOdtToPdfConversion() 23 | { 24 | Storage::disk('local')->put('test.odt', file_get_contents(__DIR__ . '/../Stubs/sample.odt')); 25 | $this->doxswap->convert('test.odt', 'pdf'); 26 | $this->assertTrue(Storage::disk('local')->exists('test.pdf')); 27 | } 28 | 29 | public function testOdtToDocxConversion() 30 | { 31 | Storage::disk('local')->put('test.odt', file_get_contents(__DIR__ . '/../Stubs/sample.odt')); 32 | $this->doxswap->convert('test.odt', 'docx'); 33 | $this->assertTrue(Storage::disk('local')->exists('test.docx')); 34 | } 35 | 36 | public function testOdtToDocConversion() 37 | { 38 | Storage::disk('local')->put('test.odt', file_get_contents(__DIR__ . '/../Stubs/sample.odt')); 39 | $this->doxswap->convert('test.odt', 'doc'); 40 | $this->assertTrue(Storage::disk('local')->exists('test.doc')); 41 | } 42 | 43 | public function testOdtToTxtConversion() 44 | { 45 | Storage::disk('local')->put('test.odt', file_get_contents(__DIR__ . '/../Stubs/sample.odt')); 46 | $this->doxswap->convert('test.odt', 'txt'); 47 | $this->assertTrue(Storage::disk('local')->exists('test.txt')); 48 | } 49 | 50 | public function testOdtToHtmlConversion() 51 | { 52 | Storage::disk('local')->put('test.odt', file_get_contents(__DIR__ . '/../Stubs/sample.odt')); 53 | $this->doxswap->convert('test.odt', 'html'); 54 | $this->assertTrue(Storage::disk('local')->exists('test.html')); 55 | } 56 | 57 | public function testOdtToXmlConversion() 58 | { 59 | Storage::disk('local')->put('test.odt', file_get_contents(__DIR__ . '/../Stubs/sample.odt')); 60 | $this->doxswap->convert('test.odt', 'xml'); 61 | $this->assertTrue(Storage::disk('local')->exists('test.xml')); 62 | } 63 | 64 | public function testOdtToRtfConversion() 65 | { 66 | Storage::disk('local')->put('test.odt', file_get_contents(__DIR__ . '/../Stubs/sample.odt')); 67 | $this->doxswap->convert('test.odt', 'rtf'); 68 | $this->assertTrue(Storage::disk('local')->exists('test.rtf')); 69 | } 70 | } -------------------------------------------------------------------------------- /tests/Integration/PngConversionTest.php: -------------------------------------------------------------------------------- 1 | doxswap = new Doxswap(); 20 | } 21 | 22 | public function testPngToPdfConversion() 23 | { 24 | Storage::disk('local')->put('test.png', file_get_contents(__DIR__ . '/../Stubs/sample.png')); 25 | $this->doxswap->convert('test.png', 'pdf'); 26 | $this->assertTrue(Storage::disk('local')->exists('test.pdf')); 27 | } 28 | 29 | public function testPngToJpgConversion() 30 | { 31 | Storage::disk('local')->put('test.png', file_get_contents(__DIR__ . '/../Stubs/sample.png')); 32 | $this->doxswap->convert('test.png', 'jpg'); 33 | $this->assertTrue(Storage::disk('local')->exists('test.jpg')); 34 | } 35 | 36 | public function testPngToSvgConversion() 37 | { 38 | Storage::disk('local')->put('test.png', file_get_contents(__DIR__ . '/../Stubs/sample.png')); 39 | $this->doxswap->convert('test.png', 'svg'); 40 | $this->assertTrue(Storage::disk('local')->exists('test.svg')); 41 | } 42 | 43 | public function testPngToTiffConversion() 44 | { 45 | Storage::disk('local')->put('test.png', file_get_contents(__DIR__ . '/../Stubs/sample.png')); 46 | $this->doxswap->convert('test.png', 'tiff'); 47 | $this->assertTrue(Storage::disk('local')->exists('test.tiff')); 48 | } 49 | 50 | public function testPngToBmpConversion() 51 | { 52 | Storage::disk('local')->put('test.png', file_get_contents(__DIR__ . '/../Stubs/sample.png')); 53 | $this->doxswap->convert('test.png', 'bmp'); 54 | $this->assertTrue(Storage::disk('local')->exists('test.bmp')); 55 | } 56 | 57 | public function testPngToWebpConversion() 58 | { 59 | Storage::disk('local')->put('test.png', file_get_contents(__DIR__ . '/../Stubs/sample.png')); 60 | $this->doxswap->convert('test.png', 'webp'); 61 | $this->assertTrue(Storage::disk('local')->exists('test.webp')); 62 | } 63 | 64 | public function testPngToGifConversion() 65 | { 66 | Storage::disk('local')->put('test.png', file_get_contents(__DIR__ . '/../Stubs/sample.png')); 67 | $this->doxswap->convert('test.png', 'gif'); 68 | $this->assertTrue(Storage::disk('local')->exists('test.gif')); 69 | } 70 | } -------------------------------------------------------------------------------- /tests/Integration/PptConversionTest.php: -------------------------------------------------------------------------------- 1 | doxswap = new Doxswap(); 20 | } 21 | 22 | public function testPptToPdfConversion() 23 | { 24 | Storage::disk('local')->put('test.ppt', file_get_contents(__DIR__ . '/../Stubs/sample.ppt')); 25 | $this->doxswap->convert('test.ppt', 'pdf'); 26 | $this->assertTrue(Storage::disk('local')->exists('test.pdf')); 27 | } 28 | 29 | public function testPptToOdpConversion() 30 | { 31 | Storage::disk('local')->put('test.ppt', file_get_contents(__DIR__ . '/../Stubs/sample.ppt')); 32 | $this->doxswap->convert('test.ppt', 'odp'); 33 | $this->assertTrue(Storage::disk('local')->exists('test.odp')); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/Integration/PptxConversionTest.php: -------------------------------------------------------------------------------- 1 | doxswap = new Doxswap(); 20 | } 21 | 22 | public function testPptxToPdfConversion() 23 | { 24 | Storage::disk('local')->put('test.pptx', file_get_contents(__DIR__ . '/../Stubs/sample.pptx')); 25 | $this->doxswap->convert('test.pptx', 'pdf'); 26 | $this->assertTrue(Storage::disk('local')->exists('test.pdf')); 27 | } 28 | 29 | public function testPptxToOdpConversion() 30 | { 31 | Storage::disk('local')->put('test.pptx', file_get_contents(__DIR__ . '/../Stubs/sample.pptx')); 32 | $this->doxswap->convert('test.pptx', 'odp'); 33 | $this->assertTrue(Storage::disk('local')->exists('test.odp')); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/Integration/RtfConversionTest.php: -------------------------------------------------------------------------------- 1 | doxswap = new Doxswap(); 20 | } 21 | 22 | public function testRtfToPdfConversion() 23 | { 24 | Storage::disk('local')->put('test.rtf', file_get_contents(__DIR__ . '/../Stubs/sample.rtf')); 25 | $this->doxswap->convert('test.rtf', 'pdf'); 26 | $this->assertTrue(Storage::disk('local')->exists('test.pdf')); 27 | } 28 | 29 | public function testRtfToDocxConversion() 30 | { 31 | Storage::disk('local')->put('test.rtf', file_get_contents(__DIR__ . '/../Stubs/sample.rtf')); 32 | $this->doxswap->convert('test.rtf', 'docx'); 33 | $this->assertTrue(Storage::disk('local')->exists('test.docx')); 34 | } 35 | 36 | public function testRtfToOdtConversion() 37 | { 38 | Storage::disk('local')->put('test.rtf', file_get_contents(__DIR__ . '/../Stubs/sample.rtf')); 39 | $this->doxswap->convert('test.rtf', 'odt'); 40 | $this->assertTrue(Storage::disk('local')->exists('test.odt')); 41 | } 42 | 43 | public function testRtfToTxtConversion() 44 | { 45 | Storage::disk('local')->put('test.rtf', file_get_contents(__DIR__ . '/../Stubs/sample.rtf')); 46 | $this->doxswap->convert('test.rtf', 'txt'); 47 | $this->assertTrue(Storage::disk('local')->exists('test.txt')); 48 | } 49 | 50 | public function testRtfToHtmlConversion() 51 | { 52 | Storage::disk('local')->put('test.rtf', file_get_contents(__DIR__ . '/../Stubs/sample.rtf')); 53 | $this->doxswap->convert('test.rtf', 'html'); 54 | $this->assertTrue(Storage::disk('local')->exists('test.html')); 55 | } 56 | 57 | public function testRtfToXmlConversion() 58 | { 59 | Storage::disk('local')->put('test.rtf', file_get_contents(__DIR__ . '/../Stubs/sample.rtf')); 60 | $this->doxswap->convert('test.rtf', 'xml'); 61 | $this->assertTrue(Storage::disk('local')->exists('test.xml')); 62 | } 63 | } -------------------------------------------------------------------------------- /tests/Integration/SvgConversionTest.php: -------------------------------------------------------------------------------- 1 | doxswap = new Doxswap(); 20 | } 21 | 22 | public function testSvgToPdfConversion() 23 | { 24 | Storage::disk('local')->put('test.svg', file_get_contents(__DIR__ . '/../Stubs/sample.svg')); 25 | $this->doxswap->convert('test.svg', 'pdf'); 26 | $this->assertTrue(Storage::disk('local')->exists('test.pdf')); 27 | } 28 | 29 | public function testSvgToPngConversion() 30 | { 31 | Storage::disk('local')->put('test.svg', file_get_contents(__DIR__ . '/../Stubs/sample.svg')); 32 | $this->doxswap->convert('test.svg', 'png'); 33 | $this->assertTrue(Storage::disk('local')->exists('test.png')); 34 | } 35 | 36 | public function testSvgToJpgConversion() 37 | { 38 | Storage::disk('local')->put('test.svg', file_get_contents(__DIR__ . '/../Stubs/sample.svg')); 39 | $this->doxswap->convert('test.svg', 'jpg'); 40 | $this->assertTrue(Storage::disk('local')->exists('test.jpg')); 41 | } 42 | 43 | public function testSvgToTiffConversion() 44 | { 45 | Storage::disk('local')->put('test.svg', file_get_contents(__DIR__ . '/../Stubs/sample.svg')); 46 | $this->doxswap->convert('test.svg', 'tiff'); 47 | $this->assertTrue(Storage::disk('local')->exists('test.tiff')); 48 | } 49 | 50 | public function testSvgToBmpConversion() 51 | { 52 | Storage::disk('local')->put('test.svg', file_get_contents(__DIR__ . '/../Stubs/sample.svg')); 53 | $this->doxswap->convert('test.svg', 'bmp'); 54 | $this->assertTrue(Storage::disk('local')->exists('test.bmp')); 55 | } 56 | 57 | public function testSvgToWebpConversion() 58 | { 59 | Storage::disk('local')->put('test.svg', file_get_contents(__DIR__ . '/../Stubs/sample.svg')); 60 | $this->doxswap->convert('test.svg', 'webp'); 61 | $this->assertTrue(Storage::disk('local')->exists('test.webp')); 62 | } 63 | 64 | public function testSvgToGifConversion() 65 | { 66 | Storage::disk('local')->put('test.svg', file_get_contents(__DIR__ . '/../Stubs/sample.svg')); 67 | $this->doxswap->convert('test.svg', 'gif'); 68 | $this->assertTrue(Storage::disk('local')->exists('test.gif')); 69 | } 70 | } -------------------------------------------------------------------------------- /tests/Integration/TiffConversionTest.php: -------------------------------------------------------------------------------- 1 | doxswap = new Doxswap(); 20 | } 21 | 22 | public function testTiffToPdfConversion() 23 | { 24 | Storage::disk('local')->put('test.tiff', file_get_contents(__DIR__ . '/../Stubs/sample.tiff')); 25 | $this->doxswap->convert('test.tiff', 'pdf'); 26 | $this->assertTrue(Storage::disk('local')->exists('test.pdf')); 27 | } 28 | 29 | public function testTiffToPngConversion() 30 | { 31 | Storage::disk('local')->put('test.tiff', file_get_contents(__DIR__ . '/../Stubs/sample.tiff')); 32 | $this->doxswap->convert('test.tiff', 'png'); 33 | $this->assertTrue(Storage::disk('local')->exists('test.png')); 34 | } 35 | 36 | public function testTiffToJpgConversion() 37 | { 38 | Storage::disk('local')->put('test.tiff', file_get_contents(__DIR__ . '/../Stubs/sample.tiff')); 39 | $this->doxswap->convert('test.tiff', 'jpg'); 40 | $this->assertTrue(Storage::disk('local')->exists('test.jpg')); 41 | } 42 | 43 | public function testTiffToSvgConversion() 44 | { 45 | Storage::disk('local')->put('test.tiff', file_get_contents(__DIR__ . '/../Stubs/sample.tiff')); 46 | $this->doxswap->convert('test.tiff', 'svg'); 47 | $this->assertTrue(Storage::disk('local')->exists('test.svg')); 48 | } 49 | 50 | public function testTiffToBmpConversion() 51 | { 52 | Storage::disk('local')->put('test.tiff', file_get_contents(__DIR__ . '/../Stubs/sample.tiff')); 53 | $this->doxswap->convert('test.tiff', 'bmp'); 54 | $this->assertTrue(Storage::disk('local')->exists('test.bmp')); 55 | } 56 | 57 | public function testTiffToWebpConversion() 58 | { 59 | Storage::disk('local')->put('test.tiff', file_get_contents(__DIR__ . '/../Stubs/sample.tiff')); 60 | $this->doxswap->convert('test.tiff', 'webp'); 61 | $this->assertTrue(Storage::disk('local')->exists('test.webp')); 62 | } 63 | 64 | public function testTiffToGifConversion() 65 | { 66 | Storage::disk('local')->put('test.tiff', file_get_contents(__DIR__ . '/../Stubs/sample.tiff')); 67 | $this->doxswap->convert('test.tiff', 'gif'); 68 | $this->assertTrue(Storage::disk('local')->exists('test.gif')); 69 | } 70 | } -------------------------------------------------------------------------------- /tests/Integration/TxtConversionTest.php: -------------------------------------------------------------------------------- 1 | doxswap = new Doxswap(); 20 | } 21 | 22 | public function testTxtToPdfConversion() 23 | { 24 | Storage::disk('local')->put('test.txt', file_get_contents(__DIR__ . '/../Stubs/sample.txt')); 25 | $this->doxswap->convert('test.txt', 'pdf'); 26 | $this->assertTrue(Storage::disk('local')->exists('test.pdf')); 27 | } 28 | 29 | public function testTxtToDocxConversion() 30 | { 31 | Storage::disk('local')->put('test.txt', file_get_contents(__DIR__ . '/../Stubs/sample.txt')); 32 | $this->doxswap->convert('test.txt', 'docx'); 33 | $this->assertTrue(Storage::disk('local')->exists('test.docx')); 34 | } 35 | 36 | public function testTxtToOdtConversion() 37 | { 38 | Storage::disk('local')->put('test.txt', file_get_contents(__DIR__ . '/../Stubs/sample.txt')); 39 | $this->doxswap->convert('test.txt', 'odt'); 40 | $this->assertTrue(Storage::disk('local')->exists('test.odt')); 41 | } 42 | 43 | public function testTxtToHtmlConversion() 44 | { 45 | Storage::disk('local')->put('test.txt', file_get_contents(__DIR__ . '/../Stubs/sample.txt')); 46 | $this->doxswap->convert('test.txt', 'html'); 47 | $this->assertTrue(Storage::disk('local')->exists('test.html')); 48 | } 49 | 50 | public function testTxtToXmlConversion() 51 | { 52 | Storage::disk('local')->put('test.txt', file_get_contents(__DIR__ . '/../Stubs/sample.txt')); 53 | $this->doxswap->convert('test.txt', 'xml'); 54 | $this->assertTrue(Storage::disk('local')->exists('test.xml')); 55 | } 56 | } -------------------------------------------------------------------------------- /tests/Integration/WebpConversionTest.php: -------------------------------------------------------------------------------- 1 | doxswap = new Doxswap(); 20 | } 21 | 22 | public function testWebpToPdfConversion() 23 | { 24 | Storage::disk('local')->put('test.webp', file_get_contents(__DIR__ . '/../Stubs/sample.webp')); 25 | $this->doxswap->convert('test.webp', 'pdf'); 26 | $this->assertTrue(Storage::disk('local')->exists('test.pdf')); 27 | } 28 | 29 | public function testWebpToPngConversion() 30 | { 31 | Storage::disk('local')->put('test.webp', file_get_contents(__DIR__ . '/../Stubs/sample.webp')); 32 | $this->doxswap->convert('test.webp', 'png'); 33 | $this->assertTrue(Storage::disk('local')->exists('test.png')); 34 | } 35 | 36 | public function testWebpToJpgConversion() 37 | { 38 | Storage::disk('local')->put('test.webp', file_get_contents(__DIR__ . '/../Stubs/sample.webp')); 39 | $this->doxswap->convert('test.webp', 'jpg'); 40 | $this->assertTrue(Storage::disk('local')->exists('test.jpg')); 41 | } 42 | 43 | public function testWebpToTiffConversion() 44 | { 45 | Storage::disk('local')->put('test.webp', file_get_contents(__DIR__ . '/../Stubs/sample.webp')); 46 | $this->doxswap->convert('test.webp', 'tiff'); 47 | $this->assertTrue(Storage::disk('local')->exists('test.tiff')); 48 | } 49 | 50 | public function testWebpToBmpConversion() 51 | { 52 | Storage::disk('local')->put('test.webp', file_get_contents(__DIR__ . '/../Stubs/sample.webp')); 53 | $this->doxswap->convert('test.webp', 'bmp'); 54 | $this->assertTrue(Storage::disk('local')->exists('test.bmp')); 55 | } 56 | 57 | public function testWebpToGifConversion() 58 | { 59 | Storage::disk('local')->put('test.webp', file_get_contents(__DIR__ . '/../Stubs/sample.webp')); 60 | $this->doxswap->convert('test.webp', 'gif'); 61 | $this->assertTrue(Storage::disk('local')->exists('test.gif')); 62 | } 63 | 64 | public function testWebpToSvgConversion() 65 | { 66 | Storage::disk('local')->put('test.webp', file_get_contents(__DIR__ . '/../Stubs/sample.webp')); 67 | $this->doxswap->convert('test.webp', 'svg'); 68 | $this->assertTrue(Storage::disk('local')->exists('test.svg')); 69 | } 70 | } -------------------------------------------------------------------------------- /tests/Integration/XlsConversionTest.php: -------------------------------------------------------------------------------- 1 | doxswap = new Doxswap(); 20 | } 21 | 22 | public function testXlsToPdfConversion() 23 | { 24 | Storage::disk('local')->put('test.xls', file_get_contents(__DIR__ . '/../Stubs/sample.xls')); 25 | $this->doxswap->convert('test.xls', 'pdf'); 26 | $this->assertTrue(Storage::disk('local')->exists('test.pdf')); 27 | } 28 | 29 | public function testXlsToOdsConversion() 30 | { 31 | Storage::disk('local')->put('test.xls', file_get_contents(__DIR__ . '/../Stubs/sample.xls')); 32 | $this->doxswap->convert('test.xls', 'ods'); 33 | $this->assertTrue(Storage::disk('local')->exists('test.ods')); 34 | } 35 | 36 | public function testXlsToCsvConversion() 37 | { 38 | Storage::disk('local')->put('test.xls', file_get_contents(__DIR__ . '/../Stubs/sample.xls')); 39 | $this->doxswap->convert('test.xls', 'csv'); 40 | $this->assertTrue(Storage::disk('local')->exists('test.csv')); 41 | } 42 | 43 | public function testXlsToHtmlConversion() 44 | { 45 | Storage::disk('local')->put('test.xls', file_get_contents(__DIR__ . '/../Stubs/sample.xls')); 46 | $this->doxswap->convert('test.xls', 'html'); 47 | $this->assertTrue(Storage::disk('local')->exists('test.html')); 48 | } 49 | } -------------------------------------------------------------------------------- /tests/Integration/XlsxConversionTest.php: -------------------------------------------------------------------------------- 1 | doxswap = new Doxswap(); 20 | } 21 | 22 | public function testXlsxToPdfConversion() 23 | { 24 | Storage::disk('local')->put('test.xlsx', file_get_contents(__DIR__ . '/../Stubs/sample.xlsx')); 25 | $this->doxswap->convert('test.xlsx', 'pdf'); 26 | $this->assertTrue(Storage::disk('local')->exists('test.pdf')); 27 | } 28 | 29 | public function testXlsxToOdsConversion() 30 | { 31 | Storage::disk('local')->put('test.xlsx', file_get_contents(__DIR__ . '/../Stubs/sample.xlsx')); 32 | $this->doxswap->convert('test.xlsx', 'ods'); 33 | $this->assertTrue(Storage::disk('local')->exists('test.ods')); 34 | } 35 | 36 | public function testXlsxToCsvConversion() 37 | { 38 | Storage::disk('local')->put('test.xlsx', file_get_contents(__DIR__ . '/../Stubs/sample.xlsx')); 39 | $this->doxswap->convert('test.xlsx', 'csv'); 40 | $this->assertTrue(Storage::disk('local')->exists('test.csv')); 41 | } 42 | 43 | public function testXlsxToHtmlConversion() 44 | { 45 | Storage::disk('local')->put('test.xlsx', file_get_contents(__DIR__ . '/../Stubs/sample.xlsx')); 46 | $this->doxswap->convert('test.xlsx', 'html'); 47 | $this->assertTrue(Storage::disk('local')->exists('test.html')); 48 | } 49 | } -------------------------------------------------------------------------------- /tests/Integration/XmlConversionTest.php: -------------------------------------------------------------------------------- 1 | doxswap = new Doxswap(); 20 | } 21 | 22 | public function testXmlToPdfConversion() 23 | { 24 | Storage::disk('local')->put('test.xml', file_get_contents(__DIR__ . '/../Stubs/sample.xml')); 25 | $this->doxswap->convert('test.xml', 'pdf'); 26 | $this->assertTrue(Storage::disk('local')->exists('test.pdf')); 27 | } 28 | 29 | public function testXmlToOdtConversion() 30 | { 31 | Storage::disk('local')->put('test.xml', file_get_contents(__DIR__ . '/../Stubs/sample.xml')); 32 | $this->doxswap->convert('test.xml', 'odt'); 33 | $this->assertTrue(Storage::disk('local')->exists('test.odt')); 34 | } 35 | 36 | public function testXmlToTxtConversion() 37 | { 38 | Storage::disk('local')->put('test.xml', file_get_contents(__DIR__ . '/../Stubs/sample.xml')); 39 | $this->doxswap->convert('test.xml', 'txt'); 40 | $this->assertTrue(Storage::disk('local')->exists('test.txt')); 41 | } 42 | 43 | public function testXmlToHtmlConversion() 44 | { 45 | Storage::disk('local')->put('test.xml', file_get_contents(__DIR__ . '/../Stubs/sample.xml')); 46 | $this->doxswap->convert('test.xml', 'html'); 47 | $this->assertTrue(Storage::disk('local')->exists('test.html')); 48 | } 49 | } -------------------------------------------------------------------------------- /tests/Stubs/sample.bmp: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:a38c24951e6ff073b8d6bf918ec89cf2aa56a692b4a57094fda6f7d23b851873 3 | size 3275658 4 | -------------------------------------------------------------------------------- /tests/Stubs/sample.csv: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:232481a7b2e553477dbf03b54be5edc546133d6cf31e3aaadd009ef5f0b273e1 3 | size 723 4 | -------------------------------------------------------------------------------- /tests/Stubs/sample.doc: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:c560136e2a2b7036523f69efdb4e9cdf369abe167ba3a095e26d74e261774b20 3 | size 1027072 4 | -------------------------------------------------------------------------------- /tests/Stubs/sample.docx: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:27cd24f7f6e1e86449c1efc75c103acbb717733be5a36377cceb59e77be9d97c 3 | size 1026736 4 | -------------------------------------------------------------------------------- /tests/Stubs/sample.gif: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:ade473de2c1cf938635cd6654b41d6e8692eee79ac8940aaabcd9aee912eeaa5 3 | size 1731368 4 | -------------------------------------------------------------------------------- /tests/Stubs/sample.html: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:602863d283f8d71795740930959ebbe2956d2e9804d23c1f30fd6daf77314fcc 3 | size 28944 4 | -------------------------------------------------------------------------------- /tests/Stubs/sample.jpg: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:9bc52b9ea29d82d6f607b6e3685ef7f62a030480695cfe5013f36c98e49702ae 3 | size 5554547 4 | -------------------------------------------------------------------------------- /tests/Stubs/sample.odp: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:4fac9fdf52f6fc073899eea2cfd153edf8c45b9ab8163382142988e079b9029c 3 | size 971659 4 | -------------------------------------------------------------------------------- /tests/Stubs/sample.ods: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:2cdbd91d0c9edd231f22bc91e96afd4a506b58faf1584066035bf449879db448 3 | size 1058796 4 | -------------------------------------------------------------------------------- /tests/Stubs/sample.odt: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:b1cbd771d3b5a7b0e02c7ecbf7330e2ca21c00d9aac88eea878b75fd9dbca23a 3 | size 21423 4 | -------------------------------------------------------------------------------- /tests/Stubs/sample.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:4327feee5c47ba804aab98f99670e3c4421fec00fd4cdc59331d0821008fdf12 3 | size 4767276 4 | -------------------------------------------------------------------------------- /tests/Stubs/sample.ppt: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:56b2799280c94871730139bbe08ff08bc29d56fba629710ce53cf77f6002568d 3 | size 1028096 4 | -------------------------------------------------------------------------------- /tests/Stubs/sample.pptx: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:71794a67f10eb12c9d94bd6ea5884815718a764b991f55602fece913d44136b0 3 | size 45680 4 | -------------------------------------------------------------------------------- /tests/Stubs/sample.rtf: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:a5fd556610a5719f1b00f3f80e1fe279a465a7cb1a9855da25fb867509500a3d 3 | size 105344 4 | -------------------------------------------------------------------------------- /tests/Stubs/sample.svg: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:d6012d46eab66404f9c2c450942dc8874ba6fe057774a38ba19b9fa570062a2d 3 | size 1067956 4 | -------------------------------------------------------------------------------- /tests/Stubs/sample.tiff: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:9a5ca0acbf1cc92da2c8a5d984a7904f751078fa5aa85508b05d5e17a4234a98 3 | size 3275784 4 | -------------------------------------------------------------------------------- /tests/Stubs/sample.txt: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:a1c139ae07086ecbd038dc15e61553a6c8092764c17cd2d95a6e3a9df5fed23d 3 | size 607 4 | -------------------------------------------------------------------------------- /tests/Stubs/sample.webp: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:c90994e27f7e26c6b3a94e8a4ebf2ccd46b974852ef3eaf3686d2270cf340abf 3 | size 658538 4 | -------------------------------------------------------------------------------- /tests/Stubs/sample.xls: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:0090823b5cf5c83f9f24334cf0a40347844a0902968c64f819cfa7b0c0e8c484 3 | size 16384 4 | -------------------------------------------------------------------------------- /tests/Stubs/sample.xlsx: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:2561e1ac6c1e8c0d5c087b08a257f2ad416fd2e1d7229cabb702858aa25743fe 3 | size 32924 4 | -------------------------------------------------------------------------------- /tests/Stubs/sample.xml: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:add65704e8253512a35168abdad541aadd4dc4901e0ba1e97d52729356c8dd4b 3 | size 4038 4 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | 17 | */ 18 | protected function getPackageProviders($app): array 19 | { 20 | return [ 21 | 'Blaspsoft\Doxswap\DoxswapServiceProvider', 22 | ]; 23 | } 24 | 25 | /** 26 | * Define environment setup. 27 | * 28 | * @param \Illuminate\Foundation\Application $app 29 | * @return void 30 | */ 31 | protected function getEnvironmentSetUp($app): void 32 | { 33 | $app['config']->set('doxswap.input_disk', 'local'); 34 | $app['config']->set('doxswap.output_disk', 'local'); 35 | $app['config']->set('doxswap.perform_cleanup', false); 36 | //$app['config']->set('doxswap.drivers.libreoffice_path', env('LIBREOFFICE_PATH', '/Applications/LibreOffice.app/Contents/MacOS/soffice')); 37 | $app['config']->set('doxswap.drivers.libreoffice_path', env('LIBREOFFICE_PATH', '/usr/bin/soffice')); 38 | } 39 | } -------------------------------------------------------------------------------- /tests/Unit/ConversionCleanupTest.php: -------------------------------------------------------------------------------- 1 | andReturnSelf(); 18 | } 19 | 20 | protected function getEnvironmentSetUp($app) 21 | { 22 | // Set up configuration values for testing 23 | $app['config']->set('doxswap.input_disk', 'local'); 24 | $app['config']->set('doxswap.output_disk', 'local'); 25 | } 26 | 27 | public function testPerformCleanupTrue() 28 | { 29 | $this->app['config']->set('doxswap.perform_cleanup', true); 30 | 31 | $conversionCleanup = new ConversionCleanup(); 32 | 33 | Storage::shouldReceive('delete') 34 | ->once() 35 | ->with('inputFile.txt'); 36 | 37 | $conversionCleanup->cleanup('inputFile.txt', 'outputFile.txt'); 38 | } 39 | 40 | public function testPerformCleanupFalse() 41 | { 42 | $this->app['config']->set('doxswap.perform_cleanup', false); 43 | 44 | $conversionCleanup = new ConversionCleanup(); 45 | 46 | Storage::shouldReceive('delete') 47 | ->never(); 48 | 49 | $conversionCleanup->cleanup('inputFile.txt', 'outputFile.txt'); 50 | } 51 | } -------------------------------------------------------------------------------- /tests/Unit/FilenameTest.php: -------------------------------------------------------------------------------- 1 | set('doxswap.filename.strategy', 'original'); 19 | config()->set('doxswap.filename.options', []); 20 | config()->set('doxswap.output_disk', 'local'); 21 | 22 | // Mock the storage disk 23 | Storage::fake('local'); 24 | } 25 | 26 | public function testGenerateFileNameOriginalStrategy() 27 | { 28 | $filePath = 'path/to/original/file.txt'; 29 | 30 | config()->set('doxswap.filename.strategy', 'original'); 31 | 32 | $reflection = new ReflectionClass(Filename::class); 33 | $method = $reflection->getMethod('generateFileName'); 34 | $method->setAccessible(true); 35 | 36 | $filenameInstance = new Filename(); 37 | $generatedFileName = $method->invoke($filenameInstance, $filePath); 38 | 39 | $this->assertEquals(basename($filePath), $generatedFileName); 40 | } 41 | 42 | public function testGenerateFileNameMethod() 43 | { 44 | $filePath = 'path/to/original/file.txt'; 45 | 46 | // Use reflection to access the protected method 47 | $reflection = new ReflectionClass(Filename::class); 48 | $method = $reflection->getMethod('generateFileName'); 49 | $method->setAccessible(true); 50 | 51 | $filenameInstance = new Filename(); 52 | $generatedFileName = $method->invoke($filenameInstance, $filePath); 53 | 54 | // Assert that the generated file name is as expected 55 | $this->assertEquals(basename($filePath), $generatedFileName); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /tests/Unit/FormatRegistryTest.php: -------------------------------------------------------------------------------- 1 | formatRegistry = new FormatRegistry(); 29 | } 30 | 31 | public function testRegisterFormat() 32 | { 33 | $mockFormat = $this->createMock(ConvertibleFormat::class); 34 | $mockFormat->method('getName')->willReturn('mock'); 35 | 36 | $this->formatRegistry->register($mockFormat); 37 | 38 | $this->assertSame($mockFormat, $this->formatRegistry->getFormat('mock')); 39 | } 40 | 41 | public function testGetFormat() 42 | { 43 | $format = $this->formatRegistry->getFormat('doc'); 44 | $this->assertInstanceOf(DocFormat::class, $format); 45 | } 46 | 47 | public function testIsSupportedConversion() 48 | { 49 | $docFormat = new DocFormat(); 50 | $this->assertTrue($this->formatRegistry->isSupportedConversion($docFormat, 'pdf')); 51 | } 52 | 53 | public function testIsSupportedMimeType() 54 | { 55 | $docFormat = new DocFormat(); 56 | $this->assertTrue($this->formatRegistry->isSupportedMimeType($docFormat, 'application/msword')); 57 | } 58 | 59 | public function testConvertThrowsExceptionForNonExistentFile() 60 | { 61 | $this->expectException(\Blaspsoft\Doxswap\Exceptions\InputFileNotFoundException::class); 62 | $this->expectExceptionMessage('Input file not found: nonexistent.doc'); 63 | 64 | $this->formatRegistry->convert('nonexistent.doc', 'pdf'); 65 | } 66 | 67 | public function testConvertThrowsExceptionForUnsupportedConversion() 68 | { 69 | Storage::disk('local')->put('test.doc', 'dummy content'); 70 | 71 | $this->expectException(\Blaspsoft\Doxswap\Exceptions\UnsupportedConversionException::class); 72 | $this->expectExceptionMessage("Conversion from 'doc' to 'unknown' is not supported"); 73 | 74 | $this->formatRegistry->convert('test.doc', 'unknown'); 75 | } 76 | 77 | public function testConvertThrowsExceptionForUnsupportedMimeType() 78 | { 79 | Storage::disk('local')->put('test.doc', 'dummy content'); 80 | 81 | $this->expectException(\Blaspsoft\Doxswap\Exceptions\UnsupportedMimeTypeException::class); 82 | $this->expectExceptionMessage("Unsupported MIME type for extension: doc"); 83 | 84 | File::shouldReceive('mimeType')->andReturn('invalid/mime-type'); 85 | $this->formatRegistry->convert('test.doc', 'pdf'); 86 | } 87 | } --------------------------------------------------------------------------------