PHPUnit Myth

380 views

Published on

PHPUnit

Published in: Technology
  • Be the first to comment

  • Be the first to like this

PHPUnit Myth

  1. 1. PH P Un itPHPUnit Myth•––• •••• •––• ••– –• •• –北緯 25 度 233 東經 121 度 3357#66
  2. 2. 寫程式時會怎麼測 試 ?!
  3. 3. 測 1 <?php 2 $fixture = array();試 ?! 3 4 $fixture[] = element; 1 <?php 2 $fixture = array(); 3 print count($fixture) . "n"; 4 $fixture[] = element; 5 print count($fixture) . "n"; 結果 : 0 1
  4. 4. 在大型專案直接把結果印出 來 反而更吃力試看看更有效率的方法 啾咪 ~^^
  5. 5. 自動化測 試<?php$fixture = array();print count($fixture) == 0 ? "okn" : "not okn";$fixture[] = element;print count($fixture) == 1 ? "okn" : "not okn";結果 :okok
  6. 6. 自動化測試 (PHPUnit 雛<?php 形)$fixture = array();assertTrue(count($fixture) == 0);$fixture[] = element;assertTrue(count($fixture) == 1);function assertTrue($condition){ if (!$condition) { throw new Exception(Assertion failed.); }}
  7. 7. PHPUnit 安裝需求PHPUnit 3.6 - 最低 PHP 5.2.7+, 建議 PHP 5.3.9+PHPUnit 3.7 - 最低 PHP 5.3.3+ , 建議 PHP 5.4.0+PHP_CodeCoverage- Xdebug 2.0.5+ 最低- Xdebug 2.1.3+ 建議安裝方式 :pear config-set auto_discover 1pear install pear.phpunit.de/PHPUnit
  8. 8. 接下來就為各位一一示範 PHPUnit 功能

×