diff --git a/.travis.yml b/.travis.yml
index 8e796be..d9d45a7 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,11 +1,9 @@
language: php
-install: composer install -o
+install:
+ - wget -O phpunit https://phar.phpunit.de/phpunit-8.phar
+ - chmod +x ./phpunit
+ - composer install -o
php:
- - 5.4
- - 5.5
- - 5.6
- - 7.0
- - hhvm
- - nightly
-after_success:
- - CODECLIMATE_REPO_TOKEN=f9c21f5f87187047d967a0f50281bd5b663820942a7b3e914c9d0b19c3d819f3 ./vendor/bin/test-reporter # CodeClimate
+ - 7.2
+ - 7.3
+ - 7.4
diff --git a/composer.json b/composer.json
index 28a7350..9bb01da 100644
--- a/composer.json
+++ b/composer.json
@@ -1,5 +1,6 @@
{
"name": "evandarwin/laravel-jsend",
+ "version": "2.0.0",
"description": "Laravel JSend Response Helper",
"keywords": [
"laravel",
@@ -15,13 +16,13 @@
}
],
"require": {
- "php": ">=5.4.0",
- "evandarwin/jsend": "1.2.*",
- "illuminate/support": "~5.0"
+ "php": ">=7.2.0",
+ "evandarwin/jsend": "~2.0.0",
+ "illuminate/support": "~6.0",
+ "ext-json": "*"
},
"require-dev": {
- "orchestra/testbench": "~3.0",
- "codeclimate/php-test-reporter": "dev-master"
+ "orchestra/testbench": "~4.0"
},
"autoload": {
"psr-4": {
diff --git a/phpunit.xml b/phpunit.xml
index 3976c95..3b620fe 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -6,15 +6,12 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
- mapTestClassNameToCoveredClassName="false"
- printerClass="PHPUnit_TextUI_ResultPrinter"
bootstrap="tests/bootstrap.php"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
- testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader"
verbose="false">
@@ -24,9 +21,6 @@
-
- tests/bootstrap.php
-
src/
diff --git a/src/EvanDarwin/JSend/Laravel/Builder/JSendLaravelBuilder.php b/src/EvanDarwin/JSend/Laravel/Builder/JSendLaravelBuilder.php
index 1924d8e..df0e0b5 100644
--- a/src/EvanDarwin/JSend/Laravel/Builder/JSendLaravelBuilder.php
+++ b/src/EvanDarwin/JSend/Laravel/Builder/JSendLaravelBuilder.php
@@ -4,11 +4,9 @@
use EvanDarwin\JSend\JSendBuilder;
-class JSendLaravelBuilder extends JSendBuilder
-{
- public function get($statusCode = 200)
- {
- return response(json_encode(parent::get()->getArray()), $statusCode)
+class JSendLaravelBuilder extends JSendBuilder {
+ public function get(int $statusCode = 200) {
+ return response(json_encode(parent::get()->getArray()), $statusCode)
->header('Content-Type', 'application/json');
- }
+ }
}
diff --git a/src/EvanDarwin/JSend/Laravel/ServiceProvider.php b/src/EvanDarwin/JSend/Laravel/ServiceProvider.php
index bcc72f5..7193283 100644
--- a/src/EvanDarwin/JSend/Laravel/ServiceProvider.php
+++ b/src/EvanDarwin/JSend/Laravel/ServiceProvider.php
@@ -4,33 +4,29 @@
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
-class ServiceProvider extends LaravelServiceProvider
-{
- /**
- * Register the service provider.
- *
- * @return void
- */
- public function register()
- {
- $this->registerHelpers();
- }
-
- /**
- * Registers custom helper functions
- */
- private function registerHelpers()
- {
- if (!function_exists('jsend')) {
- require_once 'helpers.php';
+class ServiceProvider extends LaravelServiceProvider {
+ /**
+ * Register the service provider.
+ *
+ * @return void
+ */
+ public function register(): void {
+ $this->registerHelpers();
+ }
+
+ /**
+ * Registers custom helper functions
+ */
+ private function registerHelpers(): void {
+ if (!function_exists('jsend')) {
+ require_once 'helpers.php';
+ }
+ }
+
+ public function boot(): void {
+ // Publish our configuration files
+ $this->publishes([
+ __DIR__ . '/resources/configs/jsend.php' => config_path('jsend.php')
+ ], 'config');
}
- }
-
- public function boot()
- {
- // Publish our configuration files
- $this->publishes([
- __DIR__ . '/resources/configs/jsend.php' => config_path('jsend.php')
- ], 'config');
- }
}
\ No newline at end of file
diff --git a/src/EvanDarwin/JSend/Laravel/helpers.php b/src/EvanDarwin/JSend/Laravel/helpers.php
index 2655a4b..e84f686 100644
--- a/src/EvanDarwin/JSend/Laravel/helpers.php
+++ b/src/EvanDarwin/JSend/Laravel/helpers.php
@@ -1,9 +1,11 @@
'\EvanDarwin\JSend\Laravel\Builder\JSendLaravelBuilder',
+ 'builder' => JSendLaravelBuilder::class,
);
\ No newline at end of file
diff --git a/tests/LaravelJSend_TestCase.php b/tests/LaravelJSend_TestCase.php
index 822e900..b0db357 100644
--- a/tests/LaravelJSend_TestCase.php
+++ b/tests/LaravelJSend_TestCase.php
@@ -1,12 +1,13 @@
set('jsend.builder', '\EvanDarwin\JSend\Laravel\Builder\JSendLaravelBuilder');
+use EvanDarwin\JSend\Laravel\Builder\JSendLaravelBuilder;
+use EvanDarwin\JSend\Laravel\ServiceProvider;
+use Orchestra\Testbench\TestCase;
- return ['EvanDarwin\JSend\Laravel\ServiceProvider'];
- }
+abstract class LaravelJSend_TestCase extends TestCase {
+ protected function getPackageProviders($app): array {
+ // Set the default builder
+ $app['config']->set('jsend.builder', JSendLaravelBuilder::class);
+ return [ServiceProvider::class];
+ }
}
\ No newline at end of file
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 4fd4233..3b21331 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -2,7 +2,9 @@
$loaderPath = dirname(__DIR__) . '/vendor/autoload.php';
-if (!file_exists($loaderPath))
- die("Please run 'composer install' before running tests" . PHP_EOL);
+if (!file_exists($loaderPath)) {
+ die("Please run 'composer install' before running tests" . PHP_EOL);
+}
+/** @noinspection PhpIncludeInspection */
require $loaderPath;
\ No newline at end of file
diff --git a/tests/cases/JSendBuilderTest.php b/tests/cases/JSendBuilderTest.php
index dfc478e..7a67e66 100644
--- a/tests/cases/JSendBuilderTest.php
+++ b/tests/cases/JSendBuilderTest.php
@@ -1,65 +1,59 @@
get();
-
- $this->assertJson(json_encode(array(
- 'status' => 'success',
- 'data' => array()
- )), $response);
- }
-
- public function testRendersCorrectly()
- {
- \Route::get('/jsend', function () {
- return jsend()->failed()->code(404)->get();
- });
-
- $response = $this->call('get', '/jsend');
-
- $this->assertJson(json_encode(array(
- 'status' => 'failed',
- 'code' => 404,
- 'data' => array()
- )), $response);
- }
-
- public function testRenderCompatibility()
- {
- \Route::get('/jsend', function () {
- return jsend()->failed()->code(404)->get();
- });
-
- $response = $this->call('get', '/jsend');
-
- $this->assertJson(json_encode(array(
- 'status' => 'failed',
- 'code' => 404,
- 'data' => array()
- )), $response);
- }
-
- public function testHttpStatus()
- {
- \Route::get('/jsend_http', function() {
- return jsend()->failed()->code(403)->get(403);
- });
-
- $response = $this->call('get', '/jsend_http');
-
- $this->assertResponseStatus(403);
- }
-
- /**
- * @expectedException InvalidArgumentException
- */
- public function testInvalidBuilderException()
- {
- $this->app['config']->set('jsend.builder', '');
-
- jsend()->get();
- }
+use Illuminate\Support\Facades\Route;
+
+class JSendBuilderTest extends LaravelJSend_TestCase {
+ public function testDefaultValues(): void {
+ $response = jsend()->get();
+
+ $this->assertJson(json_encode(array(
+ 'status' => 'success',
+ 'data' => array()
+ )), $response);
+ }
+
+ public function testRendersCorrectly(): void {
+ Route::get('/jsend', static function () {
+ return jsend()->failed()->code(404)->get();
+ });
+
+ $response = $this->call('get', '/jsend');
+
+ $this->assertEquals(json_encode(array(
+ 'status' => 'fail',
+ 'data' => array(),
+ 'errors' => null,
+ 'code' => 404,
+ )), $response->getContent());
+ }
+
+ public function testRenderCompatibility(): void {
+ Route::get('/jsend', static function () {
+ return jsend()->failed()->code(404)->get();
+ });
+
+ $response = $this->call('get', '/jsend');
+
+ $this->assertEquals(json_encode(array(
+ 'status' => 'fail',
+ 'data' => array(),
+ 'errors' => null,
+ 'code' => 404,
+ )), $response->getContent());
+ }
+
+ public function testHttpStatus(): void {
+ Route::get('/jsend_http', static function () {
+ return jsend()->failed()->code(403)->get(403);
+ });
+
+ $res = $this->call('get', '/jsend_http');
+ $this->assertEquals(403, $res->status());
+ }
+
+ public function testInvalidBuilderException(): void {
+ $this->expectException(InvalidArgumentException::class);
+ $this->app['config']->set('jsend.builder', '');
+ jsend()->get();
+ }
}