From 7dfffb77a0c3a2af4a428b96f762856176fd85ea Mon Sep 17 00:00:00 2001 From: geekcom Date: Wed, 18 Mar 2020 10:51:08 -0300 Subject: [PATCH] update docs, minor corrections --- README.md | 6 +++--- composer.json | 8 ++++---- docs/pt_BR/LEIA-ME_pt_BR.md | 6 +++--- src/PHPJasper.php | 16 ++++++++++++++++ tests/PHPJasperTest.php | 1 + 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0feb315..122e54a 100755 --- a/README.md +++ b/README.md @@ -94,10 +94,10 @@ With Docker CE and docker-compose installed just run: To execute tests: -* `docker exec -it phpjasper ./vendor/bin/phpunit` or -* `docker exec -it phpjasper ./vendor/bin/phpunit --testdox` +* `docker exec -it phpjasper sudo composer test` or +* `docker exec -it phpjasper sudo composer testdox` -To see coverage of tests execute the file: `tests/logs/coverage/index.html` +To see coverage manually of tests, execute the file: `tests/log/report/index.html` _Help us writing new tests, make a fork_ :) diff --git a/composer.json b/composer.json index 170b367..47ab337 100755 --- a/composer.json +++ b/composer.json @@ -36,14 +36,14 @@ }, "scripts": { "phpcs": "phpcs --standard=PSR12 -n src", + "phpstan": "phpstan analyse src --level 0", "phpcbf": "phpcbf --standard=PSR12 -n src", "unit": "phpunit --coverage-clover ./tests/log/clover.xml --colors=always", - "unit-html": "php -d phar.readonly=0 vendor/bin/phpunit --coverage-html ./tests/log/ --colors=always", - "phpstan": "phpstan analyse src --level 0", + "testdox": "phpunit --testdox", "test": [ "@phpcs", - "@unit", - "@phpstan" + "@phpstan", + "@unit" ] } } diff --git a/docs/pt_BR/LEIA-ME_pt_BR.md b/docs/pt_BR/LEIA-ME_pt_BR.md index ba4fbc2..008ba36 100644 --- a/docs/pt_BR/LEIA-ME_pt_BR.md +++ b/docs/pt_BR/LEIA-ME_pt_BR.md @@ -91,10 +91,10 @@ Com o Docker CE e o docker-compose instalados basta executar os comandos: Para rodar os testes dentro do container execute: -* `docker exec -it phpjasper ./vendor/bin/phpunit` ou -* `docker exec -it phpjasper ./vendor/bin/phpunit --testdox` +* `docker exec -it phpjasper sudo composer test` ou +* `docker exec -it phpjasper sudo composer testdox` -Para ver o coverage basta executar o arquivo: `tests/logs/coverage/index.html` +Para ver o coverage basta executar o arquivo: `tests/log/report/index.html` _Ajude-nos escrevendo novos testes, faça um fork_ :) diff --git a/src/PHPJasper.php b/src/PHPJasper.php index 5ce0b6c..8e910f5 100644 --- a/src/PHPJasper.php +++ b/src/PHPJasper.php @@ -15,6 +15,18 @@ use PHPJasper\Exception; +use function strtoupper; +use function substr; +use function is_file; +use function realpath; +use function join; +use function array_merge; +use function is_array; +use function in_array; +use function chdir; +use function exec; +use function is_dir; + class PHPJasper { @@ -127,6 +139,7 @@ public function process(string $input, string $output, array $options = []) $this->command .= ' -o ' . "\"$output\""; $this->command .= ' -f ' . join(' ', $options['format']); + if ($options['params']) { $this->command .= ' -P '; foreach ($options['params'] as $key => $value) { @@ -189,6 +202,7 @@ protected function validateFormat($format) if (!is_array($format)) { $format = [$format]; } + foreach ($format as $value) { if (!in_array($value, $this->formats)) { throw new Exception\InvalidFormat(); @@ -231,6 +245,7 @@ public function execute($user = false) chdir($this->pathExecutable); exec($this->command, $output, $returnVar); + if ($returnVar !== 0) { throw new Exception\ErrorCommandExecutable(); } @@ -275,6 +290,7 @@ protected function validateExecute() if (!$this->command) { throw new Exception\InvalidCommandExecutable(); } + if (!is_dir($this->pathExecutable)) { throw new Exception\InvalidResourceDirectory(); } diff --git a/tests/PHPJasperTest.php b/tests/PHPJasperTest.php index 805daf7..84c0b5d 100644 --- a/tests/PHPJasperTest.php +++ b/tests/PHPJasperTest.php @@ -20,6 +20,7 @@ /** * @author Rafael Queiroz + * @author Daniel Rodrigues */ final class PHPJasperTest extends TestCase {