我对我的 phpproject 有一些测试。我的测试:
class myTests extends PHPunit_Framework_Testcase{
    public function testValidateInventoryNumber(){
        include('includes/functions.php');
        $con = connectToDatabase();
        $resultTest1 = validateInventoryNumber("001234", $con);
        $this->assertEquals("001234", $resultTest1['data']);
    }
    public function testValidateLabel(){
        include('includes/functions.php');
        $resultTest1 = validateLabel("Sample Label.");
        $this->assertEquals("Sample Label.", $resultTest1['data']);
    }
}
Run Code Online (Sandbox Code Playgroud)
函数validateInventoryNumber()和validateLabel()是在 中声明的includes/functions.php,所以我需要在两个测试中都包含这个文件,对吗?
如果我想运行测试文件,我会收到以下错误:
Fatal error: Cannot redeclare connectToDatabase() (previously declared in C:\xampp\htdocs\prototype\includes\functions.php:4) in C:\xampp\htdocs\prototype\includes\functions.php on line 10
Run Code Online (Sandbox Code Playgroud)
我认为这与测试开始时的包含有关,因为如果我注释掉其中一个测试,它就会正常工作。知道如何修复它吗?
我正在尝试将数组导出到 CSV 文件中。我已经阅读了这个问题,现在可以下载 CSV。问题是,CSV 文件中还包含整个 html 文档,但我不知道它来自哪里。
该数组如下所示:
Array
(
    [0] => Array
        (
            [id] => 1
            [tphInventoryNumber] => D17001
            [title] => Assets in Leasing
            [price] => 1299.95
            [recievedDate] => 2017-11-02
            [departement] => 1
            [unit] => 1
        )
    [1] => Array
        (
            [id] => 2
            [tphInventoryNumber] => D17002
            [title] => Assets in Leasing
            [price] => 12.05
            [recievedDate] => 2017-10-31
            [departement] => 7
            [unit] => 3
        )
)
Run Code Online (Sandbox Code Playgroud)
我导出 CSV 的函数如下所示:
function exportToCSV($array, $filename = "export.csv", $delimiter = ";"){ …Run Code Online (Sandbox Code Playgroud) 我在许多使用 ldap 扩展的 PHP 脚本中看到了以下代码片段。我在网上搜索过,但没有找到有用的东西。
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
Run Code Online (Sandbox Code Playgroud)
我知道第一行将ldap协议版本设置为3。但是这个版本有什么好处呢?为什么需要它?
但我真的不知道第二行在做什么,有人可以给我解释一下吗?
我有一个充满psobjects的数组。现在,我想更改数组中每个对象的某些属性。
我的代码:
[array] $objectArray = $null
foreach ($row in $result) {
    $object = New-Object -TypeName PSObject
    $object | Add-Member -MemberType NoteProperty -Name "Classification" -Value $classification
    $object | Add-Member -MemberType NoteProperty -Name "Status" -Value $status
    $object | Add-Member -MemberType NoteProperty -Name "Priority" -Value $priority
    [array] $objectArray += $object
    Remove-Variable -Name object -ErrorAction SilentlyContinue
}
foreach ($co in $objectArray) {
    $oldStatus = $co.Status
    $oldPriority = $co.Priority
    $oldClassification = $co.Classification
    foreach ($uid in $resultUids.Tables[0]) {
        if ($oldStatus -eq $uid.status_i_d) {
            $co.Status = $uid.status_i_d …Run Code Online (Sandbox Code Playgroud)