0

在下面的测试中,我们(我的谦虚)需要确保$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

4

0 回答 0