Skip to content

Switch to github testing from travisci #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI Tests

on:
pull_request:
push:
branches:
- master
- v*

jobs:
tests:
runs-on: ubuntu-22.04

strategy:
fail-fast: false
matrix:
stability: [prefer-stable]
#versions: [ { php: 8.1, laravel: 10 }, { php: 8.2, laravel: 10 }, { php: 8.3, laravel: 10 }, { php: 8.2, laravel: 11 }, { php: 8.3, laravel: 11 } ]
versions: [ { php: 8.1, laravel: 10 }, { php: 8.2, laravel: 10 }, { php: 8.3, laravel: 10 } ]

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}

steps:
- name: Checkout code
uses: actions/checkout@v4

# Docs: https://github.com/shivammathur/setup-php
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.versions.php }}
extensions: dom, curl, libxml, mbstring, zip
ini-values: error_reporting=E_ALL
tools: composer:v2
# todo: Add
coverage: none

- name: Install dependencies
run: |
composer require "illuminate/contracts=^${{ matrix.versions.laravel }}" --no-update
composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader

- name: Run phpunit tests
run: composer test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ vendor
.php_cs
.phpunit.result.cache
.phpunit.result.cache/
test-results
8 changes: 0 additions & 8 deletions .styleci.yml

This file was deleted.

37 changes: 0 additions & 37 deletions .travis.yml

This file was deleted.

10 changes: 9 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,13 @@
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
"prefer-stable": true,
"scripts": {
"test": [
"vendor/bin/phpunit"
],
"lint": [
"vendor/bin/phpcs"
]
}
}
35 changes: 21 additions & 14 deletions src/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ class Response extends IlluminateResponse
*/
protected $binding;

/**
* Intermedia content that we are working on. The result content should be a string (symfony)
* )
* @var mixed Content with which we are working
*/
protected $workingContent;

/**
* Array of registered formatters.
*
Expand Down Expand Up @@ -125,12 +132,12 @@ public static function makeFromJson(JsonResponse $json)
*/
public function morph($format = 'json')
{
$content = $this->getOriginalContent() ?? '';
$this->workingContent = $this->getOriginalContent() ?? '';

$this->fireMorphingEvent();

if (isset(static::$transformer) && static::$transformer->transformableResponse($content)) {
$content = static::$transformer->transform($content);
if (isset(static::$transformer) && static::$transformer->transformableResponse($this->workingContent)) {
$this->workingContent = static::$transformer->transform($this->workingContent);
}

$formatter = static::getFormatter($format);
Expand All @@ -147,21 +154,21 @@ public function morph($format = 'json')

$this->fireMorphedEvent();

if ($content instanceof EloquentModel) {
$content = $formatter->formatEloquentModel($content);
} elseif ($content instanceof EloquentCollection) {
$content = $formatter->formatEloquentCollection($content);
} elseif (is_array($content) || $content instanceof ArrayObject || $content instanceof Arrayable) {
$content = $formatter->formatArray($content);
} elseif ($content instanceof stdClass) {
$content = $formatter->formatArray((array) $content);
if ($this->workingContent instanceof EloquentModel) {
$this->workingContent = $formatter->formatEloquentModel($this->workingContent);
} elseif ($this->workingContent instanceof EloquentCollection) {
$this->workingContent = $formatter->formatEloquentCollection($this->workingContent);
} elseif (is_array($this->workingContent) || $this->workingContent instanceof ArrayObject || $this->workingContent instanceof Arrayable) {
$this->workingContent = $formatter->formatArray($this->workingContent);
} elseif ($this->workingContent instanceof stdClass) {
$this->workingContent = $formatter->formatArray((array) $this->workingContent);
} else {
if (! empty($defaultContentType)) {
$this->headers->set('Content-Type', $defaultContentType);
}
}

$this->content = $content;
$this->content = $this->workingContent;

return $this;
}
Expand All @@ -177,7 +184,7 @@ protected function fireMorphedEvent()
return;
}

static::$events->dispatch(new ResponseWasMorphed($this, $this->content));
static::$events->dispatch(new ResponseWasMorphed($this, $this->workingContent));
}

/**
Expand All @@ -191,7 +198,7 @@ protected function fireMorphingEvent()
return;
}

static::$events->dispatch(new ResponseIsMorphing($this, $this->content));
static::$events->dispatch(new ResponseIsMorphing($this, $this->workingContent));
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/Provider/DingoServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Dingo\Api\Provider;

use Illuminate\Routing\CallableDispatcher;
use Illuminate\Routing\Contracts\CallableDispatcher as CallableDispatcherContract;
use RuntimeException;
use Dingo\Api\Auth\Auth;
use Dingo\Api\Dispatcher;
Expand Down Expand Up @@ -55,6 +57,7 @@ public function register()
$this->registerExceptionHandler();

$this->registerDispatcher();
$this->registerCallableDispatcher();

$this->registerAuth();

Expand Down Expand Up @@ -145,6 +148,13 @@ public function registerDispatcher()
});
}

public function registerCallableDispatcher()
{
$this->app->singleton(CallableDispatcherContract::class, function ($app) {
return new CallableDispatcher($app);
});
}

/**
* Register the auth.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/LaravelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Illuminate\Contracts\Http\Kernel;
use Dingo\Api\Event\RequestWasMatched;
use Dingo\Api\Http\Middleware\Request;
use Illuminate\Foundation\Application;
use Illuminate\Contracts\Foundation\Application;
use Dingo\Api\Http\Middleware\RateLimit;
use Illuminate\Routing\ControllerDispatcher;
use Dingo\Api\Http\Middleware\PrepareController;
Expand Down
5 changes: 4 additions & 1 deletion tests/ChecksLaravelVersionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Dingo\Api\Tests;

use Dingo\Api\Tests\Stubs\Application10Stub;
use Dingo\Api\Tests\Stubs\Application9Stub;
use Dingo\Api\Tests\Stubs\ApplicationStub;
use Dingo\Api\Tests\Stubs\Application8Stub;
Expand Down Expand Up @@ -55,7 +56,9 @@ private function getApplicationStub()
$version = str_replace('v', '', $version);

// Return the version stub for the right version
if (version_compare($version, '9.0.0', '>=')) {
if (version_compare($version, '10.0.0', '>=')) {
return new Application10Stub;
} else if (version_compare($version, '9.0.0', '>=')) {
return new Application9Stub;
} elseif (version_compare($version, '8.0.0', '>=')) {
return new Application8Stub;
Expand Down
5 changes: 4 additions & 1 deletion tests/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\CallableDispatcher;
use Illuminate\Routing\Contracts\CallableDispatcher as CallableDispatcherContract;
use Illuminate\Support\Facades\Request as RequestFacade;
use Mockery as m;
use Symfony\Component\HttpKernel\Exception\GoneHttpException;
Expand Down Expand Up @@ -67,14 +69,15 @@ public function setUp(): void

$this->transformerFactory = new TransformerFactory($this->container, new TransformerStub);

$this->adapter = new RoutingAdapterStub;
$this->adapter = new RoutingAdapterStub($this->container);
$this->exception = m::mock(Handler::class);
$this->router = new Router($this->adapter, $this->exception, $this->container, null, null);

$this->auth = new Auth($this->router, $this->container, []);
$this->dispatcher = new Dispatcher($this->container, new Filesystem, $this->router, $this->auth);

app()->instance(\Illuminate\Routing\Router::class, $this->adapter);
$this->container->singleton(CallableDispatcherContract::class, CallableDispatcher::class);

$this->dispatcher->setSubtype('api');
$this->dispatcher->setStandardsTree('vnd');
Expand Down
2 changes: 1 addition & 1 deletion tests/Exception/HandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function testExceptionTraceIncludedInResponse()

$object = json_decode($response->getContent());

$this->assertObjectHasAttribute('debug', $object);
$this->assertObjectHasProperty('debug', $object);
}

public function testHttpExceptionsWithNoMessageUseStatusCodeMessage()
Expand Down
2 changes: 1 addition & 1 deletion tests/Http/Middleware/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AuthTest extends BaseTestCase
public function setUp(): void
{
$this->container = new Container;
$this->adapter = new RoutingAdapterStub;
$this->adapter = new RoutingAdapterStub($this->container);
$this->router = m::mock(Router::class);
$this->auth = m::mock(Auth::class);
$this->middleware = new AuthMiddleware($this->router, $this->auth);
Expand Down
2 changes: 1 addition & 1 deletion tests/Http/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function testBuildingWithCustomStatusCodeAndHeaders()
public function testChangingContentWithEvents()
{
$this->events->listen(ResponseWasMorphed::class, function ($event) {
$event->content['foo'] = 'bam!';
$event->content = '{"foo":"bam!"}';
});

Response::addFormatter('json', new Json);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Laravel\Lumen\Application;
use Mockery as m;

abstract class BaseAdapterTest extends BaseTestCase
abstract class BaseAdapterTestAbstract extends BaseTestCase
{
/**
* @var Container|Application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Illuminate\Events\Dispatcher;
use Illuminate\Routing\Router;

class LaravelTest extends BaseAdapterTest
class LaravelTestAbstract extends BaseAdapterTestAbstract
{
public function getAdapterInstance()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Illuminate\Http\Request;
use Laravel\Lumen\Application;

class LumenTest extends BaseAdapterTest
class LumenTestAbstract extends BaseAdapterTestAbstract
{
public function getAdapterInstance()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Routing/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class RouteTest extends BaseTestCase

public function setUp(): void
{
$this->adapter = new RoutingAdapterStub;
$this->container = new Container;
$this->adapter = new RoutingAdapterStub($this->container);
}

public function testCreatingNewRoute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Mockery as m;
use Symfony\Component\HttpKernel\Exception\HttpException;

class RouterTest extends Adapter\BaseAdapterTest
class RouterTestAbstract extends Adapter\BaseAdapterTestAbstract
{
public function getAdapterInstance()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Dingo\Api\Tests\Stubs\RoutingControllerStub;
use Illuminate\Container\Container;

class UrlGeneratorTest extends Adapter\BaseAdapterTest
class UrlGeneratorTestAbstract extends Adapter\BaseAdapterTestAbstract
{
public function getAdapterInstance()
{
Expand Down
Loading