【问题标题】:Tenant Multi tenancy Laravel Unit Testing issue租户多租户 Laravel 单元测试问题
【发布时间】:2021-07-04 08:09:30
【问题描述】:

这是我为类别测试创建的测试用例。当我正确配置租户测试用例并且此路由存在于在 chrome 浏览器上创建的子域上时,我在此路由上得到 404。

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 响应意味着重定向到登录代码。

【问题讨论】:

    标签: php laravel multi-tenant multi-database


    【解决方案1】:

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

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

        tenancy()->initialize($tenant);
        URL::forceRootUrl('http://' . $tenant->domains[0]['domain']);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-07
      • 1970-01-01
      • 2020-11-27
      • 2020-01-11
      • 1970-01-01
      • 2019-09-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多