私はphpunitテストを書いています。クラスが見つかりませんphpunit
C:\Program Files (x86)\Ampps\www\phpunit.dev\vendor\bin>phpunit -c ../../phpunit.xml
しかし、このエラーに終わる:私はこれらの質問からいくつかのソリューションを試してみました
PHP Fatal error: Class 'Acme\SumFinder' not found in C:\Program Files (x86)\Ampps\www\phpunit.dev\tests\AcmeTests\SumFinderTest.php on line 15
:
- Class 'sample\question2\Hello' not found with composer and phpunit を私は、次のコマンドを使用して、それを実行しました
- Autoloading classes in PHPUnit using Composer and autoload.php
ただし、何も機能しません。何が問題なのか、どうすれば解決できるのでしょうか?ありがとう!
私のディレクトリ構造:
- phpunit.dev/src/Acme/SumFinder.php
- phpunit.dev/tests/AcmeTests/SumFinderTest.php
- phpunit.dev/composer.json このように書か
- phpunit.dev/phpunit.xml
マイcomposer.json:
{
"require-dev": {
"phpunit/phpunit": "3.7.*"
},
"autoload": {
"psr-4": {
"Acme\\": "./src/"
}
},
"autoload-dev": {
"psr-4": {
"AcmeTests\\": "./tests/"
}
}
}
次のように書かれた私のアクメ\ SumFinder.php:
<?php
namespace Acme;
class SumFinder {
private $inputArray;
function __construct($inputArray = null) { ... }
function findSum() { ... }
function compareArrays() { ... }
}
?>
マイAcmeTests \ SumFinderTest.php:
<?php
namespace AcmeTests;
use Acme\SumFinder;
class SumFinderTest extends \PHPUnit_Framework_TestCase
function testFindSum() { ... }
function testCompareArrays() { ... }
?>
マイphpunit.xml設定ファイル:
<?xml version="1.0" encoding="utf-8" ?>
<phpunit colors="true" bootstrap="./vendor/autoload.php">
<testsuites>
<testsuite name="First Test">
<directory>./tests</directory>
</testsuite>
</testsuites>
問題を解決するのに役立つなら、私はWindows 10とAMPPSスタックを使用しています。
cmdまたはpowershell 'composer -o dump-autoload'でこのコマンドを実行してみてください – McStuffins
これは機能します!ありがとう!しかし、なぜそれが動作し、 'コンポーザーのダンプ自動ロード'がうまくいかないのだろうか? @mcstuffins –
これはうまくいきました。 '-o'をやりましたか?作曲家のファイルを最適化するだけです。私はそれがうまくいくことがうれしいです。この問題が発生したときのほとんどの時間は、作曲家とそれが自動ロードする方法のためです。 – McStuffins