phpunit dbunit @dataProvider doesn#39;t work(phpunit dbunit @dataProvider 不起作用)
问题描述
我花了很多时间搜索问题出在哪里,但我没有找到任何东西.
I spent a lot of time by searching where is the problem, but i haven't find anything.
它是testAdd 导致错误:缺少参数".当我运行测试时,只是没有执行 dataProvider .我尝试将 die() 放入 dataProvider 并没有死.
It sais "testAdd caused an ERROR: Missing argument". Simply the dataProvider isn't executed, when I run the test. I tried to put die() into the dataProvider and it hasn't died.
这是我的代码:
class LabelEntityModelTest extends PHPUnit_Extensions_Database_TestCase
{
private static $connection = NULL;
/**
* @var CXNSDBConnectionsConnection
*/
private static $appConnection;
private static $table;
public function __construct()
{
if (self::$connection) {
return;
}
$pdo = new PDO($GLOBALS['DB_DSN'], $GLOBALS['DB_USER'], $GLOBALS['DB_PASSWD']);
self::$appConnection = new CXNSDBConnectionsConnection(array("prefix" => "test_", "driver" => "pdo", "resource" => $pdo));
self::$appConnection->connect();
self::$connection = $this->createDefaultDBConnection($pdo, 'mysql');
self::$table = $this->createXMLDataSet(__DIR__ . '/fixtures/tables.xml');
}
protected function getDataSet()
{
return self::$table;
}
public function getConnection()
{
return self::$connection;
}
public function getAppConnection()
{
return self::$appConnection;
}
/**
* @group onlyThis
* @dataProvider providerAdd
*/
public function testAdd($labelId, $entityId)
{
$lem = new appLibsLabelsLabelEntityModel($this->getAppConnection(), "contacts");
$lem->add($labelId, $entityId);
$count = $this->getAppConnection()
->select("id")
->from("label_relationships")
->where("label_id = %i", $labelId)
->where("table_ref_id = %i", $entityId)
->count();
$this->assertEquals(1, $count, "insert failed");
}
public function providerAdd()
{
return array(
array(2, 3),
array(3, 4),
array(3, 4),
array(3, 4),
array(3, 4),
array(3, 4),
array(5, 7)
);
}
}
感谢您的帮助.
推荐答案
永远不要覆盖 TestCase 构造函数.PhpUnit 有一个专门用于初始化的方法,称为 setUp
和 setUpBeforeClass
,所以我强烈建议你使用它.我很确定这是造成您问题的原因.
You should never overwrite TestCase constructor.
PhpUnit has a specialized methods for initialization purposes called setUp
and setUpBeforeClass
, so I strongly suggest you to use that.
I´m pretty sure this is the cause of your problem.
这篇关于phpunit dbunit @dataProvider 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:phpunit dbunit @dataProvider 不起作用
基础教程推荐
- 超薄框架REST服务两次获得输出 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01