mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-15 10:13:58 +02:00
Added some notes on Testing. These are by no means extensive or complete.
This commit is contained in:
@@ -4,9 +4,11 @@ isChild: true
|
|||||||
|
|
||||||
## Mac Setup
|
## Mac Setup
|
||||||
|
|
||||||
OS X comes prepackaged with PHP. As of Mountain Lion, it is _not_ the current stable version of PHP, though.
|
OSX comes prepackaged with PHP but it is normally a little behind the latest stable. Lion comes with PHP 5.3.6 and Mountain Lion has 5.3.10.
|
||||||
You can get the PHP executable through a number of Mac [package managers][mac-package-managers] or [compile it yourself][mac-compile] (if compiling, be sure to have Xcode installed, or Apple's substitute ["Command Line Tools for Xcode" downloadable from Apple's Mac Developer Center][apple-developer]).
|
|
||||||
For a complete LAMP package with GUI try [MAMP2][mamp-downloads], otherwise consider [Entropy 5.4 package][entropy-downloads].
|
To update PHP on OSX you can get the PHP executable through a number of Mac [package managers][mac-package-managers] or [compile it yourself][mac-compile] (if compiling, be sure to have installed either Xcode or Apple's substitute ["Command Line Tools for Xcode" downloadable from Apple's Mac Developer Center][apple-developer]).
|
||||||
|
|
||||||
|
For a complete LAMP package with GUI try [MAMP][mamp-downloads], otherwise consider the [Entropy 5.4][entropy-downloads] package.
|
||||||
|
|
||||||
[mac-package-managers]: http://www.php.net/manual/en/install.macosx.packages.php
|
[mac-package-managers]: http://www.php.net/manual/en/install.macosx.packages.php
|
||||||
[mac-compile]: http://www.php.net/manual/en/install.macosx.compile.php
|
[mac-compile]: http://www.php.net/manual/en/install.macosx.compile.php
|
||||||
|
@@ -2,10 +2,8 @@
|
|||||||
|
|
||||||
Writing automated tests for your PHP code is considered a best practice and can lead to well-built
|
Writing automated tests for your PHP code is considered a best practice and can lead to well-built
|
||||||
applications. Automated tests are a great tool for making sure your application
|
applications. Automated tests are a great tool for making sure your application
|
||||||
does not break when you are making changes or adding new functionality.
|
does not break when you are making changes or adding new functionality and should not be ignored.
|
||||||
|
|
||||||
Some common tools are:
|
There are several different types of testing tools (or frameworks) available for PHP, which use
|
||||||
|
different approaches - all of which are trying to avoid manual testing and the need for large
|
||||||
* [PHPUnit](http://phpunit.de)
|
Quality Assurance teams, just to make sure recent changes didn't break existing functionality.
|
||||||
* [Behat](http://behat.org)
|
|
||||||
* [Selenium](http://seleniumhq.org/)
|
|
31
_posts/07-02-01-Test-Driven-Development.md
Normal file
31
_posts/07-02-01-Test-Driven-Development.md
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
---
|
||||||
|
isChild: true
|
||||||
|
---
|
||||||
|
|
||||||
|
## Test Driven Development
|
||||||
|
|
||||||
|
Unit Testing is a programatical approach to ensure functions, classes and methods are working as
|
||||||
|
expected, from the point you build them all the way through to the development cycle. By checking
|
||||||
|
values going in and out of various functions and methods, you can make sure the internal logic is
|
||||||
|
working correctly. By using Dependecy Injection and building "mock" classes you can check internal
|
||||||
|
parameter values for even better test coverage.
|
||||||
|
|
||||||
|
When you create a class or function you should create a unit test for it. At a very basic level you should
|
||||||
|
make sure it errors if you send it bad arguments and make sure it works if you send it valid arguments.
|
||||||
|
This will help ensure that when you make changes to this class or function later on in the development
|
||||||
|
cycle that the old functionality continues to work as expected. The only alternative to this would be
|
||||||
|
var_dump() in a test.php, which is no way to build an application - large or small.
|
||||||
|
|
||||||
|
The other use for unit tests is contributing to open source. If you can write a test that shows broken
|
||||||
|
functionality, then fix it, and show the test working, patches are much more likely to be accepted. If
|
||||||
|
you run a project who accepts pull requests, you should suggest this as a requirement for pull requests.
|
||||||
|
|
||||||
|
PHPUnit is the most popular and has become a de facto standard with its popular adoption amongst [PHP
|
||||||
|
frameworks][phpfws] and [Composer][composer] component developers, but there are a few alternatives around.
|
||||||
|
|
||||||
|
* [PHPUnit](http://phpunit.de/)
|
||||||
|
* [Enhance PHP](http://www.enhance-php.com/)
|
||||||
|
* [PUnit](http://punit.smf.me.uk/)
|
||||||
|
|
||||||
|
[phpfws]: /#libraries_and_frameworks
|
||||||
|
[composer]: /#composer_and_packagist
|
11
_posts/07-03-01-Behavior-Driven-Development.md
Normal file
11
_posts/07-03-01-Behavior-Driven-Development.md
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
isChild: true
|
||||||
|
---
|
||||||
|
|
||||||
|
## Behaviour Driven Development
|
||||||
|
|
||||||
|
With BDD, you write human-readable stories that describe the behavior of your application. These stories
|
||||||
|
can then be run as actual tests against your application.
|
||||||
|
|
||||||
|
* [Behat](http://behat.org/) is inspired by Ruby's [Cucumber](http://cukes.info/) project
|
||||||
|
* [Selenium](http://seleniumhq.org/) is a browser automation tool, which automates the "clicking around the site" method of testing. It can also be [combined with PHPUnit](http://www.phpunit.de/manual/3.1/en/selenium.html)
|
Reference in New Issue
Block a user