2016-06-13 15 views
0

「応答はビューではありませんでした」私はLaravel 5.1コントローラ用のユニットテストを足すが、検索メソッドをテストしようとしているときに問題を抱えているガイド:Laravel 5.1テスト:エラー

<?php 

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

class HomeControllerTest extends TestCase 
{ 
    /** 
    * A basic test example. 
    * 
    * @return void 
    */ 
    public function testGetIndex(){ 

    $response = $this->call('GET', '/'); 

    $this->assertEquals(200, $response->getStatusCode()); 

    $this->assertViewHas(['menu_highlight', 
     'page_title', 
     'meta_description', 
     'featured_reviews', 
     'featured_categories', 
     'images', 
     'reviews']); 

    } 

    public function testGetSearch(){ 

    $response = $this->call('GET', '/search?search_terms=test'); 

    $this->assertEquals(200, $response->getStatusCode()); 

/* problem arises bellow: */ 

    $this->assertViewHas(['page_title', 
     'meta_description', 
     'products', 
     'reviews', 
     'brands', 
     'images', 
     'categories', 
     'review_reporting_reasons', 
     'search_terms']); 

    } 
} 

testGetIndex( )メソッドはOKです問題はtestGetSearch()メソッドで発生します。何が原因の可能性がありますか?

にHomeControllerコードは以下の通りである:

<?php namespace App\Http\Controllers; 

use View; 
use Input; 
use Settings; 
use DB; 

use App\Brand; 
use App\Category; 
use App\Review; 
use App\Product; 
use App\Image; 
use App\User; 
use App\FeaturedReview; 
use App\ReviewReportingReason; 


class HomeController extends Controller 
{ 

    public function getIndex() { 


      $featured_reviews = FeaturedReview::OrderBy('id', 'DESC')->take(5)->get(); 

      $reviews = Review::where('active', '=', 1)->OrderBy('id', 'DESC')->take(5)->get(); 

      $featured_categories = Category::OrderBy('id', 'DESC')->where('featured', '=', 1)->get(); 

      $images = Image::OrderBy('id', 'DESC')->take(5)->get(); 


     if ($reviews) { 
      return view('home')->with('menu_highlight', 'menu_home') 
      ->with('page_title', Settings::get('site_name')) 
      ->with('meta_description', Settings::get('meta_description')) 
      ->with('featured_reviews', $featured_reviews) 
      ->with('featured_categories', $featured_categories) 
      ->with('images', $images) 
      ->with('reviews', $reviews); 
     } 
     else { 
      throw new \Exception('Please install the application'); 
     } 

    } 

    public function getSearch() { 
     $search_terms = Input::get('search_terms'); 

     try { 
      $products = Product::LeftJoin('categories', 'categories.id', '=', 'products.category_id') 
      ->LeftJoin('brands', 'brands.id', '=', 'products.brand_id') 
      ->select(
       'products.*', 
       'categories.id as cid', 
       'categories.name as cname', 
       'brands.id as bid', 
       'brands.name as bname' 
       ) 
      ->whereRaw("MATCH (products.name) AGAINST (?)", array($search_terms)) 
      ->orWhereRaw("MATCH (categories.name) AGAINST (?)", array($search_terms)) 
      ->orWhereRaw("MATCH (brands.name) AGAINST (?)", array($search_terms)) 
      ->where('products.active', '=', 1) 
      ->OrderBy('products.rating', 'DESC') 
      ->OrderBy('products.reviews_count', 'DESC') 
      ->GroupBy('products.id') 
      ->paginate(Settings::get('front_end_pagination')); 

      $products->setPath('search'); 
     } 
     catch(\Exception $e) { 
      return view('/products/no_products')->with('search_terms', $search_terms); 
     } 

     $reviews = Review::whereRaw("MATCH (text) AGAINST (?)", array($search_terms)) 
     ->OrWhereRaw("MATCH (title) AGAINST (?)", array($search_terms)) 
     ->OrWhereRaw("MATCH (pros) AGAINST (?)", array($search_terms)) 
     ->OrWhereRaw("MATCH (cons) AGAINST (?)", array($search_terms)) 
     ->where('active', '=', 1) 
     ->orWhere('title', 'LIKE', '%' . $search_terms . '%') 
     ->orWhere('pros', 'LIKE', '%' . $search_terms . '%') 
     ->orWhere('cons', 'LIKE', '%' . $search_terms . '%') 
     ->OrderBy('id', 'DESC') 
     ->paginate(Settings::get('front_end_pagination')); 

     $reviews->setPath('search'); 

     $brands = DB::table('brands') 
     ->select(DB::raw('brands.*, count(reviews.id) as reviews, (select count(products.id) from products where products.brand_id = brands.id) as products')) 
     ->LeftJoin('products', 'brands.id', '=', 'products.brand_id') 
     ->LeftJoin('reviews', 'reviews.product_id', '=', 'products.id') 
     ->WhereRaw("MATCH (brands.name) AGAINST (?)", array($search_terms)) 
     ->GroupBy('brands.id') 
     ->OrderBy('reviews', 'DESC') 
     ->paginate(Settings::get('front_end_pagination')); 

     $brands->setPath('search'); 

     $categories = DB::table('categories') 
     ->select(DB::raw('categories.*, count(reviews.id) as reviews, (select count(products.id) from products where products.category_id = categories.id) as products')) 
     ->LeftJoin('products', 'categories.id', '=', 'products.category_id') 
     ->LeftJoin('reviews', 'reviews.product_id', '=', 'products.id') 
     ->WhereRaw("MATCH (categories.name) AGAINST (?)", array($search_terms)) 
     ->GroupBy('categories.id') 
     ->OrderBy('reviews', 'DESC') 
     ->paginate(Settings::get('front_end_pagination')); 

     $categories->setPath('search'); 

     $images = Image::whereRaw("MATCH (description) AGAINST (?)", array($search_terms)) 
     ->OrderBy('id', 'DESC') 
     ->paginate(Settings::get('front_end_pagination')); 

     $review_reporting_reasons = ReviewReportingReason::OrderBy('ID', 'DESC')->get(); 

     return view('home/search_results') 
     ->with('page_title', 'Search results for' . ' ' . $search_terms) 
     ->with('meta_description', 'Search results for '.$search_terms) 
     ->with('products', $products) 
     ->with('reviews', $reviews) 
     ->with('brands', $brands) 
     ->with('images', $images) 
     ->with('categories', $categories) 
     ->with('review_reporting_reasons', $review_reporting_reasons) 
     ->with('search_terms', $search_terms); 
    } 
} 

答えて

1

問題は、モーダルウィンドウのHTMLソースコードを含むファイルが@include(「モーダル」)に含まれたビューファイルであった代わりに@歩留まり( 'モーダル')。このファイルはブレードテンプレートとして構成されておらず、ブレードディレクティブのない単純なhtmlです。