PHPUnit 如何使用这些函数变量的值


How are the values of these function variables used by PHPUnit at all?

我正在使用Laravel 4.2,并在app/tests/TestCase.php文件中注意到了这个有趣的方法:

public function createApplication()
{
    $unitTesting = true;
    $testEnvironment = 'testing';
    return require __DIR__ . '/../../bootstrap/start.php';
}

$unitTesting$testEnvironment的作用域都限定在函数范围内,理论上,当函数完成时应该扔掉......但是,删除这些变量会导致 PHPUnit 中出现错误。

我试图弄清楚这些变量是如何使用的,无论是通过一些反射魔法还是其他什么......任何照明将不胜感激。

我认为变量在包含的文件中使用!

因为要知道require做什么!

举个例子:

文件1.php:

$foo = $unitTesting . $testEnvironment; 

文件2.php:

public function createApplication()
{
    $unitTesting = true;
    $testEnvironment = 'testing';
    return require "file1.php";
}

因此,如果要求完成,file2 如下所示:

public function createApplication()
{
    $unitTesting = true;
    $testEnvironment = 'testing';
    return $foo = $unitTesting . $testEnvironment;
}

因此,如您所见,该变量可以/几乎已在所需文件中使用