dongmo1708 2016-02-03 08:36
浏览 44
已采纳

如何在Laravel 5中检查具有单元测试的路线

I tried using unit testing, but it doesn't work. Somehow, Received status code is 404. Then, terminal stated the reason is an exception 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException'.

Routes.php

Route::get('/', function() {
    return view('toppage')->with('contents', "");
});

ExampleTest.php

use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class ExampleTest extends TestCase
{
    /**
     * A basic test example.
     *
     * @return void
     */
    public function testExample()
    {
        $this->visit('/')
             ->see('Where lane');
    }
}

nignx.conf (excerpt a part from the file)

location / {
        index            index.html index.php;
    }

    location ~* /MAMP(.*)$ {
        root             /Applications/MAMP/bin;
        index            index.php;

        location ~ \.php$ {
            try_files        $uri =404;
            fastcgi_pass     unix:/Applications/MAMP/Library/logs/fastcgi/nginxFastCGI.sock;
            fastcgi_param    SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include          fastcgi_params;
        }
    }
  • 写回答

1条回答 默认 最新

  • douyan1244 2016-02-03 12:22
    关注

    If you want to see if you can access the route. It's best to verify a text that will be on that link.

    Try this:

    class WelcomeTest extends TestCase {
    
        /**
         * Test if the public index page returns the correct view
         * GET /
         */
    
        public function testWelcomePage()
        {
            $response = $this->call('GET', '/');
    
            // check if we're getting the default welcome page. 
            //you can replace this with something on your default route's <title> Html tag
    
            $this->assertRegexp('/<title>Welcome<\/title>/', $response->getContent());
    
        }
    
    }
    

    If this fails, then try getting the site in your browser first. Clear your routes, cache and double check if the text "Where lane" acually exists on the page.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!