duandong1869 2015-04-24 13:57
浏览 103
已采纳

使用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:

default:
    extensions:
        Laracasts\Behat:
            # env_path: .env.behat
        Behat\MinkExtension:
            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.

  • 写回答

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);
        $this->visit('/');
    }
    

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程