Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning PHP 7

You're reading from   Learning PHP 7 Build powerful real-life web applications in a simple way using PHP7 and its ecosystem.

Arrow left icon
Product type Paperback
Published in Mar 2016
Publisher Packt
ISBN-13 9781785880544
Length 414 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Antonio L Zapata (GBP) Antonio L Zapata (GBP)
Author Profile Icon Antonio L Zapata (GBP)
Antonio L Zapata (GBP)
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Setting Up the Environment 2. Web Applications with PHP FREE CHAPTER 3. Understanding PHP Basics 4. Creating Clean Code with OOP 5. Using Databases 6. Adapting to MVC 7. Testing Web Applications 8. Using Existing PHP Frameworks 9. Building REST APIs 10. Behavioral Testing Index

Database testing


This will be the most controversial of the sections of this chapter by far. When it comes to database testing, there are different schools of thought. Should we use the database or not? Should we use our development database or one in memory? It is quite out of the scope of the book to explain how to mock the database or prepare a fresh one for each test, but we will try to summarize some of the techniques here:

  • We will mock the database connection and write expectations to all the interactions between the model and the database. In our case, this would mean that we would inject a mock of the PDO object. As we will write the queries manually, chances are that we might introduce a wrong query. Mocking the connection would not help us detect this error. This solution would be good if we used ORM instead of writing the queries manually, but we will leave this topic out of the book.

  • For each test, we will create a brand new database in which we add the data we would like to have...

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 $19.99/month. Cancel anytime
Banner background image