Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Instant Hands-on Testing with PHPUnit How-to
Instant Hands-on Testing with PHPUnit How-to
Instant Hands-on Testing with PHPUnit How-to
Ebook187 pages1 hour

Instant Hands-on Testing with PHPUnit How-to

Rating: 0 out of 5 stars

()

Read preview

About this ebook

Filled with practical, step-by-step instructions and clear explanations for the most important and useful tasks. This is a Packt Instant How-to guide, which provides concise and clear recipes for getting started with PHPUnit for performing code testing and improving code quality."Instant Hands-on Testing with PHPUnit How-to" is for PHP developers that have an appreciation for writing accurate code. If you are new to PHPUnit, it will give you a solid foundation for understanding how to use PHPUnit to write tests for your projects. If you already have a cursory understanding of PHPUnit it will whet your appetite for some of the more difficult-to-understand concepts in PHPUnit.
LanguageEnglish
Release dateMay 23, 2013
ISBN9781782169598
Instant Hands-on Testing with PHPUnit How-to

Related to Instant Hands-on Testing with PHPUnit How-to

Related ebooks

Computers For You

View More

Related articles

Reviews for Instant Hands-on Testing with PHPUnit How-to

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Instant Hands-on Testing with PHPUnit How-to - Michael Lively

    Table of Contents

    Instant Hands-on Testing with PHPUnit How-to

    Credits

    About the Author

    About the Reviewers

    www.PacktPub.com

    Support files, eBooks, discount offers and more

    Why Subscribe?

    Free Access for Packt account holders

    Preface

    What this book covers

    What you need for this book

    Who this book is for

    Conventions

    Reader feedback

    Customer support

    Downloading the example code

    Errata

    Piracy

    Questions

    1. Instant Hands-on Testing with PHPUnit How-to

    Installing PHPUnit (Simple)

    How to do it...

    How it works...

    There's more...

    Installing PHPUnit using Composer

    Installing PHPUnit on older versions of PHP

    Writing your first test (Simple)

    Getting ready...

    How to do it...

    How it works...

    There's more...

    Class names

    Running tests (Simple)

    How to do it...

    How it works...

    There's more...

    Command line options

    --colors

    --stop-on-error and --stop-on-failure

    --debug

    --strict

    Configuring PHPUnit (Simple)

    How to do it...

    How it works...

    There's more...

    Additional configurations

    Using phpunit.xml.dist

    Adding PHPUnit to your project (Simple)

    Getting ready...

    How to do it…

    How it works…

    There's more...

    Generating tests from code (Advanced)

    Getting ready

    How to do it...

    How it works...

    There's more...

    Using @assert to generate additional code

    Using the Skeleton Generator for test-driven development

    Using test fixtures (Simple)

    How to do it...

    How it works...

    There's more...

    Using data providers (Intermediate)

    How to do it...

    How it works...

    Identifying test failures

    Using test dependencies (Advanced)

    How to do it...

    How it works...

    Multiple test dependencies

    Multiple dependent tests

    Using mock objects (Simple)

    How to do it...

    How it works...

    There's more...

    Thoughts on partial mocks

    Ignoring parameters on method expectations

    Stubbing exceptions

    Stubbing multiple return values

    Stubbing with callbacks

    Using mock builders

    Using alternative mock frameworks

    Phake

    Mockery

    Testing abstract classes (Intermediate)

    How to do it...

    How it works...

    Abstract classes in Phake

    Testing traits (Intermediate)

    How to do it...

    How it works...

    Testing exceptions and errors (Intermediate)

    How to do it...

    How it works...

    There's more...

    Testing output (Intermediate)

    How to do it...

    How it works...

    There's more...

    Testing protected and private methods (Intermediate)

    How to do it...

    How it works...

    Private and protected methods

    Testing database interaction (Advanced)

    Getting ready

    How to do it...

    How it works...

    There's more...

    Alternate data sets

    Flat XML data set

    MySQL XML data set

    YAML data set

    Validating your data with queries

    Viewing code coverage (Advanced)

    Getting ready

    How to do it...

    How it works...

    Instant Hands-on Testing with PHPUnit How-to


    Instant Hands-on Testing with PHPUnit How-to

    Copyright © 2013 Packt Publishing

    All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

    Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

    Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

    First published: May 2013

    Production Reference: 1170513

    Published by Packt Publishing Ltd.

    Livery Place

    35 Livery Street

    Birmingham B3 2PB, UK.

    ISBN 978-1-78216-958-1

    www.packtpub.com

    Credits

    Author

    Michael Lively

    Reviewers

    Brian Feaver

    Adam Englander

    Acquisition Editor

    Mary Jasmine Nadar

    Commissioning Editor

    Yogesh Dalvi

    Technical Editor

    Worrell Lewis

    Project Coordinator

    Michelle Quadros

    Proofreader

    Lydia May Morris

    Production Coordinator

    Melwyn D'sa

    Cover Work

    Melwyn D'sa

    Cover Image

    Aditi Gajjar

    About the Author

    Michael Lively has worked in a variety of roles in the software development industry for 12 years, from developer to architect and now a software development director. He has worked on a variety of different projects and a variety of different technologies over that time, from small home-grown sites serving a handful of regular users to large enterprise platforms serving millions of consumers. In addition to his professional work, he has been an active member of the PHP open source community. Some of his contributions include the database extension for PHPUnit and more recently an alternative mocking framework for PHP called Phake.

    I would like to thank everyone who, over the years, has given me opportunities to work in and with the technology industry. From my schooling to the present day I have had the fortunate blessing of meeting some of the most gifted and knowledgeable folks in the IT industry. Specifically, I would like to thank Sebastian Bergmann who introduced me to unit testing and provided me great opportunities to contribute back to the community. I would also like to thank Brian Feaver and Adam Englander. Both are fantastic co-workers and gave me lots of great feedback when I discussed topics for this book with them.

    Last but certainly not least this journey called life would not be nearly as complete without my girls. I would like to thank my wonderful wife Sharon and my fantastic girls Trinity, Hannah, and Gracelyn. Their patience and willingness to chase my goals with me has made all the difference in the world.

    About the Reviewers

    Brian Feaver is the Lead Software Architect at Selling Source LLC. He's been a software developer for over 10 years, contributes to multiple open source projects, and participates in developer-user communities. He is a strong advocate of developer testing and automated testing in general.

    Adam Englander is the CTO of Coupla where he leads their development and cloud platform initiatives. He is an accomplished software

    Enjoying the preview?
    Page 1 of 1