Skip to content

Commit

Permalink
Updating the package
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Feb 6, 2019
1 parent e410d70 commit 1a176c3
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ checks:
tools:
external_code_coverage:
timeout: 600
runs: 2
runs: 4
php_code_sniffer:
enabled: true
config:
Expand Down
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ sudo: false
php:
- 7.0
- 7.1
- 7.2
- 7.3
- nightly

matrix:
allow_failures:
- php: nightly

env:
- TESTBENCH_VERSION=3.5.*

before_script:
- travis_retry composer self-update
- travis_retry composer require --prefer-source --no-interaction --dev "orchestra/testbench-browser-kit:${TESTBENCH_VERSION}"
- travis_retry composer install --prefer-source --no-interaction

script:
- composer validate
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2017 ARCANEDEV - Laravel API Helper
Copyright (c) 2017-2019 ARCANEDEV - Laravel API Helper

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Laravel API Helper is a package that allows you to add features to build api fas
* Easy setup & configuration.
* Well documented & IDE Friendly.
* Well tested with maximum code quality.
* Laravel `5.1 | 5.2 | 5.3 | 5.4 | 5.5` are supported.
* Laravel `5.1` to `5.5` are supported.
* Made with :heart: & :coffee:.

## Contribution
Expand Down
16 changes: 5 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
"license": "MIT",
"require": {
"php": ">=7.0",
"arcanedev/support": "~4.0"
"ext-json": "*",
"arcanedev/support": "~4.2.0"
},
"require-dev": {
"phpunit/phpunit": "~6.0",
"phpunit/phpcov": "~4.0"
"phpunit/phpunit": "~6.0",
"phpunit/phpcov": "~4.0",
"orchestra/testbench": "~3.5.0"
},
"autoload": {
"psr-4": {
Expand All @@ -31,13 +33,5 @@
"psr-4": {
"Arcanedev\\LaravelApiHelper\\Tests\\": "tests/"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"scripts": {
"testbench": "composer require --dev \"orchestra/testbench-browser-kit=~3.0\""
}
}
2 changes: 1 addition & 1 deletion src/Http/ApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public function response($request = null)
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\Response|mixed
*/
public function toResponse($request)
{
Expand Down
4 changes: 2 additions & 2 deletions tests/ApiHelperServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function it_can_be_instantiated()
];

foreach ($expectations as $expected) {
$this->assertInstanceOf($expected, $this->provider);
static::assertInstanceOf($expected, $this->provider);
}
}

Expand All @@ -62,6 +62,6 @@ public function it_can_provides()
\Arcanedev\LaravelApiHelper\Contracts\Http\JsonResponse::class
];

$this->assertSame($expected, $this->provider->provides());
static::assertSame($expected, $this->provider->provides());
}
}
7 changes: 3 additions & 4 deletions tests/Http/ApiResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ public function setUp()
/** @test */
public function it_can_be_instantiated()
{
$user = new User([
$user = User::query()->create([
'first_name' => 'John',
'last_name' => 'DOE',
'email' => '[email protected]',
]);
$user->save();

$this->assertJson($content = UserResource::make($user)->response()->content());
$this->assertSame([
static::assertJson($content = UserResource::make($user)->response()->content());
static::assertSame([
'data' => [
'hashed_id' => 'hashed_id_here',
'full_name' => 'John DOE',
Expand Down
19 changes: 8 additions & 11 deletions tests/Http/FormRequestTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php namespace Arcanedev\LaravelApiHelper\Tests\Http;

use Arcanedev\LaravelApiHelper\Http\FormRequest;
use Arcanedev\LaravelApiHelper\Tests\TestCase;

/**
Expand All @@ -19,14 +18,13 @@ class FormRequestTest extends TestCase
/** @test */
public function it_can_fail_validation_with_form_request()
{
$response = $this->json('POST', 'form-request')->response;
$response = $this->json('POST', 'form-request');

$this->assertFalse($response->isOk());
$this->assertSame(422, $response->status());
$response->assertStatus(422);

$this->assertJson($content = $response->content());
static::assertJson($content = $response->content());

$this->assertSame([
static::assertSame([
'message' => 'The given data was invalid.',
'errors' => [
'name' => [
Expand All @@ -45,16 +43,15 @@ public function it_can_validate_form_request()
$response = $this->json('POST', 'form-request', [
'name' => 'ARCANEDEV',
'email' => '[email protected]',
])->response;
]);

$this->assertTrue($response->isOk());
$this->assertSame(200, $response->status());
$response->assertSuccessful();

$this->assertJson($response->content());
$this->assertJson($content = $response->content());
$this->assertSame(json_encode([
'status' => 200,
'code' => 'success',
'message' => 'Everything is good !',
]), $response->content());
]), $content);
}
}
28 changes: 14 additions & 14 deletions tests/Http/JsonResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ public function it_can_respond_with_success_response()
{
$response = $this->jsonResponse->success(['foo' => 'bar']);

$this->assertJsonResponse($response);
static::assertJsonResponse($response);

$expected = [
'status' => 200,
'code' => 'success',
'foo' => 'bar',
];

$this->assertSame($expected, $response->getData(true));
static::assertSame($expected, $response->getData(true));
}

/** @test */
Expand All @@ -71,18 +71,18 @@ public function it_can_respond_with_error_response()
'message' => $message,
];

$this->assertJsonResponse($response);
$this->assertSame($expected, $response->getData(true));
static::assertJsonResponse($response);
static::assertSame($expected, $response->getData(true));
}

/** @test */
public function it_can_respond_with_success_response_via_trait()
{
/** @var \Illuminate\Http\JsonResponse $response */
$response = $this->json('GET', '/valid-slug')->response;
$response = $this->json('GET', '/valid-slug')->baseResponse;

$this->assertJsonResponse($response);
$this->assertTrue($response->isOk());
static::assertJsonResponse($response);
static::assertTrue($response->isOk());

$expected = [
'status' => 200,
Expand All @@ -91,25 +91,25 @@ public function it_can_respond_with_success_response_via_trait()
'content' => 'Post content',
];

$this->assertSame($expected, $response->getData(true));
static::assertSame($expected, $response->getData(true));
}

/** @test */
public function it_can_respond_with_error_response_via_trait()
{
/** @var \Illuminate\Http\JsonResponse $response */
$response = $this->json('GET', '/invalid-slug')->response;
$response = $this->json('GET', '/invalid-slug')->baseResponse;

$this->assertJsonResponse($response);
$this->assertFalse($response->isOk());
static::assertJsonResponse($response);
static::assertFalse($response->isOk());

$expected = [
'status' => 404,
'code' => 'error',
'message' => 'Post not found with the given slug [invalid-slug]',
];

$this->assertSame($expected, $response->getData(true));
static::assertSame($expected, $response->getData(true));
}

/* -----------------------------------------------------------------
Expand All @@ -122,8 +122,8 @@ public function it_can_respond_with_error_response_via_trait()
*
* @param \Illuminate\Http\JsonResponse $response
*/
protected function assertJsonResponse($response)
public static function assertJsonResponse($response)
{
$this->assertInstanceOf(\Illuminate\Http\JsonResponse::class, $response);
static::assertInstanceOf(\Illuminate\Http\JsonResponse::class, $response);
}
}
10 changes: 5 additions & 5 deletions tests/Http/Middleware/AjaxOnlyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ class AjaxOnlyTest extends TestCase
public function it_can_pass_ajax_request()
{
/** @var \Illuminate\Http\JsonResponse $response */
$response = $this->json('GET', '/')->response;
$response = $this->json('GET', '/')->baseResponse;

$this->assertTrue($response->isOk());
static::assertTrue($response->isOk());

$expected = [
'status' => 200,
'code' => 'success',
'message' => 'Hello world',
];

$this->assertSame($expected, $response->getData(true));
static::assertSame($expected, $response->getData(true));
}

/** @test */
Expand All @@ -38,14 +38,14 @@ public function it_must_block_non_ajax_request()
/** @var \Illuminate\Http\JsonResponse $response */
$response = $this->call('GET', '/');

$this->assertFalse($response->isOk());
static::assertFalse($response->isOk());

$expected = [
'status' => 403,
'code' => 'error',
'message' => 'Invalid AJAX Request',
];

$this->assertSame($expected, $response->getData(true));
static::assertSame($expected, $response->getData(true));
}
}
7 changes: 4 additions & 3 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php namespace Arcanedev\LaravelApiHelper\Tests;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Orchestra\Testbench\BrowserKit\TestCase as BaseTestCase;
use Orchestra\Testbench\TestCase as BaseTestCase;

/**
* Class TestCase
Expand Down Expand Up @@ -92,14 +93,14 @@ private function registerRoutes($router)

protected function createTables()
{
Schema::create('users', function ($table) {
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('first_name');
$table->string('last_name');
$table->string('email');
});

Schema::create('posts', function ($table) {
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->string('title');
Expand Down
Loading

0 comments on commit 1a176c3

Please sign in to comment.