Q&A
すでに稼動しているCakePHP2で、テストコードを実行することになったため、PHPUnit を入れましたが正常に動作しません。
もしよければアドバイスいただけると嬉しいです。
1. 環境
- SentOS 7
- PHP 5.5
- CakePHP2.2
- ドキュメントルートが/var/www/public_html/hoge/
2. PHPunitをインストールした手順
(1) 以下のCakePHPのページを参考にcomposerでインストールしました。
※composer.pharはドキュメントルートにDL後、下記ページ記載のコマンドを実行
https://book.cakephp.org/2/ja/development/testing.html#composer
php composer.phar require --dev phpunit/phpunit:"3.7.38"
(2) テストコードを以下の階層に作成
/var/www/public_html/hoge/fuge/Test/Case/Model/SampleTest.php
※「fuge」の部分は本来CakePHPの「app」に該当します。理由があってディレクトリ名を「fuge」に変更しています。
※/var/www/public_html/hoge/fuge/Model/Sample.phpがあることは確認済み
※テストコードはひとまず実行確認ができればと思ったので以下のように記載しました。
App::uses('Sample', 'Model'); class SampleTest extends CakeTestCase { public function testBase { $str = null; $this->assertNull($str); } }
(3) fugeの階層に移動しテストコードを実行するとエラーになる
※テストコード実行
./Console/cake test app Model/SampleTest
※エラー
Warning Error: include(PHPUnit/Autoload.php): failed to open stream: No such file or directory in [/var/www/public_html/hoge/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php, line 146] 2022-05-10 21:32:30 Warning: 3042 - - include(PHPUnit/Autoload.php): failed to open stream: No such file or directory in [/var/www/public_html/hoge/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php, line 146] Warning Error: include(): Failed opening 'PHPUnit/Autoload.php' for inclusion (include_path='/var/www/public_html/hoge/lib:/usr/local/bin') in [/var/www/public_html/hoge/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php, line 146] 2022-05-10 21:32:30 Warning: 3042 - - include(): Failed opening 'PHPUnit/Autoload.php' for inclusion (include_path='/var/www/public_html/hoge/lib:/usr/local/bin') in [/var/www/public_html/hoge/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php, line 146] Error: Please install PHPUnit framework v3.7 (http://www.phpunit.de) #0 /var/www/public_html/hoge/lib/Cake/Console/ShellDispatcher.php(206): TestShell->initialize() #1 /var/www/public_html/hoge/lib/Cake/Console/ShellDispatcher.php(66): ShellDispatcher->dispatch() #2 /var/www/public_html/hoge/fuge/Console/cake.php(35): ShellDispatcher::run(Array) #3 {main}
(4)以下参考にしてbootstrap.phpの一番上にパスを記載
https://qiita.com/tkj/items/7b480672f55ecad5d36b
<?php require '/var/www/public_html/hoge/vendor/autoload.php'; /**
(5) モジュールをインストール
yum install --enablerepo=remi-php55 php-xml
(6) テストコードを実行。コマンドは通ったように見えるがエラーとなっている
Welcome to CakePHP v2.4.10 Console --------------------------------------------------------------- App : fuge Path: /var/www/public_html/hoge/huge/ --------------------------------------------------------------- CakePHP Test Shell --------------------------------------------------------------- Argument #2 of PHPUnit_TextUI_ResultPrinter::__construct() must be a boolean
この「PHPUnit_TextUI_ResultPrinter::__construct() must be a boolean」が永遠に解決できず、原因が全然分かりません…
何かアドバイスがあれば、よろしくお願いします。
ーーーーーーーーーーーーー
2022年5月15日 追記
ーーーーーーーーーーーーー
PHPUnit側のソースを修正して通過するようにしたところ、今度はSegmentation faultとなり、PHPUnitを実行したら落ちるようになってしまいました。
こちらの原因が特定できず困っていたところ、gdbでログを取得し、そこから落ちている箇所を特定できるかもしれないとありましたので実行してみましたが、なぜかコアファイルが作成されません。
以下サイトを参考にしながらgdbを設定しました。
https://sarface2012.hatenablog.com/entry/20101027
1. gdbをインストール
sudo yum install gdb
2. /etc/profileに以下を記載し、core file sizeをunlimitedに設定
ulimit -c unlimited > /dev/null 2>&1
3. /etc/httpd/conf/httpd.confに以下を記載
CoreDumpDirectory /tmp
4. サーバー再起動
5. エラーを発生させる
しかし、なぜか/tmpにcore.xxxxというようなコアファイルが生成されませんでした。
以下のメッセージが出力されるのですが、もしよければアドバイスいただけないでしょうか。。。よろしくお願いいたします。
[core:notice] [pid 4194] AH00052: child pid 4197 exit signal Segmentation fault (11) [core:notice] [pid 4194] AH00052: child pid 4198 exit signal Segmentation fault (11) [core:notice] [pid 4194] AH00052: child pid 4199 exit signal Segmentation fault (11) [core:notice] [pid 966] core dump file size limit raised to 18446744073709551615 bytes [suexec:notice] [pid 966] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) [so:warn] [pid 966] AH01574: module rewrite_module is already loaded, skipping AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress t his message [lbmethod_heartbeat:notice] [pid 966] AH02282: No slotmem from mod_heartmonitor [mpm_prefork:notice] [pid 966] AH00163: Apache/2.4.6 (CentOS) PHP/5.5.38 configured -- resuming normal operations [core:notice] [pid 966] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。