gpt4 book ai didi

PHPUnit:数据提供者问题

转载 作者:可可西里 更新时间:2023-10-31 23:52:30 29 4
gpt4 key购买 nike

以下测试有什么问题:

<?php

class TestSomething extends PHPUnit_Framework_TestCase
{
/**
* @dataProvider provider
*/
public function testSomething($array, $expectedResult)
{
$this->assertEquals($array, $expectedResult);
}

public function provider()
{
return array(
array(array(), array()),
);
}
}

?>

错误信息:

$phpunit index.php
PHP Warning: Missing argument 1 for TestSomething::testSomething() in /var/www/tests/something-test/index.php on line 8
PHP Warning: Missing argument 2 for TestSomething::testSomething() in /var/www/tests/something-test/index.php on line 8
PHP Notice: Undefined variable: array in /var/www/tests/something-test/index.php on line 11
PHP Notice: Undefined variable: expectedResult in /var/www/tests/something-test/index.php on line 11
PHP Fatal error: Uncaught exception 'PHPUnit_Framework_ExpectationFailedException' with message 'Failed asserting that
Array
(
[0] => Array
(
)

[1] => Array
(
)

)
is equal to <string:testSomething>.' in /usr/share/php/PHPUnit/Framework/Constraint/IsEqual.php:164
Stack trace:
#0 /usr/share/php/PHPUnit/Framework/Assert.php(2087): PHPUnit_Framework_Constraint_IsEqual->fail(Array, '')
#1 /usr/share/php/PHPUnit/Framework/Assert.php(343): PHPUnit_Framework_Assert::assertThat(Array, Object(PHPUnit_Framework_Constraint_IsEqual), '')
#2 /var/www/tests/something-test/index.php(11): PHPUnit_Framework_Assert::assertEquals('testSomething', Array)
#3 /usr/share/php/PHPUnit/Framework/TestSuite.php(537): TestSomething->testSomething('testSomething', Array, 0)
#4 /usr/share/php/PHPUnit/Framework/TestSuite.php(816): PHPUnit_Framework_TestSuite::createTest(Object(ReflectionClass), 'testSomething')
#5 /usr/share/php/PHPUnit/Framework/TestSuite.php(224): PHPUnit_Framework_TestSuite->addTestMethod(Object(ReflectionClass), Object(Reflectio in /usr/share/php/PHPUnit/Framework/Constraint/IsEqual.php on line 164

谢谢。

最佳答案

我也遇到了同样的事情,我正在使用 __construct() 方法来设置内部变量。

我需要做的是有一个 function setUp() {} 会发生这种情况。


我刚刚再次遇到这个问题 - 但这次的问题是评论 - 我曾经使用过:

/*
* @dataProvider ....
*/

但是注释必须以/**开头才能被识别。

关于PHPUnit:数据提供者问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6960169/

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