åºç¤ãã¼ã ã«æå±ãã¦ãã @okinaka ã§ãã
å人çã«ã¯ CakePHP ã¨ã¯é·ãä»ãåãã§ããã14年以ä¸ã«ãªãã¾ãã BASE ã®äºæ¥ã«ããã¦ã10å¹´éãã£ã¨æ¯ãã¦ããã¦ãã大å¤ããããã Web ãã¬ã¼ã ã¯ã¼ã¯ã§ãã
以åãã BASE ã®å¤ãã®ã³ã¼ãã¯ã¾ã å¤ã CakePHP 2 (v2.10.24) ä¸ã§åä½ãã¦ãããã¨ã課é¡ã«ãªã£ã¦ãã¾ãã CakePHP èªèº«ã¯é 調ã«éçºãç¶ç¶ããã¦ãã¾ããã2ç³»ãã3ç³»ã¸ã®ãã¼ã¸ã§ã³ã¢ããã¯ãªããªãå°é£ã§äºã®è¶³ãè¸ãã§ãã¾ããã ãããããã¦ãããã¡ã«å¤ããã¼ã¸ã§ã³ã®2ç³»ã¯æ¢ã«å ¬å¼ã§ã®ãµãã¼ãã¯åãã¦ããããã« PHP 8.0 æªãµãã¼ãã®ç¶æ ã§ãã
ãããã«ãã®ã¾ã¾ç¶ç¶ãã¦å©ç¨ããã®ã¯ç¡çãããã®ã§ãæ°å¹´åãããããæè»ã«ã·ã¹ãã ãæ§ç¯ããããã®ã¢ã¼ããã¯ãã£åè¨è¨ããããã¦ãã¾ãã
ãã®ææã¯ä¸ãã£ã¦ãã¦ããã®ã§ãããåç´ãªãã¬ã¼ã ã¯ã¼ã¯ã®ãã¼ã¸ã§ã³ã¢ããã«ã¨ã©ã¾ãããæ ¹æ¬çãªã¢ã¼ããã¯ãã£ãåè¨è¨ãã¦ããã¨ãããªã®ã§ãå ¨ã¦ãå·æ°ãããã¾ã§ã«ã¯ãã¾ã ã¾ã æ¢åã®ä»çµã¿ãå©ç¨ãããã¨ãç¶ãããã§ãã(ã¢ã¼ããã¯ãã£ã®åè¨è¨ã«é¢ãã¦ã¯ããã©ãããã©ã¼ã ãã¼ã ãå¥ã®æ©ä¼ã§ç´¹ä»ãããã¨ã«ãªãã¨æãã¾ããï¼
ããã大å¤ãPHP 7.4 ã® EOL (2022-11-28) ãè¿ãã¦ãããå¾ã®ãªãç¶æ ããã®ã¾ã¾å ã«é²ãã«ã¯ PHP 8.0 以ä¸ã«ä¸ããå¿ è¦ã«è¿«ããã¦ãã¾ããã
PHP 8.0 ã§ãæå¤ã¨åãã
ããããããã¨ã«ãCakePHP 2 ãå ¬å¼ã®ãªãã¸ããªãããã©ã¼ã¯ã㦠PHP 8.0 対å¿ããã¦ããæ¹ããããã¨ã CakePHP ã® Slack ãã£ã³ãã«ã§ç¥ãã¾ããã
ã試ãã§ãã£ã¦ã¿ããããããªãåãã§ã¯ããã¾ãããï¼ãããï¼ã¨æã£ãã®ã§ãããä¸ã¤ã ãåé¡ãããã¾ããã ããã¯èªåãã¹ãã¯ãæªå¯¾å¿ãªã®ã§ããã
ã¨ãããã¨ã§ãPHP 8.0 ã§åä½ããããã«å¿ è¦ãª PHPUnit 9 対å¿ãç¬èªã«ãã£ã¦ã¿ããã§ããã¨ããå ±åã§ãã
PHPUnit 9 ã«å¯¾å¿ãã¦ã¿ã
åç½®ããé·ããªã£ã¦ãã¾ãã¾ããããæ¬é¡ã«å ¥ãã¾ãã
PHPUnit 9 㯠PHP 7.3 以ä¸ã«å¯¾å¿ãã¦ãã¾ãã®ã§ããããªã PHP 8.0 ã¾ã§ä¸ããå¿ è¦ã¯ããã¾ããã ä»åã¯å ¬å¼ã® CakePHP 2.10.24 (& PHP 7.4) ã®ã¾ã¾ã§ PHPUnit 9 ã«å¯¾å¿ãã¦ã¿ã¾ãã
大ããªè¦ç¹ã¯2ç¹ããã¾ãã
- CakeTestCase ã ControllerTest ãç¶æ¿ããªã (ãããã¯å·®ãæ¿ãã)
cake test
ã使ããã«ç´æ¥ PHPUnit ãå®è¡ãã
ä»ã«ãç´°ããªãã¤ã³ãã¯ããããããã®ã§ãããããã«é·ããªããããªã®ã§ä»¥ä¸ã§çãã¦ããã¾ãã
CakeTestCase ã ControllerTest ãç¶æ¿ããªã (ãããã¯å·®ãæ¿ãã)
ã¨ã¦ãæ®å¿µãªãã¨ã§ãããPHPUnit ã®ãã¼ã¸ã§ã³ã¢ãã(phpunit>=8.0)ã«ä¼´ãå¾æ¹äºææ§ã®ãªãå¤æ´ããã£ããããCakeTestCase ã ControllerTest ãç¶æ¿ãã¦ãã¹ããæ¸ããã¨ã¯ã§ããªããªãã¾ããã
TestCase ã® setUp()
ã tearDown()
ãªã©ã®ã¡ã½ããã®æ»ãå¤ã«å宣è¨ã追å ãããããã§ãã
ããã°ããã¯ããã¬ã¼ã¯ã¯ã¼ã¯å´ãä¿®æ£ãããããªãã®ã§ãå¿æ¥æªç½®ã¨ã㦠CakeTestCase ãã³ãã¼ããã¯ã©ã¹ãç¨æãã¾ããã
åå空éããªããç¬èªã®ã¯ã©ã¹ãã¼ãã¼ãå©ç¨ãã¦ããã¡ãªãããæ´»ãããapp/TestSuite/CakeTestCase.php
ãé
ç½®ãããã¨ã§ãApp::uses('CakeTestCase', 'TestSuite');
ã¨æ¸ããã¦ããã¨ããªãªã¸ãã«ã§ã¯ãªãã³ãã¼ã®æ¹ãèªã¿è¾¼ã¾ãã¾ãã
対å¿ä¾ã¯ãã¡ãã
ç´æ¥ PHPUnit ãå®è¡ãã
CakePHP 2 ã§ã¯ãcake test
ã¨ããã³ãã³ããç¨æããã¦ãã¦ãå
é¨ã§ã¯ PHPUnit ãåããã¦ãã¾ãã å¤ãPHPUnit åãã®ãã¸ãã¯ãæ¸ããã¦ãããããããã使ããã¨ãé¿ã㦠PHPUnit ãç´æ¥å®è¡ãã¾ãã
å¼ç¤¾ã§ã¯ããã¼ã¸ã§ã³ã¢ãã以åãã PhpStorm ãªã©ã® IDE ã®æ¯æ´ãåããããã« PHPUnit ãç´æ¥å©ç¨ãããã¨ããçç±ã§å¯¾å¿ãã¦ã¾ããã ãã®ããã®å¯¾å¿æ¹æ³ã¯ GitHub ã® issue ã«å¼ç¤¾ã® tenkoma ãããç´¹ä»ãã¦ãã¾ãã®ã§åèã«ãªãã¾ãã
ãã¹ãã³ãã³ãèµ·åæã®ãã¾ããªãå°ã ã¨ãã£ã¯ã¹ãã£å¨ãã®ãã¸ãã¯ã®è¿½å ãå¿ è¦ã§ããã
ãªããCakePHP 2 ã«ã¯ web ä¸ãããã¹ããå®è¡ããæ©è½ãããã®ã§ããããã®æ©è½ã¯åãæ¨ã¦ããã¨ã«ãªãã¾ãã(IDE ã CI ã§ãã¹ãããåã«ã¯ä¸è¦ãªã®ã§ãªãã¦ãå°ããªãã¨æãã¾ãã)
対å¿ä¾ã¯ãã¡ãã
ãµã³ãã«
ä»åã®ããã°ã®ããã«ãCakePHP 2 㧠PHPUnit 9 ãåãããµã³ãã«ãä½æãã¦ã¿ã¾ããã CakeTestCase ã®ããã®ãã¹ãã±ã¼ã¹ (CakeTestCaseTest) ãç¨æãã¾ãããGitHub Actions ã® workflow ã使ã£ã¦èªåãã¹ãã«ã対å¿ãã¦ãã¾ãã
ãããã«
æ¬æ¥ããã¬ã¼ã¯ã¯ã¼ã¯ã¯å¸¸ã«ææ°ãã¼ã¸ã§ã³ã使ããã¨ã好ã¾ãããã¨ãªã®ã§ãããèªåãã¹ããããã°ãå¤ããã¼ã¸ã§ã³ã使ã£ã¦ãã¦ãå®å¿ã§ããã¨æãã¾ãã (ããã¾ã§ç§»è¡å®äºã¾ã§ã®ä¸ç¶ãã¨ãã¦ã§ãã)
ãã®è¨äºã§ãCakePHP ã®ãã¼ã¸ã§ã³ã¢ãããã§ããã«å¤ããã¼ã¸ã§ã³ã延å½ããããã©ããè¿·ã£ã¦ããæ¹ã«åèã«ãªãã°å¹¸ãã§ãã