有没有办法为Eclipse PDT添加自定义phpdoc注释?例如,我想@depends在自动完成列表中看到(对于PHPUnit)注释,但现在我只能看到标准注释(例如@deprecated).
提前致谢.
我使用PHPUnit和Selenium Server来测试Yii应用程序,即时通讯使用xp操作系统.我安装PHPUnit_Selenium(1.0.1)和其他软件.实际上我遵循这个bellow指令安装http://www.yiiframework.com/forum/index.php?/topic/14995-wamp-netbeans-phpunit-selenium-警予/
我还下载了selenium-server-standalone-2.20.0.jar文件并通过命令提示我使用java -jar selenium-server-standalone-2.0b3.jar命令启动服务器..
之后我打开了新的命令提示符,我试着测试我简单的hello world yii应用程序.我调用了这个命令phpunit functional/SiteTest.php和ya我也在webtestcase中设置了Test_Base_URL ..
但是在调用上面的命令进行测试之后..一些进程正在进行,2到3次firefox自动打开和关闭,最后我得到了这个错误"@ php_bin @"被识别为内部或外部命令,可操作程序或批处理文件
即使我附上cmd提示的屏幕截图... http://s14.postimage.org/o057x7wox/1cmd.jpg
我正在为一些项目使用Zend Framework,并希望为它们构建PHPUnit测试套件.不幸的是,Zend Framework中的当前版本(1.11.x)仅支持PHPUnit 3.5.同时,我还想开始使用Symfony框架,而Symfony框架又支持更新版本的PHPUnit.那么问题是,如何在我的开发机器上同时运行多个版本的PHPUnit而无需安装单独的服务器或类似的东西?
我正在运行OS X Lion(10.7)并使用通过MacPorts安装的apache和php(5.3.10).理想情况下,我想最终在一种情况下我可以在终端中输入例如phpunit5来执行3.5版本并键入phpunit6来执行3.6版本,依此类推.
对于C#,有一种方法可以编写一个语句来等待页面上的元素出现:
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement myDynamicElement = wait.Until<IWebElement>((d) =>
{
return d.FindElement(By.Id("someDynamicElement"));
});
Run Code Online (Sandbox Code Playgroud)
但有没有办法在phpunit的selenium扩展中做同样的事情?
我发现的唯一的事情是$this->timeouts()->implicitWait(),但显然它不是我想要的.
这个问题是关于Selenium2和PHPUnit_Selenium2相应的扩展.
我想使用PHPUnit来测试以正确的顺序调用方法.
我->at()在模拟对象上使用的第一次尝试不起作用.例如,我预计以下内容会失败,但它不会:
public function test_at_constraint()
{
$x = $this->getMock('FirstSecond', array('first', 'second'));
$x->expects($this->at(0))->method('first');
$x->expects($this->at(1))->method('second');
$x->second();
$x->first();
}
Run Code Online (Sandbox Code Playgroud)
如果以错误的顺序调用事件,我能想到的唯一方法就是强制失败是这样的:
public function test_at_constraint_with_exception()
{
$x = $this->getMock('FirstSecond', array('first', 'second'));
$x->expects($this->at(0))->method('first');
$x->expects($this->at(1))->method('first')
->will($this->throwException(new Exception("called at wrong index")));
$x->expects($this->at(1))->method('second');
$x->expects($this->at(0))->method('second')
->will($this->throwException(new Exception("called at wrong index")));
$x->second();
$x->first();
}
Run Code Online (Sandbox Code Playgroud)
有没有更优雅的方式来做到这一点?谢谢!
我正在使用phpunit编写一些单元测试,现在我想断言一个数组包含一个特定的值,但我能找到的唯一函数是assertArrayHasKey().没有任何assertArrayHasValue.
所以要明确我想要这样的东西:
$a = [5, 8, 16];
assertArrayHasValue(8, $a);
Run Code Online (Sandbox Code Playgroud)
欢迎所有提示!
我在我的Mac上安装了多个PHP版本,并希望针对特定的PHP版本(或针对多个版本)运行单元测试
这是我的php版本:
$ php --version
Output: PHP 5.4.23 ...
$ /Applications/MAMP/bin/php/php5.2.17/bin/php --version
Output: PHP 5.2.17 ...
Run Code Online (Sandbox Code Playgroud)
我的测试用例如下:
function test_php_version() {
$actual = phpversion();
$expected = '5.2.17';
$this->assertEquals( $expected, $actual, 'Wrong PHP version!' );
}
Run Code Online (Sandbox Code Playgroud)
当我运行测试时,我收到了这个回复:
$ phpunit
Wrong PHP version!
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'5.2.17'
+'5.4.24'
$ /Applications/MAMP/bin/php/php5.2.17/bin/php phpunit
Error: Could not open input file: phpunit
Run Code Online (Sandbox Code Playgroud)
如何使用php 5.2.7版运行测试?
更新:
我发现PHPUnit不再运行php5.2.17了.所以我改变了我的要求,用php5.3.5运行单元测试,这是支持的.
我正在尝试模拟一个链(嵌套)方法来返回所需的值,这是代码:
public function __construct($db)
{
$this->db = $db;
}
public function getResults()
{
return $this->db->getFinder()->find($this->DBTable);
}
Run Code Online (Sandbox Code Playgroud)
我试过这个模拟,但它不起作用:
$dbMock = $this->createMock(DB::class);
$dbMock = $dbMock
->expects(self::any())
->method('getFinder')
->method('find')
->with('questions')
->will($this->returnValue('7'));
Run Code Online (Sandbox Code Playgroud)
任何解决方案如何解决这样的问题?
谢谢 .
我有一个Laravel 5.3应用程序.
在我的api.php文件中,有一条在投票中发布答案的路线.
Route::group(['middleware' => 'auth:api'], function () {
Route::post('/poll/answer', 'API\PollsController@createAnswer');
});
该路由是由auth:api中间件限制的组的一部分,使用Laravel的Passport引擎.
当从Postman或任何其他工具调用此路由来测试API时,我得到401,这是好的,因为我没有附加令牌.
但是当使用PHPUnit对该调用进行单元测试时,它返回500.我不知道为什么.
$this->postJson('api/poll/answer');
我可能错过了配置或设置指令.
有任何想法吗?
我按照站点使用一次性数据库教程测试Symfony应用程序.我在我的测试用例中添加了Fixtures,并且在SetUp期间没有出现错误.如果我在灯具中添加一个错误(例如,将一个nullable = false字段留空),则会显示错误,因此该代码肯定会被执行.
我的配置:
doctrine:
dbal:
default_connection: memory
connections:
memory:
driver: pdo_sqlite
memory: true
charset: UTF8
Run Code Online (Sandbox Code Playgroud)
我的WebTestCase中的SetUp:
protected function setUp() {
parent::setUp();
self::bootKernel();
DatabasePrimer::prime(self::$kernel);
$this->loadFixtures([
'AppBundle\DataFixtures\ORM\UserData',
'AppBundle\DataFixtures\ORM\ArtistData'
]);
}
Run Code Online (Sandbox Code Playgroud)
然而,在我的WebTestCase中,似乎没有表存在.输出抛出一个Doctrine异常,说我的表不存在.
SQLSTATE[HY000]: General error: 1 no such table: my_user_table
Run Code Online (Sandbox Code Playgroud)
如果我在文件中切换到sql_lite,一切正常,没有任何其他更改:
dbal:
default_connection: file
connections:
file:
driver: pdo_sqlite
path: %kernel.cache_dir%/test.db
charset: UTF8
Run Code Online (Sandbox Code Playgroud)
任何人都有成功的说教程或使用sqlite内存数据库进行单元测试,并有任何提示或想法?
更新: 我将我的安装程序更改为此以确保内核不会在其间关闭.它没有帮助:
parent::setUp();
$this->client = $this->getClient();
MemoryDbPrimer::prime(self::$kernel);
$this->loadFixtures([
'AppBundle\DataFixtures\ORM\UserData',
'AppBundle\DataFixtures\ORM\ArtistData'
]);
Run Code Online (Sandbox Code Playgroud)