【发布时间】:2021-04-07 21:15:32
【问题描述】:
我是 PHPUnit 和一般单元测试的新手。我似乎找不到关于如何最好地进行测试的明确教程或资源:
- 不传递参数失败。
- 如何为构造函数测试传递参数。
- 传递空参数会导致预期的异常。
我将如何测试这个构造函数?
<?php
class SiteManagement {
public function __construct (array $config) {
// Make sure we actually passed a config
if (empty($config)) {
throw new \Exception('Configuration not valid', 100);
}
// Sanity check the site list
if (empty($config['siteList'])) {
throw new \Exception('Site list not set', 101);
}
}
}
【问题讨论】:
-
新站点管理($configarray);
标签: php unit-testing phpunit