Skip to content

Commit

Permalink
Merge pull request #10 from naillizard/laravel-6-support
Browse files Browse the repository at this point in the history
Laravel 6 support
  • Loading branch information
mlanin authored Feb 10, 2020
2 parents df78288 + 04ac654 commit 3246041
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 30 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/build/
/vendor/
composer.lock
.php_cs.cache
.php_cs.cache
.phpunit.result.cache
9 changes: 2 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ dist: trusty
language: php

php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3

sudo: false

Expand All @@ -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
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Package Test Suite">
Expand Down
3 changes: 2 additions & 1 deletion src/ApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public function authorize()
*/
protected function failedValidation(Validator $validator)
{
throw new ValidationFailedApiException($this->formatErrors($validator));
throw new ValidationFailedApiException($validator->getMessageBag()->toArray());
}
}
4 changes: 3 additions & 1 deletion src/Support/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Lanin\Laravel\ApiExceptions\Support;

use Illuminate\Support\Str;

class Validator extends \Illuminate\Validation\Validator
{
/**
Expand All @@ -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,
];

Expand Down
4 changes: 2 additions & 2 deletions tests/ApiExceptionsServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 15 additions & 11 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@

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();
}

/**
* Get package providers.
*
* @param \Illuminate\Foundation\Application $app
* @param Application $app
*
* @return array
*/
Expand All @@ -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)
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand Down

0 comments on commit 3246041

Please sign in to comment.