Skip to content
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

[8.x] Add implicit binding test #35443

Merged
merged 7 commits into from
Dec 4, 2020
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"guzzlehttp/guzzle": "^6.5.5|^7.0.1",
"league/flysystem-cached-adapter": "^1.0",
"mockery/mockery": "^1.4.2",
"orchestra/testbench-core": "^6.5",
"orchestra/testbench-core": "^6.8",
"pda/pheanstalk": "^4.0",
"phpunit/phpunit": "^8.5.8|^9.3.3",
"predis/predis": "^1.1.1",
Expand Down
95 changes: 95 additions & 0 deletions tests/Integration/Routing/ImplicitRouteBindingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

namespace Illuminate\Tests\Integration\Routing;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Orchestra\Testbench\Concerns\InteractsWithPublishedFiles;
use Orchestra\Testbench\TestCase;

class ImplicitRouteBindingTest extends TestCase
{
use InteractsWithPublishedFiles;

protected $files = [
'routes/testbench.php',
];

/**
* Teardown the test environment.
*/
protected function tearDown(): void
{
$this->tearDownInteractsWithPublishedFiles();

parent::tearDown();
}

protected function defineEnvironment($app)
{
$app['config']->set('app.debug', 'true');

$app['config']->set('database.default', 'testbench');

$app['config']->set('database.connections.testbench', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);
}

protected function defineDatabaseMigrations(): void
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->timestamps();
});

$this->beforeApplicationDestroyed(function () {
Schema::dropIfExists('users');
});
}

public function testWithRouteCachingEnabled()
{
$route = <<<PHP
<?php

use Illuminate\Tests\Integration\Routing\ImplicitBindingModel;

Route::post('/user/{user}', function (ImplicitBindingModel \$user) {
return \$user;
})->middleware('web');
PHP;

file_put_contents(base_path('routes/testbench.php'), $route);

$this->artisan('route:cache')->run();

$this->reloadApplication();

$this->assertFilenameExists('bootstrap/cache/routes-v7.php');

$this->requireApplicationCachedRoutes();

$user = ImplicitBindingModel::create(['name' => 'Dries']);

$response = $this->postJson("/user/{$user->id}");

$response->assertJson([
'id' => $user->id,
'name' => $user->name,
]);

$this->artisan('route:clear')->run();
}
}

class ImplicitBindingModel extends Model
{
public $table = 'users';

protected $fillable = ['name'];
}