2012.03.27 PHPåå¼·ä¼@æ±äº¬ #58
2012.03.27 PHPåå¼·ä¼@æ±äº¬ #58
èºèºãè絡ãç¡ããstartã ã¾ãã¯installã gitã§å¼ã£å¼µã£ã¦ãããã®ã§å¤§å¤ã«ããã¡ãã好ã¿ã é©å½ãªãã£ã¬ã¯ããªã«ããã¦ããã¾ãããã clone git://github.com/mlively/Phake.git phakeä»åã¯ãphakeãã£ã¦ãã£ã¬ã¯ããªã«ãã¦ããããç´ ç´ã¨ããããã¯åç´ã ã¾ãã使ãããããã«ããã ã¤ã³ã¹ãã¼ã«ãã£ã¬ã¯ããªãä¸ã®srcã«ãã¹ãéã£ã¦ãå¿ è¦ãããã£ã½ãã®ã§ãæä½éãããããªæãã $dir = "./phake/src/"; set_include_path(get_include_path() . ':' . $dir); require_once('Phake.php');é¢åã ããdirã¯ç¸å¯¾ãã¹ã ãã©ãæ¬å½ã¯çµ¶å¯¾ãã¹ã®ã»ããããã¨æãã MagicWeaponã ã¨ãconfigã®lib_pathã«è¿½å ããæããããã ããã§
ååæºåãããPHPUnitãã®ãµã³ãã«ãããªãã¸ã§ã¯ãå¶æ¥½é¨ãã§ç´¹ä»ããã¦ãããè»çªããã®TDDã(PDF)ã¨ããè¨äºãåèã«ãTDD(Test Driven Development / ãã¹ãé§åéçº)ã¨ãã¢ããã°ã©ãã³ã°ã®æ¼ç¿è¨äºãPHPUnitã§ãªãã£ã¦ã¿ããæ®å¿µãªããèªå® ã§ç¬ãã§æ¸ããã®ã§ããã¢ããã®ãµã³ãã«ã«ã¯ãªããªããã ä½ãã®ã¯ã¹ã¿ãã¯ã¯ã©ã¹ãä»æ§ã¯â¦ isEmpty()ã§ã¹ã¿ãã¯ã空ã®å ´åãtrueããã以å¤false ãè¿ãã boolean isEmpty()size()ã§ã¹ã¿ãã¯ã®ãµã¤ãºãåå¾ããã int size()push()ã§å¼æ°ã®å¤ãã¹ã¿ãã¯ã®ä¸çªä¸ã«ç©ãã void push(int value)pop()ã§ã¹ã¿ãã¯ã®ä¸çªä¸ã®å¤ãåãé¤ãã void pop() ã¹ã¿ãã¯ã空ã®å ´åãjava.util.EmptyStackException ãçºçããt
# vendor/phake ã«ã¤ã³ã¹ãã¼ã« $ git clone https://github.com/jaz303/phake.git vendor/phake # app/bootsrap_test.php ãã¤ãã --------------------------------------------------------- <?php require_once __DIR__.'/bootstrap.php.cache'; require_once __DIR__.'/../vendor/phake/tests/bootstrap.php'; --------------------------------------------------------- # app/phpunit.xml.dist ã« bootstrap_test.php ãæå®ãã ---------
4. PHPUnit - Advanced Features Mock Objects - A way to further isolate code while testing. Database Extension - A DBUnit port to allow creation of fixtures for database content. Selenium Integration - A gateway to integration testing. PHPUnderControl - Not really PHPUnit...but still very cool. Much to cover and not much of time. Let's get started! 5. PHPUnit - Mock Objects Mock Objects - A way to
src/Acme/DemoBundle/ ã«ãã¢ããããããããããã®ã½ã¼ã¹ãèªãã§ã¿ãã Twigé¢é£ã®è¨äºã ã»Twig - The flexible, fast, and secure template engine for PHP ã»ã¦ãã¦ã©ã by Zynga Japan: PHPãã³ãã¬ã¼ãã¨ã³ã¸ã³Twigãããã£ã¦ã¿ã¾ãã Symfony2ã¯require_onceãæ¸ããªããautoload.php ã«èªã¿è¾¼ããã£ã¬ã¯ããªãæ¸ãã ã»åçï¼ç¬¬4åSymfony2åå¼·ä¼ Symfony2ç³»ã®ãã³ãã«ã¯ãããã¦Symfony1ç³»ã§è¡¨ç¾ããã¨ã¢ããªã±ã¼ã·ã§ã³ã ãã©ãããããSymfony1ç³»ã¨æ¯è¼ããªããï¼å¥ç©ãªã®ã§ããï¼ â ãã£ã·ã¥ã®åé¤ ç¾ç¶ã1系㮠symfony cc ã®ãããªãã£ãã·ã¥ãåé¤ããã³ãã³ãã¯ãªãããã§ãã ãªã®ã§ãæåã§åé¤ãããããªãã¿ããã§ããrm
以åã®Symfonyåå¼·ä¼ã®æã«ã¦ããããã¹ãã¨ã¢ãã¯ã®è©±ãããã¦ããã ããã®ã§ããããã®æã«@cakephperãããã次ã®ãããªæè¦ãé ãã¦ãã¾ããã APIãä¿¡ç¨ãã¦åºæ¬Mockã§ã¨ãã話ãAPIå´ã®ä»æ§å¤æ´ã常ã«ã¦ã©ãããã¦ãªãã¨ãããªãã®ã§ãã¬ã¼ã ã¯ã¼ã¯ã®ã¢ãããã¼ãã¨ã大å¤ãªããããªãã®ããªã¨æã£ããã ãã©ããããã¨ãã¾ã æ¶åã§ãã¦ãªã twitter - @cakephper ã¾ãæåã«åçã¨ãã¦ã¯ãAPIãå¤ããã®ã§ããã°æ¦ããã®ã¨ãããã¨ãªãã¾ããããããããã¯ã¢ãã¯ã使ããã©ããã«ã¯é¢ä¿ããã¾ãããã½ããã¦ã§ã¢ã¯ãã¬ã¼ã ã¯ã¼ã¯ãã©ã¤ãã©ãªçãµã¼ããã¼ãã£ã³ã¼ãã®ä»æ§å¤æ´ã«å¸¸ã«å½±é¿ãåãã¾ããããã§ãè°è«ã®åæãå ±æãã¦ããå¿ è¦ãããã§ãããã ã¦ããããã¹ãã¨ãã¡ã³ã¯ã·ã§ãã«ãã¹ãã®ä½¿ãåããã©ã¡ããæ¸ããããã®ããã¦ããããã¹ãã§ãã¹ããããç®æã¯ã©ãããåæã¨ãã¦ã
Symfonyã®æ©è½ãã¹ãã§ã¯æåã«WebTestCase::createClient()ã¡ã½ããã§Clientãªãã¸ã§ã¯ããä½æãããã®ãªãã¸ã§ã¯ãã使ã£ã¦ãªã¯ã¨ã¹ããè¡ãããã®è¿ãå¤ã確èªãããã¨ã«ãã£ã¦ãã¹ããè¡ãã¾ãã ãã¹ãã¯ã©ã¹: <?php ... class ...Test extends WebTestCase { public function test...() { $client = static::createClient(); $client->request('GET', '/path/to/foo'); $this->assertEquals(200, $client->getResponse()->getStatusCode()); $this->assertThat($client->getCrawler()->filter('title')->text
Symfony2åå¼·ä¼ #6 ã§LTããã¦ãã¾ããã ã¾ã¨ã¾ãã®ãªãLTã«ãªã£ã¦ãã¾ããæãåºãã®ãæ¥ããããã®ã§ãããLTã®å 容ãè£è¶³ãã¾ãã ç®æ¬¡ LTã§è©±ããã㨠å人çã«é·ãã¨æã£ã¦ãããã¹ãã³ã¼ã åå²ããå¾ã®ãã¹ãã³ã¼ã(åãã¾ãã) containerããçæããtokenãä¸æ£ ãã¹ãæã®ã¿ãcsrfãç¡å¹ã«ããã¨ãæ§ã ãªå¼å®³ã CSRF対çãæå¹ãã©ãããå¤å®ããifæ DIããæ å ±ã¯ãç»é¢é·ç§»ã§åæåããã¦æ¶ãã 諸å 輩ããã®ã¢ããã¤ã¹ ãµãããã LTã§è©±ããã㨠Symfony2ã®ã³ã³ããã¼ã©ã®ãã¡ã³ã¯ã·ã§ãã«ãã¹ãã¯ãè¤æ°ã¢ã¯ã·ã§ã³ã«ã¾ãããã®ã§ä¸ã¤ä¸ã¤ã®ãã¹ãã±ã¼ã¹ãé·ããªããã¡ããã¹ãã±ã¼ã¹ãé·ãã¨ã¡ã³ããã³ã¹ãã¥ããã®ã§ãçãããããPOSTãªã¯ã¨ã¹ãã®ã¢ã¯ã·ã§ã³ããã¹ããããã¨ãã¦ãCSRF対çã«è¦ããã ãSessionãDIãã¦ãããã¹ãã±ã¼ã¹å ã§ç»é¢é·
è¦ç´Â¶ ãã®ç« ã«æ¥ãã¾ã§ã« Symfony2 ã§ã®éçºã«é¢ããã³ã¢ã®ã³ã³ã»ããã®å¤ãã®åéãè¦ã¦ãã¾ãããããã«æ©è½ã追å ããåã«ãããã§ãã¹ãã説æãã¦ããã¾ããããã¦ããããã¹ãã§åã ã®æ©è½ããã¹ãããæ¹æ³ãæ©è½ãã¹ãã§è¤æ°ã®ã³ã³ãã¼ãã³ãã®åä½ãæ£ãããã確èªããæ¹æ³ã®ä¸¡æ¹ãè¦ã¦ããã¾ãã Symfony2 ã®ãã¹ãã®ä¸å¿ã®ã©ã¤ãã©ãªã§ãã PHP ã®ãã¹ãã©ã¤ãã©ãª PHPUnit ã説æãã¾ãããã¹ãã¯éè¦ãªãããã¯ãªã®ã§ãå¾ã®ç« ã§ãæ±ãäºå®ã§ãããã®ç« ã®æå¾ã§ã¯ãã¦ããããã¹ããæ©è½ãã¹ãã®ä¸¡æ¹ã«ããå¤ãã®ãã¹ããæ¸ããã¨ã«ãªãã¾ãããã©ã¦ã¶ãã·ãã¥ã¬ã¼ããããããã©ã¼ã ã«ãã¼ã¿ãå ¥åããããã¦ã§ããã¼ã¸ãæ£ããåºåããã¦ãããã¬ã¹ãã³ã¹ããã§ãã¯ãããã¾ããã¾ããã¢ããªã±ã¼ã·ã§ã³ã®ã³ã¼ããã¼ã¹ã§ãã¹ããã©ã®ãããã®ã«ãã¬ãã¸ãªã®ããã§ãã¯ããã¾ãã Symfony2 ã«ããã
ã¯ãã㫠第1åç®ã®æ¬ç¨¿ã¯ãå®éã«ãã¹ãã³ã¼ããæ¸ãåã«ãåºæ¬çãªèãæ¹ã§ããããªããã¹ãã³ã¼ããæ¸ãã®ãï¼ãã解説ãã¾ãã 対象èªè JavaScriptã®åºæ¬ãããç¨åº¦ç解ãã¦ããæ¹ ãã¹ãã³ã¼ããããããæ¸ããã¨èãã¦ããæ¹ é »ç¹ãªå¤åã¸ã®å¯¾å¿ ã¾ãã¯ãéçºç¾å ´ã§å¤ãè¡ããã¦ããåºæ¬çãªèãæ¹ãæ¯ãè¿ãããã¹ãã³ã¼ãããªãå¿ è¦ãªã®ããèãã¦è¡ãããã¨æãã¾ãã ããã¾ã§ã®ãã¹ãã®èãæ¹ ã¾ãã¯ãä¸è¬çãªã¦ã©ã¼ã¿ãã©ã¼ã«ã¢ãã«ãä¾ã«èãã¦ã¿ã¾ããããé常ã¦ã©ã¼ã¿ãã©ã¼ã«ã¢ãã«ã§ã¯ãè¨è¨âå®è£ âãã¹ãã¨ããé çªã§ãä½ã£ããã®ãæå¾ã«ãã¹ããã¾ããæå¾ã«ãã¹ããè¡ãã¨ããã®ã¯ãè¨ãæããã¨ãå質ãæå¾ã«æ ä¿ãããã¨è¨ãã¾ãã ã¾ããæå¾ã«ãã¹ãããå ´åã¯ãé常ãã¹ãä»æ§æ¸ãªã©ãä½æããä¸ã§å¿ è¦ãªãã¹ããã¿ã¼ã³ãæ´ãåºããæåã§ãã¹ããå®æ½ãã¾ãã å¤åã¸ã®å¯¾å¿ãæ±ãããã¦ãã ã¹ã¿ã¼ãã¢ã
íì ë¡ê·¸ì¸ íìê°ì ë¡ê·¸ì¸ ì림 à ë«ê¸° Save changes
å¹³ç´ ãããPHPããï¼ãããæ顧ããã ããèª ã«ãããã¨ããããã¾ãã 2006å¹´ããéå¶ãã¦ã¾ããã¾ãããPHPããï¼ãã§ããããµã¼ãã¹ã®å©ç¨ç¶æ³ãéã¿ã¾ãã¦ã2018å¹´9æ25æ¥ï¼ç«ææ¥ï¼ããã¡ã¾ãã¦ãµã¼ãã¹ãçµäºããã¦ããã ããã¨ã«ãªãã¾ããã ãµã¼ãã¹çµäºã«ä¼´ãã¾ãã¦ã2018å¹´8æ28æ¥ï¼ç«ææ¥ï¼ãæã¡ã¾ãã¦ãæ°è¦ä¼å¡ç»é²ãªãã³ã«Q&Aæ²ç¤ºæ¿ã¸ã®æ°ããªè³ªåãåçã®æ稿ãåæ¢ããã¦ããã ãã¾ãã ãªãããç»é²ããã ããçæ§ã®å人æ å ±ã«ã¤ãã¾ãã¦ã¯ããµã¼ãã¹çµäºå¾ãå¼ç¤¾ã責任ããã£ã¦æ¶å»ãããã¾ãã ããã¾ã§å¤ãã®çæ§ã«ãå©ç¨ãããã ãã¾ãã¦ãèª ã«ãããã¨ããããã¾ããã ãµã¼ãã¹çµäºã«ä¼´ããçæ§ã«ã¯ãä¸ä¾¿ãããããããã¾ããã¨ãå¿ãããè©«ã³ç³ãä¸ãã¾ãã æ¬ä»¶ã«é¢ãããåãåããã¯ãã¡ããããé¡ããããã¾ãã
ãã®ãããã¯ã§ã¯ã¦ããããã¹ãã®å¦ç¿ã«æç¨ãªæ¸ç±ãããã¤ãã®ã«ãã´ãªãã¨ã«ç´¹ä»ãã¦ããã¾ãã ãã®ãããã¯ã§ã¯ã¦ããããã¹ãã®å¦ç¿ã«æç¨ãªæ¸ç±ãããã¤ãã®ã«ãã´ãªãã¨ã«ç´¹ä»ãã¦ããã¾ãã 1. åºç¤ãå¦ã¶ ã¾ãæåã«ã¦ããããã¹ãã®åºæ¬çãªãããã¯ãæ±ãæ¸ç±ãç´¹ä»ãã¾ãã ãJUnitå®è·µå ¥é ï½ä½ç³»çã«å¦ã¶ã¦ããããã¹ãã®ææ³ãï¼æ¸¡è¾º ä¿®å¸, æè¡è©è«ç¤¾, 2012å¹´ï¼ ãåå¿è ï½ä¸ç´è åãã JUnitã®è§£èª¬ãä¸å¿ã«ãã¦ããããã¹ãã«é¢ããæ§ã ãªãããã¯ãä½ç³»çã«è§£èª¬ãã¦ãã¾ãã æ±ã話é¡ã¯ãxUnitããã¹ãããã«ãã·ãã¥ã¬ã¼ã¿ã®æ´»ç¨ãç¶ç¶çã¤ã³ãã°ã¬ã¼ã·ã§ã³ã«ããéç¨ãã¦ããããã¹ãã使ãæ¹æ³è«ãªã©ãå®ã«ãã¾ãã¾ã§ããã¦ããããã¹ãã«ã¤ãã¦ç¶²ç¾ çã«ç¥è¦ãæ·±ãããã¾ãã®ã§ãJUnitãJavaã使ç¨ãã¦ããªãæ¹ã§ããå§ãã§ããä¸åã§ãã ãç¾å ´ã§ä½¿ããã½ããã¦ã§ã¢ãã¹ã Javaç·¨
2012å¹´04æ19æ¥ æè¿ãæ°äººã®ãã¹ãã³ã¼ããè¦ãæ©ä¼ããããã¦ããããã¹ãã®æ¸ãæ¹ã«ã¤ãã¦èããæ©ä¼ããã£ããã¦ããããã¹ãã¯ãã³ãã¬ã¼ãã¿ãããªãã®ãããã®ã§ãããããæ¼ãããã°ã誰ã§ãç°¡åã«æ¸ããã¨ãã§ããã ããã§ã¯ããã®æ¹æ³ã«ã¤ãã¦ç´¹ä»ãããããµã³ãã«ã¯RSpecã§æ¸ããããã®ä»ã®ã¦ããããã¹ããã¬ã¼ã ã¯ã¼ã¯ã§ããå¿ç¨ãã§ããã¨ãããã ã¯ããã«ããåç´åããã¨ããã¹ã対象ã¯ç¶æ ãæã¡ãå ¥åãä¸ããã¨ä½ããã®åºåãè¡ãªããã®ã§ãããå ¥åãå¤ããã°åºåã¯å¤åããããç¶æ ãå¤åããã¨å ¥åãåãã§ãåºåãå¤ããï¼ãããããªãï¼ã ã¦ããããã¹ãã¯ããã¹ã対象ã®ç¶æ ãæä½ããä¸ããå ¥åã«ãã£ã¦æå³éãã®åºåãå¾ããããã確èªããä½æ¥ã®ãã¨ãããããªã®ã§ãã¦ããããã¹ããæ¸ãã¨ãã«ã¯ããªãã¸ã§ã¯ãã®ç¶æ ãã¨ã«ã¡ã½ããåä½ã§å ¥åã¨åºåã確èªããããã«ããã RSpecã®çä¼¼ã³ã¼ãã§æ¸ãã¨
åãã¤ãã£ããã©å¿ããã®ã§ãã¡ã¢ã 対象ã«ããã®ã¯ããã®WordPressãã©ã°ã¤ã³ãPubMan Wordpress Plugin - MPDLMediaWikiã ã¤ã³ã¹ãã¼ã«ã«è¿½å ã㦠PEARã§pear.phpunit.deãchannel discoverãã¦ã¤ã³ã¹ãã¼ã«ãã以å¤ã« # su - # pecl install xdebug $ pear install phpunit/PHPUnit_SkeletonGeneratoræå¾ã®ã¯ãPHPUnit â The PHP Testing Frameworkãããæã«å¿ è¦ã ã£ãPHPUnitã®ãªãã·ã§ã³ããã±ã¼ã¸ã ã¹ã±ã«ãã³ã®ä½æ ææ°è¾¼ã㧠$ phpunit-skelgen --test PubManPluginããã PHPUnit Skeleton Generator 1.2.0 by Sebastian Berg
ã¯ããã« åä½ãã¹ãã¨ã¯ãã·ã¹ãã ã®æ§æè¦ç´ ã§ããã¯ã©ã¹ãã¡ã½ããåä½ã§ã®åä½ã確èªããä½æ¥ã®ãã¨ãè¨ãã¾ãã Webã·ã¹ãã ã¯åºæ¬çã«ä¸ç¹å®å¤æ°ã«å ¬éãããã®ã§ãããå ¬éåã«ã¯ãã¡ãã¨ãã¹ããè¡ã£ã¦ãããã¨ãéè¦ã§ãã PHPã«ã¯ãã¹ããã¼ã«ã¨ãã¦PHPUnitã¨ããåä½ãã¹ãã®ãã¼ã«ããããPHPUnitãå©ç¨ããã¨ã¯ã©ã¹å ã®ã¡ã½ããã«å¯¾ãã¦ãã¹ãç¨ã®ã¯ã©ã¹ãèªåã§çæããå¹çãããã¹ããããã¨ãã§ãã¾ãã PHPUnitãå©ç¨ãã¦åä½ãã¹ãããå ´åã®ããã»ã¹ã¯ ãã¹ã対象ã¨ãªãã¯ã©ã¹ãPHPããã°ã©ã ã®ä½æ 1.ã§ä½æããã¯ã©ã¹ããPHPUnitå ã®ã¯ã©ã¹ãç¨ãã¦ãã¹ãç¨ã®ã¯ã©ã¹ãä½æ 2.ã§ä½æãããã¹ãç¨ã®ã¯ã©ã¹ã«ç®çã«å¿ãã¦ãã¹ãã¡ã½ããã®å®ä½ãè¨è¿° ãã¹ãå®è¡ãçµæã®ç¢ºèª ã¨ãªãã¾ãã æ¬è¨äºã§ã¯ãæ¬é£è¼ç¬¬4åãGPSæºå¸¯ã使ã£ãå£ã³ããµã¤ãæ§ç¯ãã®éã¸ãªã³ã¼ãã£ã³ã°å¦çãã
ã©ããªã«ããããããã°ã©ãããééããç¯ãã¾ãã ããããã°ã©ãã¨ããã§ãªãããã°ã©ãã®éãã¯ã ããããã°ã©ãã¯ãã¹ããè¡ã£ã¦ééããã§ããã ãæ©ãçºè¦ãã¦ãã¾ããã¨ã§ãã ãã¹ããããã®ãæ©ããã°æ©ãã»ã©ééããçºè¦ãããããªãã ã¾ããããä¿®æ£ãããããªãã¾ãã ãªãªã¼ã¹ç´åã¾ã§ãã¹ããå 延ã°ãã«ãã¦ãããã¨ãé常ã«åé¡ã§ããã®ã¯ãã®ããã§ãã ãããªãã¨ãããã¨ããã¹ã¦ã®ã¨ã©ã¼ãçºè¦ããããã¨ãã§ããã çºè¦ããã¨ã©ã¼ãä¿®æ£ãããã¨ãé常ã«é£ãããªãã¾ããçµå±ã¯ã ããªã¢ã¼ã¸ãè¡ã£ã¦ã©ã®ã¨ã©ã¼ã«å¯¾å¿ããããå¤æããªããã°ãªããªããªãã¾ãã ãªããªããã¹ã¦ã®ã¨ã©ã¼ãå®å ¨ã«ä¿®æ£ãããã¨ã¯ä¸å¯è½ã ããã§ãã PHPUnit ã使ç¨ãããã¹ãã¯ãå ¨ä½ã¨ãã¦ã¯ããªããããã¾ã§ã«è¡ã£ã¦ãããã¨ã¨åãã§ãã ãã ããã®ããæ¹ãéãã ãã§ããããã¯ããã¹ã ã¤ã¾ãããªãã®ããã°ã©ã ãæå¾ éãã«ãµã
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}