1

这是我为类别测试创建的测试用例。我在这条路线上得到 404,而我已经正确配置了租户测试用例,并且这条路线存在于在 chrome 浏览器上创建的子域上。

public function test_example()
{
    $response = $this->call('GET', '/categories/6/edit');
    $this->assertEquals(200, $response->getStatusCode(),$response->exception->getMessage());
}

我的TestCase.php

  protected $tenancy = false;

public function setUp(): void
{
    parent::setUp();
    if ($this->tenancy) {
        $this->initializeTenancy();
    }
}

public function initializeTenancy()
{
    $tenant = Tenant::create();
    tenancy()->initialize($tenant);
}

我正在关注的文档 https://tenancyforlaravel.com/docs/v3/testing

结果:我想要 302 响应意味着重定向到登录代码。

4

1 回答 1

0

我希望这段代码可以帮助你

https://github.com/archtechx/tenancy/issues/635#issuecomment-939226522

    tenancy()->initialize($tenant);
    URL::forceRootUrl('http://' . $tenant->domains[0]['domain']);
于 2021-11-15T15:27:01.733 回答