2015-04-24 13:57
浏览 102

使用Behat / Mink和Behat Laravel Extension测试多租户Laravel应用程序

I am building a multi-tenant SaaS application which I am trying to write tests for with Behat, using Mink and the Behat Laravel Extension

When you register for an account, you get your own subdomain on the site {account}.tenancy.dev

my behat.yml file looks like so:

            # env_path: .env.behat
            default_session: laravel
            base_url: http://tenancy.dev
            laravel: ~

I am having problems straight off the bat as when I try to test my registration flow, I am getting a 404 error testing that the new subdomain is accessible, all of the data has been saved correctly, manually testing the process works and the subdomain routing works.

I was wondering if there was any way to do this using Behat and how I would go about setting Behat / Mink to use wildcard subdomains to test SaaS applications?

I am running the test inside the Homestead VM.

图片转代码服务由CSDN问答提供 功能建议

我正在构建一个多租户SaaS应用程序,我正在尝试使用Mink编写测试,使用Mink和 Behat Laravel Extension

当您注册时 帐户,您在网站上获得自己的子域 {account} .tenancy.dev

我的 behat.yml 文件看起来像这样 :

 Laracasts \ Behat:
 Behat \ MinkExtension:
 base_url  :http://tenancy.dev 

我直接遇到问题,因为当我尝试测试我的注册流程时,我是 得到404错误测试可以访问新子域,所有数据都已正确保存,手动测试过程工作和子域路由工作。

我想知道是否 有什么办法可以使用Behat以及我如何设置Behat / Mink使用通配符子域来测试SaaS应用程序?

我在Homestead VM中运行测试。< / p>

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • duanjue7508 2015-08-01 00:43

    After a short while I revisited this problem and found a rather simple solution to be used in my FeatureContext.php:

    $this->setMinkParameter('base_url', $url);

    This changes the base url for any scenario it is used in:

     * @Given I visit the url :url
    public function visitDomain($url)
        $this->setMinkParameter('base_url', $url);

    Which is used in the following way:

    Scenario: Test Multi Tenancy
      Given I have a business "mttest"
      When I visit the url "http://mttest.example.com"
      Then I should see "mttest"

    Obviously this is slightly contrived but does show that what I was intending to do is possible.

    解决 无用
    打赏 举报
  • dqq22391 2015-04-27 23:07

    The base_url: http://tenancy.dev configuration is used to generate a fully qualified domain URL when you utilize relative path URL's in your mink steps (IE "/home").

    When you want to hit a domain different from the domain specified in base_url, all you have to do is use the fully qualified domain URL in your step like "http://test.tenancy.dev/fully/qualified".

    So use the base_url configuration to set what you will be using for the majority of your steps as relative url's and then explicitly specify the full domain for the exceptions.

    When I create an account named foo And GET "http://foo.tenancy.dev/ping" Then I get a 200 response code When I GET "/home" Then the response contains "Sign Up"

    If the majority of your testing will be against the sub domain, set that as your base_url and explicitly specify your top level domain when necessary.

    解决 无用
    打赏 举报
  • duanqiechui2378 2015-05-03 11:30

    You may resolve subdomains using xip.io, which is especially useful if you cannot access the /etc/hosts file on a CI server, for example.

    To route {account}.tenancy.dev to your local webserver, you can use account.tenancy.dev. which resolves to

    解决 无用
    打赏 举报