Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Laravel 5.x Cookbook

You're reading from  Laravel 5.x Cookbook

Product type Book
Published in Sep 2016
Publisher Packt
ISBN-13 9781786462084
Pages 402 pages
Edition 1st Edition
Languages
Authors (2):
Terry Matula Terry Matula
Profile icon Terry Matula
Alfred Nutile Alfred Nutile
Profile icon Alfred Nutile
View More author details

Table of Contents (17) Chapters

Laravel 5.x Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
1. Setting Up and Installing Laravel 2. Using Composer Packages 3. Routing 4. Building Views and Adding Style 5. Working with Data 6. Adding Angular to Your App 7. Authentication, Security, and Subscriptions 8. Testing and Debugging Your Application 9. Adding Advanced Features to Your App 10. Deploying Your App Index

Testing your view based route in PHPUnit


Using the above recipe, I was able to make a view right from the route, now I want to test my view and make sure it is doing what is expected. Typically, I would use Behat but in this example, I will use PHPUnit.

Getting ready

If you follow the above recipe, you will have an example page in place. From here we will start with the testing.

How to do it…

Follow the listed steps for testing your view based route:

  1. As usual, make a test:

    >php artisan make:test ExampleViewTest
    
  2. Then, in that file tests/ExampleViewTest.php, I begin to write a test:

  3. Run the test and it passes:

    > phpunit --filter=example_view
    
  4. Now, to see how we can deal with authentication, add this to the route:

  5. And what was a passing test is now failing:

  6. All we have to do is add $this->actingAs():

  7. And we are back to passing. If you are using $this->call() instead of $this->visit() then you can use $this->be() instead:

How it works…

Pretty nice how Laravel brings all of this into PHPUnit...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}