Skip to content

Commit

Permalink
✨ Support Laravel 7 (#137)
Browse files Browse the repository at this point in the history
* Bump nunomaduro/larastan to ^0.5

* Support Laravel 7

* Don't use removed trait

* Remove TestResponse macro's and usages
  • Loading branch information
erikgaal authored Mar 8, 2020
1 parent 898d61a commit 5a8e1b2
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: false
matrix:
php: [7.2, 7.3, 7.4]
laravel: [^6.0]
laravel: [^6.0, ^7.0]
stability: [prefer-lowest, prefer-stable]

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }}
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
"require": {
"php": "^7.1.3",
"ext-json": "*",
"illuminate/support": "^6.0",
"illuminate/support": "^6.0|^7.0",
"webonyx/graphql-php": "^0.13.0"
},
"require-dev": {
"fzaninotto/faker": "^1.9",
"mockery/mockery": "^1.2",
"nunomaduro/larastan": "^0.4.3",
"orchestra/testbench": "^4.0",
"phpunit/phpunit": "^8.0"
"nunomaduro/larastan": "^0.5.0",
"orchestra/testbench": "^4.0|^5.0",
"phpunit/phpunit": "^8.0|^9.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
5 changes: 1 addition & 4 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
namespace Bakery\Console;

use Illuminate\Console\Command;
use Illuminate\Console\DetectsApplicationNamespace;

class InstallCommand extends Command
{
use DetectsApplicationNamespace;

/**
* The name and signature of the console command.
*
Expand Down Expand Up @@ -37,7 +34,7 @@ public function handle()
$this->callSilent('bakery:modelschema', ['name' => 'User']);
copy(__DIR__.'/stubs/user-schema.stub', app_path('Bakery/User.php'));

$this->setAppNamespace(app_path('Bakery/User.php'), $this->getAppNamespace());
$this->setAppNamespace(app_path('Bakery/User.php'), $this->laravel->getNamespace());
}

/**
Expand Down
12 changes: 6 additions & 6 deletions tests/Feature/AttachPivotMutationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function it_lets_you_attach_pivot_ids()
';

$response = $this->json('GET', '/graphql', ['query' => $query]);
$response->assertJsonKey('id');
$response->assertJsonFragment(['id' => $article->id]);
$this->assertDatabaseHas('taggables', ['taggable_id' => '1', 'tag_id' => '1']);
$this->assertDatabaseHas('taggables', ['taggable_id' => '1', 'tag_id' => '2']);
}
Expand All @@ -54,7 +54,7 @@ public function it_lets_you_attach_pivot_ids_with_missing_pivot_data()
';

$response = $this->json('GET', '/graphql', ['query' => $query]);
$response->assertJsonKey('id');
$response->assertJsonFragment(['id' => $user->id]);
$this->assertDatabaseHas('role_user', [
'user_id' => '1',
'role_id' => '1',
Expand All @@ -79,7 +79,7 @@ public function it_lets_you_attach_pivot_ids_with_pivot_data()
';

$response = $this->json('GET', '/graphql', ['query' => $query]);
$response->assertJsonKey('id');
$response->assertJsonFragment(['id' => $user->id]);
$this->assertDatabaseHas('role_user', [
'user_id' => '1',
'role_id' => '1',
Expand All @@ -106,7 +106,7 @@ public function it_lets_you_attach_pivot_ids_with_pivot_relation_data()
';

$response = $this->json('GET', '/graphql', ['query' => $query]);
$response->assertJsonKey('id');
$response->assertJsonFragment(['id' => $user->id]);
$this->assertDatabaseHas('role_user', [
'user_id' => '1',
'role_id' => '1',
Expand All @@ -132,7 +132,7 @@ public function it_lets_you_attach_pivot_with_create()
';

$response = $this->json('GET', '/graphql', ['query' => $query]);
$response->assertJsonKey('id');
$response->assertJsonFragment(['id' => $user->id]);
$this->assertDatabaseHas('role_user', [
'user_id' => '1',
'role_id' => '1',
Expand Down Expand Up @@ -162,7 +162,7 @@ public function it_lets_you_attach_pivot_ids_with_pivot_data_inversed()
';

$response = $this->json('GET', '/graphql', ['query' => $query]);
$response->assertJsonKey('id');
$response->assertJsonFragment(['id' => $user->id]);
$this->assertDatabaseHas('role_user', [
'user_id' => '1',
'role_id' => '1',
Expand Down
10 changes: 5 additions & 5 deletions tests/Feature/DetachPivotMutationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function it_lets_you_detach_pivot_ids()
';

$response = $this->json('GET', '/graphql', ['query' => $query]);
$response->assertJsonKey('id');
$response->assertJsonFragment(['id' => $article->id]);
$this->assertDatabaseMissing('taggables', ['taggable_id' => '1', 'tag_id' => '1']);
$this->assertDatabaseMissing('taggables', ['taggable_id' => '1', 'tag_id' => '2']);
$this->assertDatabaseHas('taggables', ['taggable_id' => '1', 'tag_id' => '3']);
Expand All @@ -59,7 +59,7 @@ public function it_lets_you_detach_pivot_ids_with_pivot_data()
';

$response = $this->json('GET', '/graphql', ['query' => $query]);
$response->assertJsonKey('id');
$response->assertJsonFragment(['id' => $user->id]);
$this->assertDatabaseHas('role_user', [
'user_id' => '1',
'role_id' => '1',
Expand Down Expand Up @@ -92,7 +92,7 @@ public function it_lets_you_detach_without_pivot_to_match_all_relatives()
';

$response = $this->json('GET', '/graphql', ['query' => $query]);
$response->assertJsonKey('id');
$response->assertJsonFragment(['id' => $user->id]);
$this->assertDatabaseMissing('role_user', [
'user_id' => '1',
'role_id' => '1',
Expand Down Expand Up @@ -120,7 +120,7 @@ public function it_lets_you_detach_with_relational_pivot_data()
';

$response = $this->json('GET', '/graphql', ['query' => $query]);
$response->assertJsonKey('id');
$response->assertJsonFragment(['id' => $user->id]);
$this->assertDatabaseHas('role_user', [
'user_id' => '1',
'role_id' => '1',
Expand Down Expand Up @@ -153,7 +153,7 @@ public function it_lets_you_detach_pivot_ids_with_pivot_data_inversed()
';

$response = $this->json('GET', '/graphql', ['query' => $query]);
$response->assertJsonKey('id');
$response->assertJsonFragment(['id' => $user->id]);
$this->assertDatabaseHas('role_user', [
'user_id' => '1',
'role_id' => '1',
Expand Down
26 changes: 0 additions & 26 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,8 @@

namespace Bakery\Tests;

use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use PHPUnit\Framework\Assert as PHPUnit;
use Illuminate\Foundation\Testing\TestResponse;
use Orchestra\Testbench\TestCase as OrchestraTestCase;

class TestCase extends OrchestraTestCase
{
public function __construct()
{
parent::__construct();

TestResponse::macro('assertJsonKey', function (string $key) {
$actual = json_encode(Arr::sortRecursive(
(array) $this->decodeResponseJson()
));

$expected = substr(json_encode([$key]), 1, -1);

PHPUnit::assertTrue(
Str::contains($actual, $expected),
'Unable to find JSON key: '.PHP_EOL.PHP_EOL.
'['.$key.']'.PHP_EOL.PHP_EOL.
'within'.PHP_EOL.PHP_EOL.
"[{$actual}]."
);

return $this;
});
}
}

0 comments on commit 5a8e1b2

Please sign in to comment.