gpt4 book ai didi

PHPUnit 找不到 Framework.php

转载 作者:行者123 更新时间:2023-12-02 12:19:37 24 4
gpt4 key购买 nike

现在已经两天了,我一直在尝试让 phpunit 在我的 OSX 上运行。我正在从 MAMP 安装运行 php。

我已经通过 PEAR 安装了它以及所有依赖项。phpunit --version 命令正在运行并显示:

$ phpunit --version
PHPUnit 3.6.10 by Sebastian Bergmann.

但是当我从命令行运行测试时,它显示:

Warning: require_once(/Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/Framework): failed to open stream: No such file or directory in /Users/magalie/Sites/HelloWorld/HelloWorldTest.php on line 3

Call Stack:
0.0028 632128 1. {main}() /Applications/MAMP/bin/php/php5.3.6/bin/phpunit:0
0.0078 1161288 2. PHPUnit_TextUI_Command::main() /Applications/MAMP/bin/php/php5.3.6/bin/phpunit:46
0.0078 1162016 3. PHPUnit_TextUI_Command->run() /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/TextUI/Command.php:130
0.1109 1793352 4. PHPUnit_Runner_BaseTestRunner->getTest() /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/TextUI/Command.php:150
0.1109 1793352 5. PHPUnit_Runner_BaseTestRunner->loadSuiteClass() /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/Runner/BaseTestRunner.php:104
0.1115 1837832 6. PHPUnit_Runner_StandardTestSuiteLoader->load() /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/Runner/BaseTestRunner.php:168
0.1126 1983864 7. PHPUnit_Util_Fileloader::checkAndLoad() /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/Runner/StandardTestSuiteLoader.php:78
0.1127 1983984 8. PHPUnit_Util_Fileloader::load() /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/Util/Fileloader.php:79
0.1128 1994704 9. include_once('/Users/magalie/Sites/HelloWorld/HelloWorldTest.php') /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/Util/Fileloader.php:95


Fatal error: require_once(): Failed opening required 'PHPUnit/Framework' (include_path='.:/Applications/MAMP/bin/php/php5.3.6/lib/php:/Applications/MAMP/bin/php5.3/lib/php/PEAR:/usr/lib/php') in /Users/magalie/Sites/HelloWorld/HelloWorldTest.php on line 3

Call Stack:
0.0028 632128 1. {main}() /Applications/MAMP/bin/php/php5.3.6/bin/phpunit:0
0.0078 1161288 2. PHPUnit_TextUI_Command::main() /Applications/MAMP/bin/php/php5.3.6/bin/phpunit:46
0.0078 1162016 3. PHPUnit_TextUI_Command->run() /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/TextUI/Command.php:130
0.1109 1793352 4. PHPUnit_Runner_BaseTestRunner->getTest() /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/TextUI/Command.php:150
0.1109 1793352 5. PHPUnit_Runner_BaseTestRunner->loadSuiteClass() /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/Runner/BaseTestRunner.php:104
0.1115 1837832 6. PHPUnit_Runner_StandardTestSuiteLoader->load() /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/Runner/BaseTestRunner.php:168
0.1126 1983864 7. PHPUnit_Util_Fileloader::checkAndLoad() /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/Runner/StandardTestSuiteLoader.php:78
0.1127 1983984 8. PHPUnit_Util_Fileloader::load() /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/Util/Fileloader.php:79
0.1128 1994704 9. include_once('/Users/magalie/Sites/HelloWorld/HelloWorldTest.php') /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/Util/Fileloader.php:95

这是 pear 的配置

Configuration (channel pear.php.net):
=====================================
Auto-discover new Channels auto_discover 1
Default Channel default_channel pear.php.net
HTTP Proxy Server Address http_proxy <not set>
PEAR server [DEPRECATED] master_server pear.php.net
Default Channel Mirror preferred_mirror pear.php.net
Remote Configuration File remote_config <not set>
PEAR executables directory bin_dir /Applications/MAMP/bin/php/php5.3.6/bin
PEAR documentation directory doc_dir /Applications/MAMP/bin/php/php5.3.6/lib/php/doc
PHP extension directory ext_dir /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions
PEAR directory php_dir /Applications/MAMP/bin/php/php5.3.6/lib/php/
PEAR Installer cache directory cache_dir /var/folders/qH/qHdMKNY5GsywPNMBPX-T7U+++TI/-Tmp-//pear/cache
PEAR configuration file cfg_dir /Applications/MAMP/bin/php/php5.3.6/lib/php/cfg
directory
PEAR data directory data_dir /Applications/MAMP/bin/php/php5.3.6/lib/php/data
PEAR Installer download download_dir /var/folders/qH/qHdMKNY5GsywPNMBPX-T7U+++TI/-Tmp-//pear/download
directory
PHP CLI/CGI binary php_bin /Applications/MAMP/bin/php/php5.3.6/bin/php
php.ini location php_ini /Applications/MAMP/bin/php/php5.3.6/conf/php.ini
--program-prefix passed to php_prefix <not set>
PHP's ./configure
--program-suffix passed to php_suffix <not set>
PHP's ./configure
PEAR Installer temp directory temp_dir /var/folders/qH/qHdMKNY5GsywPNMBPX-T7U+++TI/-Tmp-//pear/temp
PEAR test directory test_dir /Applications/MAMP/bin/php/php5.3.6/lib/php/tests
PEAR www files directory www_dir /Applications/MAMP/bin/php/php5.3.6/lib/php/www
Cache TimeToLive cache_ttl 3600
Preferred Package State preferred_state stable
Unix file mask umask 22
Debug Log Level verbose 1
PEAR password (for password <not set>
maintainers)
Signature Handling Program sig_bin /usr/local/bin/gpg
Signature Key Directory sig_keydir /Applications/MAMP/bin/php/php5.3.6/pearkeys
Signature Key Id sig_keyid <not set>
Package Signature Type sig_type gpg
PEAR username (for username <not set>
maintainers)
User Configuration File Filename /Users/magalie/.pearrc
System Configuration File Filename /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf

并且 phpunit 从/usr/lib/php 运行,它是 $PATH 的一部分

这是我的 HElloWorldTest.php 文件的内容,我已经尝试过使用或不使用 Framework 文件的 php 扩展名,但没有成功。

<?php
require_once 'HelloWorld.php';
require_once 'PHPUnit/Framework';
///Applications/MAMP/bin/php/php5.3.6/lib/php/

class HelloWorldTest extends PHPUnit_Framework_TestCase
{
public function test__construct()
{
$hw = new HelloWorld();
$this->assertType('HelloWorld, $hw');
}

public function testSayHello()
{
$hw = new HelloWorld();
$string = $hw->sayHello();
$this->asserEquals('Hello World!', $string);
}
}

我已经尝试卸载并重新安装 phpunit,但没有成功。并且查看PHPUnit目录,没有Framework.php文件。

那么我做错了什么?有人有同样的问题吗?你是怎么解决的?这让我发疯,我有一种在原地打转的感觉......

感谢您的帮助。

最佳答案

您不需要在测试中加载 PHPUnit。 phpunit 可执行文件负责设置自己的自动加载器。删除这一行:

require_once 'PHPUnit/Framework';

关于PHPUnit 找不到 Framework.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9217353/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com