diff --git a/CmdExecuteService.php b/CmdExecuteService.php index 1aca7da..00507e6 100644 --- a/CmdExecuteService.php +++ b/CmdExecuteService.php @@ -74,7 +74,10 @@ public function execute($cmd, $data): \Closure $pipes = []; // Start process, telling it to use STDIN for input and STDOUT for output. - $cmd = escapeshellcmd($cmd); + $cmd = match (gettype($cmd)) { + 'array' => $cmd, + default => escapeshellcmd($cmd), + }; $process = proc_open($cmd, $descr, $pipes); // Get the data into pipe only if data is resource diff --git a/README.md b/README.md index dd597f7..48d5877 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![Crayfish](https://user-images.githubusercontent.com/2371345/48163075-11c6cf80-e2b5-11e8-8b5b-991b366014a5.png) # Crayfish Commons -[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.4-8892BF.svg?style=flat-square)](https://php.net/) +[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%208.0-8892BF.svg?style=flat-square)](https://php.net/) [![Build Status](https://github.com/islandora/crayfish-commons/actions/workflows/build-2.x.yml/badge.svg)](https://github.com/Islandora/crayfish-commons/actions) [![Contribution Guidelines](http://img.shields.io/badge/CONTRIBUTING-Guidelines-blue.svg)](./CONTRIBUTING.md) [![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](./LICENSE) @@ -18,7 +18,7 @@ Shared Classes include: ## Requirements -* PHP 7.4+ +* PHP 8.0+ * [Composer](https://getcomposer.org/) ## Installation diff --git a/Tests/CmdExecuteServiceTest.php b/Tests/CmdExecuteServiceTest.php index 6120657..ccae093 100644 --- a/Tests/CmdExecuteServiceTest.php +++ b/Tests/CmdExecuteServiceTest.php @@ -7,7 +7,25 @@ class CmdExecuteServiceTest extends AbstractCrayfishCommonsTestCase { - public function testExecuteWithResource() + public function dataProviderWithResource() + { + return [ + 'test as string' => [ + 'sort -', + ], + 'test as array' => [ + [ + 'sort', + '-', + ], + ] + ]; + } + + /** + * @dataProvider dataProviderWithResource + */ + public function testExecuteWithResource(string|array $command) { $service = new CmdExecuteService($this->logger); @@ -16,8 +34,6 @@ public function testExecuteWithResource() fwrite($data, $string); rewind($data); - $command = 'sort -'; - $callback = $service->execute($command, $data); $this->assertTrue(is_callable($callback), "execute() must return a callable."); @@ -36,11 +52,28 @@ public function testExecuteWithResource() $callback(); } - public function testExecuteWithoutResource() + public function dataProviderWithoutResource() + { + return [ + 'test as string' => [ + 'echo "derp"', + ], + 'test as array' => [ + [ + 'echo', + 'derp', + ], + ] + ]; + } + + /** + * @dataProvider dataProviderWithoutResource + */ + public function testExecuteWithoutResource(string|array $command) { $service = new CmdExecuteService($this->logger); - $command = 'echo "derp"'; $callback = $service->execute($command, ""); $this->assertTrue(is_callable($callback), "execute() must return a callable.");