SlideShare a Scribd company logo
Automated Unit Testing   using PHPUnit, Selenium and Phing Tricode Professional Services www.tricode.nl 01-05-2008 Sander van Beek & Patrick van Dissel
“ One test is worth a thousand expert opinions” -- Bill Nye, The Science Guy
Automated Unit Testing Put Angels on Your Shoulders Unit Testing Use It Before You Build It PHPUnit Different Makes a Difference Selenium Automate, Automate, Automate Phing
Put Angels on Your Shoulders Unit Testing  is a software verification and validation method where the programmer gains confidence that individual units of source code are fit for use A  unit  is the smallest testable part of an application, e.g. a  method Unit testing is  regression testing , making sure made changes are not a step backwards
Unit Testing Without Unit Testing: You write code and stick in some print statements to see the value of a few key variables. You run the code, maybe in a debug mode, and look at the results manually, fix problems that come up  Then you throw away the print statements or exit the debug mode, and move on to the next item
Unit Testing With Unit Testing: With Unit Testing you take that familiar process and instead of throwing away debug code, you save it, and continue to run it automatically Instead of manually inspecting the interesting variables, you write code to check for specific values in specific situations
Unit Testing Benefits: Provides instant feedback Code gets exercised repeatedly. As you change and rewrite your code, test cases will check that you haven’t broken existing contracts. You can quickly identify and fix any problems Makes your code robust Testing helps you think through the behavior of the code, exercising the positive, negative and exceptional cases
Unit Testing Benefits (continued): Can be a helpful design tool Unit testing can help you achieve a pragmatic and simpler design Is a confidence booster You’ve tested your code and exercised its behavior for a variety of different conditions: this will give you the confidence when faced with new,  high pressure tasks on tight deadlines You can change anything as long as the tests stay  green !
Unit Testing Benefits (continued): Can act as probes when solving problems Tests go  red  when something is wrong. If something is wrong and tests stay  green , that means that new test-cases need to be created for that specific situation Are reliable documentation Unit tests can serve as accurate, reliable documentation  When following an easy naming-convention you can even create documentation based on unit tests
Unit Testing Benefits (continued): Are a learning aid You can write unit tests against an API to facilitate your learning. The tests not only help you understand the behavior of the API but also help you quickly find any incompatible changes that might be introduced later
Unit Testing Limitations: Public API only Unit tests are focused on the public API only! Protected and private API can be tested, but wrappers are needed to get this to work. It’s a bit more work, but advised for very important/complex methods Tests are not created and updated by themselves Creating and keeping unit tests up-to-date is not an automatic process. You must to have the discipline to create and update the tests yourself!
Unit Testing Limitations (continued): Not everything can be tested By default, unit tests are focused on testing behavior of single units. Integration, performance, GUI and user acceptance tests are not the focus or supported by unit testing alone Using unit testing in combination with other testing tools can extend the reach of the tests. More and more extensions are added to unit testing frameworks to support these tools
Unit Testing Some best practices: Don't assume the order in which tests within a test case run Avoid writing test cases with side effects Do not load data from hard-coded locations on a file system Keep tests in the same location as the source code Name tests properly Keep tests small and fast Test Behavior, Not Methods Apply the “Too Simple to Break” Rule Use Object-Oriented Best Practices In Your Test Cases
Use It Before You Build It PHPUnit  is a unit testing framework for PHP5 It is one of the  xUnit  family of frameworks that originated with Kent Beck's SUnit for Smalltalk Wikipedia has a nice list of unit testing frameworks: http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks
PHPUnit Static Test structure
PHPUnit Runtime Test structure
PHPUnit Basic concepts of xUnit: Test fixture The set of preconditions or state needed for a test to succeed. Also known as a test context.  Test case A single test method within a test suite. The  setUp()  and  tearDown()  methods of the test suite are executed before and after each test case, respectively Assertion Evaluate the result of the test case Test suite A collection of test cases, and A collection of test suites
A simple Test Suite class  ArrayTest extends   PHPUnit_Framework_TestCase { public function  testNewArrayIsempty() { $array  =  array (); $this -> assertEquals ( 0 , count( $array )); } }
A simple Test Suite class  ArrayTest extends  PHPUnit_Framework_TestCase { protected   $fixture ; protected   function   setUp() { parent ::setUp(); $this ->fixture =  array (); } protected function   tearDown() { parent ::tearDown(); $this ->fixture = null; } public function  testNewArrayIsempty() { $this ->assertEquals( 0 , count( $this ->fixture )); } }
Writing tests A  test suite  is a class that extends from  PHPUnit_Framework_TestCase A  test case  is a method within a test suite, which: Method name starts with ‘ test ’, or Is annotated with ‘ @test ’ The  setUp()  method of a test suite can be overriden and should be used to setup the fixture.  setUp()  is called  before each  test case The  tearDown()  method of a test suite can be overriden and should be used to cleanup the fixture. tearDown()  is called  after each  test case
Executing tests DEMO From command-line From Zend Studio Generating a result report Code-coverage
Data providers class  DataTest extends  PHPUnit_Framework_TestCase { /**       *  @dataProvider provider       */ public function  testAdd( $a ,  $b ,  $c )      {          $this ->assertEquals( $c ,  $a  +  $b );      }      public function   provider()      {       return array (             array ( 0, 0, 0 )         ,  array (0, 1, 1)          ,  array (1, 0, 1)             ,  array (1, 1, 3)  // fails          );      } }
Testing exceptions class  ExceptionTest  extends  PHPUnit_Framework_TestCase {      /**       *  @expectedException InvalidArgumentException       */      public function  testException()      { throw new   InvalidArgumentException (); } } PHPUnit converts PHP errors, notices and warnings to  exceptions, respectively: PHPUnit_Framework_Error PHPUnit_Framework_Error_Notice PHPUnit_Framework_Error_Warning
Testing performance class  PerformanceTest  extends   PHPUnit_Extensions_PerformanceTestCase { public function  testPerformance()      {          $this -> setMaxRunningTime ( 2 );   // 2 seconds          sleep( 1 );   // 1 second      } }
Testing output class  OutputTest extends   PHPUnit_Extensions_OutputTestCase {      public function  testExpectFooActualFoo()      {          $this -> expectOutputString(' foo ');          print  ' foo ';      }  } PHP's Output Buffering feature is used to provide the functionality that is necessary for this
Advanced usage Code Coverage Analysis Grouping of tests @group Mark tests incomplete Mark tests skipped Behavior-Driven development stories Agile documentation --story, --tap, --testdox Test doubles Stubs and Mocks Skeleton generation from test case to class from class to test case
Documentation Want to learn more? PHPUnit pocket guide  www.phpunit.de /manual/   Testing patterns  www.xunitpatterns.com At the end you will receive: A PHPUnit Cheatsheet for version 3.3 A Unit Testing best practices document A Test-Driven-Development: Rhythm reference guide Quick reference guid
Selenium Web application automated testing suite Tricode Professional Services www.tricode.nl 24-04-2009 Sander van Beek
Selenium Selenium is a suite of tools to automate web app testing across many platforms.  Selenium... runs in many browsers and operating systems  can be controlled by many programming languages and testing frameworks.
Selenium Selenium suite has 3 main tools: Selenium IDE  Create tests Selenium RC (remote contol) Run tests in different browsers Selenium Grid Scale out, speed up
Selenium
Selenium IDE Firefox plug-in Record tests (demo) Export them to different formats HTML C# Java PHP Ruby Perl Python
Selenium IDE Commands: Actions  open, click, refresh Accessors  Get state and store it Assertions  Verify state. Have 3 modes: - assert (halt on error) - verify (generate warning on error) - waitFor (wait for condition to become true)
Selenium RC Run distributed Selenium tests on one (remote) server
Selenium RC Supported browsers: Firefox 2, 3 IE 7, 8 Safari 2, 3 Opera 8, 9 Others: partially Supported operating systems: Windows Linux OS X, Solaris Others (as long as they run supported browsers)
Selenium Grid Selenium in parallel on multiple servers (or VM’s)
Selenium Grid http://saucelabs.com/ : Selenium on EC2 TestSwarm:  http:// ejohn.org/blog/javascript -testing-does-not-scale/
Questions More info:  http://seleniumhq.org/
Phing  An automated build system based on Apache ant  Tricode Professional Services www.tricode.nl 14-12-2008 Sander van Beek
Phing PHing Is Not GNU make;  it's a project build system based on Apache Ant. You can do anything with it that you could do with a traditional build system like GNU make, and its use of simple XML build files and extensible PHP "task" classes make it an easy-to-use and highly flexible build framework. Features include file transformations (e.g. token replacement, XSLT transformation, Smarty template transformations), file system operations, interactive build support, SQL execution, CVS operations, tools for creating PEAR packages, and much more.
Phing Automated build tool Types of automated builds: On demand Scheduled (nightly build) Automated (continuous integration)
Phing Why ‘build’ PHP? Improve product quality  Eliminate redundant tasks  Minimize "bad builds"  Eliminate dependencies on key personnel  Have history of builds and releases in order to investigate issues Save time and money - because of the reasons listed above
Concepts Targets & taks The build file: build.xml Project Target1 Task1 Task2 Target2 Task1 Task2 Target3 Task1 Task2 Targets can be dependant on each other One default target (run when no task is specified on command line)
Task types Core PhingCall, input, phpeval, condition, echo, exec File system Copy, delete, move, mkdir, touch, available, resolvePath Transformation XsltTask, ReflexiveTask Packaging pearPackageTask, zipTask, tarTask, dbdeploy, ioncube
Task types Version control svnCheckout, svnExport, svnUpdate, svnLastRevision Quality assurance phpunitTask, zendCodeAnalyser, phpDocumentor, phpCodesniffer, coverageXXX, phpLint Filters Replacing, stripping comments/whitespaces, line numbering, tidy and more Easy to add new tasks
Filesets Can be used in many tasks <fileset dir=&quot;/etc&quot; > <include name=&quot;httpd/**&quot; /> <include name=&quot;php.ini&quot; /> <exclude name=“doc/**&quot; /> </fileset>  **/* <- Ant glob syntax
Property files Create environment specific builds E.g. build.properties, c ontains ‘key=value’ lines. E.g: database.user=upcpl Can be used to replace properties in source code - e.g. ${database.user} <property file=&quot;build.properties&quot; />  <reflexive> <fileset dir=“config&quot;> <include file=“config.php”/> </fileset> <filterchain> <expandproperties />  </filterchain> </reflexive>
Running phine Simply run ‘phing’ in the directory containing build.xml Optionally specify a target as the first parameter Can also be run automated, e.g. from cruisecontrol or hudson

More Related Content

PPT
Automated Unit Testing
PDF
Unit Testing
PPS
Why Unit Testingl
PDF
Unit testing best practices
PPT
ODP
Testing In Java
PDF
Unit testing, principles
PPT
Testing and Mocking Object - The Art of Mocking.
Automated Unit Testing
Unit Testing
Why Unit Testingl
Unit testing best practices
Testing In Java
Unit testing, principles
Testing and Mocking Object - The Art of Mocking.

What's hot (20)

PDF
Clean Unit Test Patterns
PDF
Unit testing with JUnit
PPTX
PDF
PPTX
.Net Unit Testing with Visual Studio 2010
PDF
Test driven development - JUnit basics and best practices
PPTX
Unit Testing Concepts and Best Practices
PDF
Workshop unit test
PPTX
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
PPT
PPTX
Introduction To J unit
ODP
Embrace Unit Testing
PPS
JUnit Presentation
PPTX
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
PDF
Unit testing with JUnit
PPT
JUnit 4
PPTX
Unit Testing with JUnit4 by Ravikiran Janardhana
PPTX
JUnit- A Unit Testing Framework
PPTX
Unit tests & TDD
Clean Unit Test Patterns
Unit testing with JUnit
.Net Unit Testing with Visual Studio 2010
Test driven development - JUnit basics and best practices
Unit Testing Concepts and Best Practices
Workshop unit test
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
Introduction To J unit
Embrace Unit Testing
JUnit Presentation
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Unit testing with JUnit
JUnit 4
Unit Testing with JUnit4 by Ravikiran Janardhana
JUnit- A Unit Testing Framework
Unit tests & TDD
Ad

Similar to Unit testing php-unit - phing - selenium_v2 (20)

PPTX
PHPUnit: from zero to hero
PDF
Fighting Fear-Driven-Development With PHPUnit
PPTX
Unit Testng with PHP Unit - A Step by Step Training
ZIP
Test
PPT
Test Driven Development with PHPUnit
PPTX
Test in action – week 1
PPT
Unit testing
PDF
Introduction to Unit Testing with PHPUnit
PPT
Unit Testing using PHPUnit
KEY
PHPUnit testing to Zend_Test
PDF
Leveling Up With Unit Testing - LonghornPHP 2022
KEY
Developer testing 101: Become a Testing Fanatic
KEY
Php Unit With Zend Framework Zendcon09
PDF
Unit Testing from Setup to Deployment
PDF
Test Automation
PDF
Cursus phpunit
PPTX
Test in action week 2
PPT
Phpunit
PDF
Unit testing in PHP
PDF
Leveling Up With Unit Testing - php[tek] 2023
PHPUnit: from zero to hero
Fighting Fear-Driven-Development With PHPUnit
Unit Testng with PHP Unit - A Step by Step Training
Test
Test Driven Development with PHPUnit
Test in action – week 1
Unit testing
Introduction to Unit Testing with PHPUnit
Unit Testing using PHPUnit
PHPUnit testing to Zend_Test
Leveling Up With Unit Testing - LonghornPHP 2022
Developer testing 101: Become a Testing Fanatic
Php Unit With Zend Framework Zendcon09
Unit Testing from Setup to Deployment
Test Automation
Cursus phpunit
Test in action week 2
Phpunit
Unit testing in PHP
Leveling Up With Unit Testing - php[tek] 2023
Ad

More from Tricode (part of Dept) (20)

PDF
The Top Benefits of Magnolia CMS’s Inspirational Open Suite Ideology
PPTX
Agile QA 2017: A New Hope
PDF
Mobile Sensor Networks based on Smartphone devices and Web Services
PPTX
Keeping Your Clients Happy and Your Management Even Happier
PDF
Intro to JHipster
PDF
Porn, the leading influencer of Technology
PDF
De 4 belangrijkste risicofactoren van het nearshoring proces
PDF
Internet Addiction (Social Media Edition)
PPTX
Kids Can Code - an interactive IT workshop
PPTX
RESTful API - Best Practices
PDF
Deep Learning - STM 6
PDF
How Technology is Affecting Society - STM 6
ODP
Monolithic to Microservices Architecture - STM 6
PDF
Customers speak on Magnolia CMS
PDF
Quality Nearshoring met Tricode
PDF
AEM Digital Assets Management - What's new in 6.2?
PDF
10 nearshoring it trends om in 2016 te volgen
PDF
Tricode & Magnolia
PDF
Why you should use Adobe Experience Manager Mobile
PDF
Introducing: Tricode's Software Factory
The Top Benefits of Magnolia CMS’s Inspirational Open Suite Ideology
Agile QA 2017: A New Hope
Mobile Sensor Networks based on Smartphone devices and Web Services
Keeping Your Clients Happy and Your Management Even Happier
Intro to JHipster
Porn, the leading influencer of Technology
De 4 belangrijkste risicofactoren van het nearshoring proces
Internet Addiction (Social Media Edition)
Kids Can Code - an interactive IT workshop
RESTful API - Best Practices
Deep Learning - STM 6
How Technology is Affecting Society - STM 6
Monolithic to Microservices Architecture - STM 6
Customers speak on Magnolia CMS
Quality Nearshoring met Tricode
AEM Digital Assets Management - What's new in 6.2?
10 nearshoring it trends om in 2016 te volgen
Tricode & Magnolia
Why you should use Adobe Experience Manager Mobile
Introducing: Tricode's Software Factory

Unit testing php-unit - phing - selenium_v2

  • 1. Automated Unit Testing using PHPUnit, Selenium and Phing Tricode Professional Services www.tricode.nl 01-05-2008 Sander van Beek & Patrick van Dissel
  • 2. “ One test is worth a thousand expert opinions” -- Bill Nye, The Science Guy
  • 3. Automated Unit Testing Put Angels on Your Shoulders Unit Testing Use It Before You Build It PHPUnit Different Makes a Difference Selenium Automate, Automate, Automate Phing
  • 4. Put Angels on Your Shoulders Unit Testing is a software verification and validation method where the programmer gains confidence that individual units of source code are fit for use A unit is the smallest testable part of an application, e.g. a method Unit testing is regression testing , making sure made changes are not a step backwards
  • 5. Unit Testing Without Unit Testing: You write code and stick in some print statements to see the value of a few key variables. You run the code, maybe in a debug mode, and look at the results manually, fix problems that come up Then you throw away the print statements or exit the debug mode, and move on to the next item
  • 6. Unit Testing With Unit Testing: With Unit Testing you take that familiar process and instead of throwing away debug code, you save it, and continue to run it automatically Instead of manually inspecting the interesting variables, you write code to check for specific values in specific situations
  • 7. Unit Testing Benefits: Provides instant feedback Code gets exercised repeatedly. As you change and rewrite your code, test cases will check that you haven’t broken existing contracts. You can quickly identify and fix any problems Makes your code robust Testing helps you think through the behavior of the code, exercising the positive, negative and exceptional cases
  • 8. Unit Testing Benefits (continued): Can be a helpful design tool Unit testing can help you achieve a pragmatic and simpler design Is a confidence booster You’ve tested your code and exercised its behavior for a variety of different conditions: this will give you the confidence when faced with new, high pressure tasks on tight deadlines You can change anything as long as the tests stay green !
  • 9. Unit Testing Benefits (continued): Can act as probes when solving problems Tests go red when something is wrong. If something is wrong and tests stay green , that means that new test-cases need to be created for that specific situation Are reliable documentation Unit tests can serve as accurate, reliable documentation When following an easy naming-convention you can even create documentation based on unit tests
  • 10. Unit Testing Benefits (continued): Are a learning aid You can write unit tests against an API to facilitate your learning. The tests not only help you understand the behavior of the API but also help you quickly find any incompatible changes that might be introduced later
  • 11. Unit Testing Limitations: Public API only Unit tests are focused on the public API only! Protected and private API can be tested, but wrappers are needed to get this to work. It’s a bit more work, but advised for very important/complex methods Tests are not created and updated by themselves Creating and keeping unit tests up-to-date is not an automatic process. You must to have the discipline to create and update the tests yourself!
  • 12. Unit Testing Limitations (continued): Not everything can be tested By default, unit tests are focused on testing behavior of single units. Integration, performance, GUI and user acceptance tests are not the focus or supported by unit testing alone Using unit testing in combination with other testing tools can extend the reach of the tests. More and more extensions are added to unit testing frameworks to support these tools
  • 13. Unit Testing Some best practices: Don't assume the order in which tests within a test case run Avoid writing test cases with side effects Do not load data from hard-coded locations on a file system Keep tests in the same location as the source code Name tests properly Keep tests small and fast Test Behavior, Not Methods Apply the “Too Simple to Break” Rule Use Object-Oriented Best Practices In Your Test Cases
  • 14. Use It Before You Build It PHPUnit is a unit testing framework for PHP5 It is one of the xUnit family of frameworks that originated with Kent Beck's SUnit for Smalltalk Wikipedia has a nice list of unit testing frameworks: http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks
  • 15. PHPUnit Static Test structure
  • 16. PHPUnit Runtime Test structure
  • 17. PHPUnit Basic concepts of xUnit: Test fixture The set of preconditions or state needed for a test to succeed. Also known as a test context. Test case A single test method within a test suite. The setUp() and tearDown() methods of the test suite are executed before and after each test case, respectively Assertion Evaluate the result of the test case Test suite A collection of test cases, and A collection of test suites
  • 18. A simple Test Suite class ArrayTest extends PHPUnit_Framework_TestCase { public function testNewArrayIsempty() { $array = array (); $this -> assertEquals ( 0 , count( $array )); } }
  • 19. A simple Test Suite class ArrayTest extends PHPUnit_Framework_TestCase { protected $fixture ; protected function setUp() { parent ::setUp(); $this ->fixture = array (); } protected function tearDown() { parent ::tearDown(); $this ->fixture = null; } public function testNewArrayIsempty() { $this ->assertEquals( 0 , count( $this ->fixture )); } }
  • 20. Writing tests A test suite is a class that extends from PHPUnit_Framework_TestCase A test case is a method within a test suite, which: Method name starts with ‘ test ’, or Is annotated with ‘ @test ’ The setUp() method of a test suite can be overriden and should be used to setup the fixture. setUp() is called before each test case The tearDown() method of a test suite can be overriden and should be used to cleanup the fixture. tearDown() is called after each test case
  • 21. Executing tests DEMO From command-line From Zend Studio Generating a result report Code-coverage
  • 22. Data providers class  DataTest extends  PHPUnit_Framework_TestCase { /**       *  @dataProvider provider       */ public function  testAdd( $a ,  $b ,  $c )      {          $this ->assertEquals( $c ,  $a  +  $b );      }      public function   provider()      {      return array (            array ( 0, 0, 0 )        , array (0, 1, 1)         , array (1, 0, 1)            , array (1, 1, 3) // fails          );      } }
  • 23. Testing exceptions class  ExceptionTest  extends  PHPUnit_Framework_TestCase {      /**       *  @expectedException InvalidArgumentException       */      public function  testException()      { throw new InvalidArgumentException (); } } PHPUnit converts PHP errors, notices and warnings to exceptions, respectively: PHPUnit_Framework_Error PHPUnit_Framework_Error_Notice PHPUnit_Framework_Error_Warning
  • 24. Testing performance class  PerformanceTest  extends   PHPUnit_Extensions_PerformanceTestCase { public function  testPerformance()      {          $this -> setMaxRunningTime ( 2 ); // 2 seconds          sleep( 1 ); // 1 second      } }
  • 25. Testing output class  OutputTest extends   PHPUnit_Extensions_OutputTestCase {      public function  testExpectFooActualFoo()      {          $this -> expectOutputString(' foo ');          print  ' foo ';      }  } PHP's Output Buffering feature is used to provide the functionality that is necessary for this
  • 26. Advanced usage Code Coverage Analysis Grouping of tests @group Mark tests incomplete Mark tests skipped Behavior-Driven development stories Agile documentation --story, --tap, --testdox Test doubles Stubs and Mocks Skeleton generation from test case to class from class to test case
  • 27. Documentation Want to learn more? PHPUnit pocket guide www.phpunit.de /manual/ Testing patterns www.xunitpatterns.com At the end you will receive: A PHPUnit Cheatsheet for version 3.3 A Unit Testing best practices document A Test-Driven-Development: Rhythm reference guide Quick reference guid
  • 28. Selenium Web application automated testing suite Tricode Professional Services www.tricode.nl 24-04-2009 Sander van Beek
  • 29. Selenium Selenium is a suite of tools to automate web app testing across many platforms. Selenium... runs in many browsers and operating systems can be controlled by many programming languages and testing frameworks.
  • 30. Selenium Selenium suite has 3 main tools: Selenium IDE Create tests Selenium RC (remote contol) Run tests in different browsers Selenium Grid Scale out, speed up
  • 32. Selenium IDE Firefox plug-in Record tests (demo) Export them to different formats HTML C# Java PHP Ruby Perl Python
  • 33. Selenium IDE Commands: Actions open, click, refresh Accessors Get state and store it Assertions Verify state. Have 3 modes: - assert (halt on error) - verify (generate warning on error) - waitFor (wait for condition to become true)
  • 34. Selenium RC Run distributed Selenium tests on one (remote) server
  • 35. Selenium RC Supported browsers: Firefox 2, 3 IE 7, 8 Safari 2, 3 Opera 8, 9 Others: partially Supported operating systems: Windows Linux OS X, Solaris Others (as long as they run supported browsers)
  • 36. Selenium Grid Selenium in parallel on multiple servers (or VM’s)
  • 37. Selenium Grid http://saucelabs.com/ : Selenium on EC2 TestSwarm: http:// ejohn.org/blog/javascript -testing-does-not-scale/
  • 38. Questions More info: http://seleniumhq.org/
  • 39. Phing An automated build system based on Apache ant Tricode Professional Services www.tricode.nl 14-12-2008 Sander van Beek
  • 40. Phing PHing Is Not GNU make; it's a project build system based on Apache Ant. You can do anything with it that you could do with a traditional build system like GNU make, and its use of simple XML build files and extensible PHP &quot;task&quot; classes make it an easy-to-use and highly flexible build framework. Features include file transformations (e.g. token replacement, XSLT transformation, Smarty template transformations), file system operations, interactive build support, SQL execution, CVS operations, tools for creating PEAR packages, and much more.
  • 41. Phing Automated build tool Types of automated builds: On demand Scheduled (nightly build) Automated (continuous integration)
  • 42. Phing Why ‘build’ PHP? Improve product quality Eliminate redundant tasks Minimize &quot;bad builds&quot; Eliminate dependencies on key personnel Have history of builds and releases in order to investigate issues Save time and money - because of the reasons listed above
  • 43. Concepts Targets & taks The build file: build.xml Project Target1 Task1 Task2 Target2 Task1 Task2 Target3 Task1 Task2 Targets can be dependant on each other One default target (run when no task is specified on command line)
  • 44. Task types Core PhingCall, input, phpeval, condition, echo, exec File system Copy, delete, move, mkdir, touch, available, resolvePath Transformation XsltTask, ReflexiveTask Packaging pearPackageTask, zipTask, tarTask, dbdeploy, ioncube
  • 45. Task types Version control svnCheckout, svnExport, svnUpdate, svnLastRevision Quality assurance phpunitTask, zendCodeAnalyser, phpDocumentor, phpCodesniffer, coverageXXX, phpLint Filters Replacing, stripping comments/whitespaces, line numbering, tidy and more Easy to add new tasks
  • 46. Filesets Can be used in many tasks <fileset dir=&quot;/etc&quot; > <include name=&quot;httpd/**&quot; /> <include name=&quot;php.ini&quot; /> <exclude name=“doc/**&quot; /> </fileset> **/* <- Ant glob syntax
  • 47. Property files Create environment specific builds E.g. build.properties, c ontains ‘key=value’ lines. E.g: database.user=upcpl Can be used to replace properties in source code - e.g. ${database.user} <property file=&quot;build.properties&quot; /> <reflexive> <fileset dir=“config&quot;> <include file=“config.php”/> </fileset> <filterchain> <expandproperties /> </filterchain> </reflexive>
  • 48. Running phine Simply run ‘phing’ in the directory containing build.xml Optionally specify a target as the first parameter Can also be run automated, e.g. from cruisecontrol or hudson