In the below test we (the humbly well my I am) need to make sure that $utmSource
class field received correct value.
<?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;
}
}
Off course, this test will not pass, because $response
and $topPageController
are independent, so $utmSource
will be null
. How we can relate $response
and $topPageController
?