在下面的测试中,我们(非常谦卑)需要确保$utmSource
类字段收到正确的值。
<?php
class ExampleTest extends TestCase {
public function testHttpRequestAndControllerCoordination() {
$response = $this->call('GET', '/')->json([utm_source => 'Google']);
$topPageController = new TopPageController();
$topPageController->renderTopPage();
$this->assertAttributeSame('Google', 'utm_source', $topPageController);
}
}
class TopPageController extends Controller {
private $utmSource;
public function renderTopPage(){
$this->utmSource = request()->utm_source;
}
}
当然,该测试不会通过,因为$response
和$topPageController
是独立的,所以$utmSource
将是null
。我们如何关联$response
和$topPageController
?