How to get view data during unit testing in Laravel

0 votes

I would like to check the array given to a view in a controller function has certain key value pairs. 

//my controller I am testing


public function getEdit ($user_id)
{
    $this->data['user'] = $user = \Models\User::find($user_id);

    $this->data['page_title'] = "Users | Edit";

    $this->data['clients'] = $user->account()->firstOrFail()->clients()->lists('name', 'id');

    $this->layout->with($this->data);

    $this->layout->content = \View::make('user/edit', $this->data);
}

//my test
public function testPostEdit (){

    $user = Models\User::find(parent::ACCOUNT_1_USER_1);

    $this->be($user);

    $response = $this->call('GET', 'user/edit/'.parent::ACCOUNT_1_USER_1);   

    //clients is an array.  I want to get this 
    //array and use $this->assetArrayContains() or something
    $this->assertViewHas('clients');

    $this->assertViewHas('content');

}

How do I do this using phpunit testing?

Nov 2, 2020 in Laravel by kartik
• 37,520 points
2,146 views

1 answer to this question.

0 votes

Hii,

Try this:

$response->getSession()->get("errors")

And from there you can check the contents of the message box for whatever error you might want verify.

Hope it helps!!

answered Nov 2, 2020 by Niroj
• 82,840 points

Related Questions In Laravel

0 votes
1 answer

How to pass data to view in Laravel?

Hello @kartik, You can pass data to the ...READ MORE

answered Sep 11, 2020 in Laravel by Niroj
• 82,840 points
704 views
0 votes
1 answer

How to pass data through URL and access through controller in Laravel?

Hello, You can  first refer how to  Create controller through ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
11,904 views
0 votes
1 answer

How to identify wheather the request is HTTP GET or HTTP POST in Laravel?

Hey, In order to identify the type of ...READ MORE

answered Mar 19, 2020 in Laravel by Niroj
• 82,840 points
3,294 views
+1 vote
5 answers

How to get user's IP address in Laravel?

Hey, We can get the user's IP address ...READ MORE

answered Mar 20, 2020 in Laravel by Niroj
• 82,840 points
73,776 views
0 votes
1 answer

How can we Create Multiple Where Clause Query Using Laravel Eloquent?

Hii, You can use Conditions using Array: $users = User::where([ ...READ MORE

answered Mar 30, 2020 in Laravel by Niroj
• 82,840 points
16,743 views
0 votes
1 answer

How to send email using php?

Hello @kartik 1.) Download PHPMailer, open the zip file ...READ MORE

answered Apr 1, 2020 in PHP by Niroj
• 82,840 points
1,371 views
0 votes
1 answer

Where to register Facades & Service Providers in Lumen?

Hello, To register a facade with an alias, ...READ MORE

answered Apr 6, 2020 in Laravel by Niroj
• 82,840 points
4,481 views
0 votes
1 answer

How can I update NodeJS and NPM to the next versions?

Hello @kartik, First check your NPM version npm -v 1).Update ...READ MORE

answered May 5, 2020 in Java-Script by Niroj
• 82,840 points
1,040 views
0 votes
1 answer

How to get data from Laravel backend and display in Vue/Nuxt frontend

Hello, You have to use the package dotenv. Then ...READ MORE

answered Apr 8, 2020 in Laravel by Niroj
• 82,840 points
3,234 views
0 votes
1 answer

How to pass data to mail View in laravel Mail send?

Hello @kartik, Send data like this. $data = [ ...READ MORE

answered Jul 30, 2020 in Laravel by Niroj
• 82,840 points
7,906 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP