From 791f57e00dca360b82502e7d973ff6be744c7474 Mon Sep 17 00:00:00 2001 From: naillizard Date: Tue, 19 Nov 2019 11:58:53 +1300 Subject: [PATCH 1/3] Ignoring .phpunit.result.cache file --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f83f2db..6a08720 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ /build/ /vendor/ composer.lock -.php_cs.cache \ No newline at end of file +.php_cs.cache +.phpunit.result.cache \ No newline at end of file From e098d338ad6abcff7f0e20cd4c031eb649260546 Mon Sep 17 00:00:00 2001 From: naillizard Date: Tue, 19 Nov 2019 12:03:43 +1300 Subject: [PATCH 2/3] Added support for laravel 6. --- composer.json | 10 ++++----- phpunit.xml | 1 - src/ApiException.php | 3 ++- src/Support/Request.php | 2 +- src/Support/Validator.php | 4 +++- tests/ApiExceptionsServiceProviderTest.php | 4 ++-- tests/TestCase.php | 26 +++++++++++++--------- 7 files changed, 28 insertions(+), 22 deletions(-) diff --git a/composer.json b/composer.json index 14db559..2f196a0 100644 --- a/composer.json +++ b/composer.json @@ -11,13 +11,13 @@ } ], "require": { - "php": ">=5.6.0", - "illuminate/support": "^5.3" + "php": "^7.2", + "illuminate/support": "^6.0" }, "require-dev": { - "orchestra/testbench": "~3.4", - "phpunit/phpunit": "~5.7", - "mockery/mockery": "0.9.*" + "orchestra/testbench": "^4.0", + "phpunit/phpunit": "^8.0", + "mockery/mockery": "^1.0" }, "autoload": { "psr-4": { diff --git a/phpunit.xml b/phpunit.xml index 86508cd..f77dd9b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,7 +8,6 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" > diff --git a/src/ApiException.php b/src/ApiException.php index 7142627..ac5d2a3 100644 --- a/src/ApiException.php +++ b/src/ApiException.php @@ -4,6 +4,7 @@ use Illuminate\Contracts\Support\Arrayable; use Illuminate\Contracts\Support\Jsonable; +use Illuminate\Support\Str; use Lanin\Laravel\ApiExceptions\Contracts\ShowsPrevious; use Lanin\Laravel\ApiExceptions\Contracts\ShowsTrace; use Symfony\Component\Debug\Exception\FlattenException; @@ -71,7 +72,7 @@ public function toArray() } $return = []; - $return['id'] = $e instanceof IdException ? $e->getId() : snake_case(class_basename($e)); + $return['id'] = $e instanceof IdException ? $e->getId() : Str::snake(class_basename($e)); $return['message'] = $e->getMessage(); if ($e instanceof ApiException) { diff --git a/src/Support/Request.php b/src/Support/Request.php index 4d0de47..314a9f8 100644 --- a/src/Support/Request.php +++ b/src/Support/Request.php @@ -38,6 +38,6 @@ public function authorize() */ protected function failedValidation(Validator $validator) { - throw new ValidationFailedApiException($this->formatErrors($validator)); + throw new ValidationFailedApiException($validator->getMessageBag()->toArray()); } } diff --git a/src/Support/Validator.php b/src/Support/Validator.php index 92d1239..0849ed8 100644 --- a/src/Support/Validator.php +++ b/src/Support/Validator.php @@ -2,6 +2,8 @@ namespace Lanin\Laravel\ApiExceptions\Support; +use Illuminate\Support\Str; + class Validator extends \Illuminate\Validation\Validator { /** @@ -18,7 +20,7 @@ protected function addError($attribute, $rule, $parameters) $message = $this->doReplacements($message, $attribute, $rule, $parameters); $return = [ - 'rule' => snake_case($rule), + 'rule' => Str::snake($rule), 'message' => $message, ]; diff --git a/tests/ApiExceptionsServiceProviderTest.php b/tests/ApiExceptionsServiceProviderTest.php index f42145b..da0658b 100644 --- a/tests/ApiExceptionsServiceProviderTest.php +++ b/tests/ApiExceptionsServiceProviderTest.php @@ -9,13 +9,13 @@ class ApiExceptionsServiceProviderTest extends TestCase /** @var ApiExceptionsServiceProvider */ private $provider; - public function setUp() + public function setUp(): void { parent::setUp(); $this->provider = $this->app->getProvider(ApiExceptionsServiceProvider::class); } - public function tearDown() + public function tearDown(): void { parent::tearDown(); unset($this->provider); diff --git a/tests/TestCase.php b/tests/TestCase.php index 83c1066..574f5e6 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,18 +2,20 @@ namespace Lanin\Laravel\ApiExceptions\Tests; -use Illuminate\Support\Str; +use Illuminate\Foundation\Application; use Lanin\Laravel\ApiExceptions\ApiExceptionsServiceProvider; use Orchestra\Testbench\TestCase as BaseTestCase; -use PHPUnit_Framework_ExpectationFailedException as PHPUnitException; use ReflectionClass; +use ReflectionException; +use ReflectionMethod; +use ReflectionProperty; abstract class TestCase extends BaseTestCase { /** * Setup the test environment. */ - public function setUp() + public function setUp(): void { parent::setUp(); } @@ -21,7 +23,7 @@ public function setUp() /** * Get package providers. * - * @param \Illuminate\Foundation\Application $app + * @param Application $app * * @return array */ @@ -35,7 +37,7 @@ protected function getPackageProviders($app) /** * Define environment setup. * - * @param \Illuminate\Foundation\Application $app + * @param Application $app * @return void */ protected function getEnvironmentSetUp($app) @@ -49,9 +51,10 @@ protected function getEnvironmentSetUp($app) /** * Make protected/private class property accessible. * - * @param string|object $class - * @param string $name - * @return \ReflectionProperty + * @param string|object $class + * @param string $name + * @return ReflectionProperty + * @throws ReflectionException */ protected function getPublicProperty($class, $name) { @@ -69,9 +72,10 @@ protected function getPublicProperty($class, $name) /** * Make protected/private class method accessible. * - * @param string $name - * @param string|object $class - * @return \ReflectionMethod + * @param string $name + * @param string|object $class + * @return ReflectionMethod + * @throws ReflectionException */ protected function getPublicMethod($name, $class) { From 04ac6545c085f3572e559ffc5a72c690ded25d01 Mon Sep 17 00:00:00 2001 From: naillizard Date: Tue, 19 Nov 2019 12:58:33 +1300 Subject: [PATCH 3/3] Changed travis file to test php 7.2 and 7.3 --- .travis.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index dfa6d0d..db7a928 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,9 +3,8 @@ dist: trusty language: php php: - - 5.6 - - 7.0 - - 7.1 + - 7.2 + - 7.3 sudo: false @@ -21,7 +20,3 @@ before_script: script: - vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover - -after_script: - - if [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi - - if [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml; fi