我在Laravel测试中有这种疲惫的行为.让我告诉你我的测试.
<?php
class MatchesControllerTest extends TestCase
{
public function setUp()
{
parent::setUp();
DB::beginTransaction();
}
public function tearDown()
{
DB::rollBack();
}
public function testForFun()
{
$title = 'Yay Great Post';
// "Create" post
Post::create(compact('title'));
$crawler = $this->client->request('GET', 'posts');
$this->assertEquals(
1,
count($crawler->filter("body:contains('{$title}')")),
"Expected to see the text '{$title}' within a body element."
);
}
}
Run Code Online (Sandbox Code Playgroud)
理想情况下,测试应该在测试结束时创建一行并删除但是没有发生,我还应该做些什么.我知道当发生一些意外的异常但是我故意在最后调用它时会调用回滚,这不应该像我们认为的那样工作吗?
我对Laravel 4,嵌套路由有问题.我可以显示创建方法表单但无法存储.这是代码,我只是说到了这一点.我有一个基本资源控制器和另一个嵌套控制器
This is in my Routes.php
Route::resource('profile','ProfileController');
Route::resource('profile.bands','BandsController');
Run Code Online (Sandbox Code Playgroud)
我不认为我必须在这里显示配置文件的代码,我将向您展示BandsController
public function create($profileId)
{
return View::make('bands.create',['title' => 'Create Band Profile' , 'profileId' => $profileId]);
}
Run Code Online (Sandbox Code Playgroud)
如您所知,这只会显示表单.表格是:
{{Form::open( [ 'route' => ['profile.bands.create',$profileId]])}}
<input class="input" type="text" name="name" value="" />
<input class="input" type="text" name="city" value="" />
<input type="submit" value="submit" />
{{Form::close()}}
Run Code Online (Sandbox Code Playgroud)
现在,我不明白,当我在浏览器中查看时,表单操作url看起来不错,但是当我提交它时,我得到了,这个错误.
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
open: E:\server\www\gigmor.com\gigmor\vendor\laravel\framework\src\Illuminate\Routing\Router.php
// The method not allowed exception is essentially a HTTP 405 error, so we
// will grab the allowed methods …Run Code Online (Sandbox Code Playgroud)