0% found this document useful (0 votes)
14 views25 pages

Chapter 06 (Session6 - Reviewed)

Testing a PHP application involves three phases: testing the user interface, testing with valid data, and testing with invalid data. There are three types of errors that can occur: syntax errors, runtime errors, and logic errors. xDebug and NetBeans allow developers to debug PHP applications by setting breakpoints, stepping through code, inspecting variables, and viewing the stack trace to identify and fix errors.

Uploaded by

Thanh Van Dao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views25 pages

Chapter 06 (Session6 - Reviewed)

Testing a PHP application involves three phases: testing the user interface, testing with valid data, and testing with invalid data. There are three types of errors that can occur: syntax errors, runtime errors, and logic errors. xDebug and NetBeans allow developers to debug PHP applications by setting breakpoints, stepping through code, inspecting variables, and viewing the stack trace to identify and fix errors.

Uploaded by

Thanh Van Dao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Session 6

How to test and debug


a PHP application
Objectives
• An introduction to testing and debugging
• How to debug with xDebug and NetBeans
An introduction to
testing and debugging
Typical test phases for a PHP
application
• In the first phases, as you test the user interface.
• In the second phase, you should test the
application with valid data.
• In the third phase, you go all to make the
application fail by testing every combination of
invalid data and user action that you can think of.
The three types of errors that
can occur
• The goal of testing: To find all errors before the
application is put into production.
• The goal of debugging: to fix all errors before
the application is put into production.
• Three test phases
- Check the user interface to make sure that it works
correctly
- Test the application with valid input data to make
sure the results are correct
- Test the application with invalid data or unexpected
user actions.
The three types of errors that
can occur (cont.)
• The Three type of errors that can occur
– Syntax errors
– Runtime error
– Logic errors
The three types of errors that
can occur (cont.)
• The Product Discount application with a logic error
Common PHP errors
• PHP code that contains errors
Common PHP errors (cont.)
• The PHO code that contains errors in NetBeans
Common PHP errors (cont.)
• Common syntax errors
– Misspelling keywords
– Forgetting an opening or closing parenthesis, bracket,
brace, or comment character.
– Forgetting to end a PHP statement with a semicolon
– Forgetting an opening or closing quotation mark
– Not using the same opening and closing quotation
mark.
Common PHP errors (cont.)
• Problems with variable names
– Misspelling or incorrectly capitalizing a variable name
– Using a keyword as a variable name
• Problem with values
– Not checking that a value is the right data type before
processing it.
– Using one equal sign instead of two when testing for
equality.
An easy way to trace the
execution of your PHP code
• An easy way to trace the execution of a PHP
application is to insert echo statements at key
points in the code.
• The echo statement can display the values of
variables or display messages that indicate what
portion of the code is being executed.
• The incorrect value displayed, there is a good
chance that you have a logic error between the
current echo statement and the previous one.
An easy way to trace the execution
of your PHP code (cont.)
• PHP with echo statements that trace the
execution of the code
An easy way to trace the execution
of your PHP code (cont.)
• The data displayed in a browser
How to debug with xDebug and
NetBeans
How to set and remove
breakpoints
• A code editor window with a breakpoint
How to set and remove
breakpoints (cont.)
• A breakpoint is indicated by a small red square.
• Set a breakpoint.
• Remove a breakpoint
• Use the Debug Main project button on the
toolbar to begin debugging.
• When you begin debugging, NetBeans may
display a dialog box that asks you want to
debug.
How to step through code
• When you run an application with the debugger,
it stops when it encounters the first PHP
statement in the application.
How to inspect variables
• When you being a debugging session, NetBeans
stops on the first PHP statement that it
encounters.
• At this point, you can use the buttons in the
debugging toolbar to continue program
execution.
How to inspect variables (cont.)
• The toolbar buttons and shortcut keys for
stepping through the code
How to inspect variables (cont.)
• A debugging session with variables displayed
How to inspect the stack trace
• The Call Stack window show the stack trace,
which is a list of function in the reverse order in
which they were called.
• A debugging session with a stack trace
displayed.
How to inspect the stack trace
(cont.)
Summary
• The goal of testing is to find all the errors in an
application.
• The goal of debugging is to fix all the errors
before the application is put into production.
• Three type of errors can occur when you test an
application: syntax errors, runtime errors, and
logic errors.
• You can trace the execution of an application by
inserting echo statement at appropriate.
Summary (2)
• XAMPP includes a debugger known as xDebug
that can be used with an IDE like Netbeans.
• You can set breakpoints when you use a
debugger.
• You can get a stack trace when you use a
debugger.

You might also like