2012-09-15 42 views
1

我遇到了Behat和Mink的一些問題。使用的驅動程序是Goutte。我試圖測試我的Symfony 2.1應用程序。Behat,mink和goutte:當前的URI必須是絕對URL

behat.yml

default: 
extensions: 
    Behat\Symfony2Extension\Extension: 
     mink_driver: true 
    Behat\MinkExtension\Extension: 
     base_url: 'http://localhost/project/web/app_dev.php' 
     goutte: ~ 

test.feature

Feature: Test 
    In order to log-in 
    As a user 
    I need to be able to use the login-form 

    Scenario: Logging in 
     Given I am on "/login" 
     When I fill in "username" with "admin" 
     And I fill in "password" with "password" 
     And I press "_submit" 
     Then show last response 
     Then I should see "Hello" 

當我嘗試執行測試(在Windows 7):

bin\behat @MyTestBundle 

測試停止在

And I press "_submit"

有了這個錯誤:

Current URI must be an absolute URL ("/app_dev.php"). 

我已經嘗試過幾乎所有可能的BASE_URL路徑和我沒有設法得到它的工作。

你有任何想法如何解決這個問題?

形式我嘗試提交:

<form action="/app_dev.php/login_check" class="form-horizontal" method="post"> 
    <fieldset> 
     <div class="control-group"> 
      <label class="control-label" for="username">Nazwa użytkownika:</label> 

      <div class="controls"><input type="text" id="username" name="_username" value=""/></div> 
     </div> 

     <div class="control-group"> 
      <label for="password" class="control-label">Hasło:</label> 

      <div class="controls"><input type="password" id="password" name="_password"/></div> 
     </div> 

     <div class="control-group"> 
      <div class="controls"> 
       <label for="remember_me" class="checkbox"> 
        <input type="checkbox" id="remember_me" name="_remember_me" value="on"/>Nie wylogowuj mnie 
       </label> 
      </div> 

     </div> 
     <div class="form-actions"> 
      <input type="submit" class="btn-primary" id="_submit" name="_submit" 
        value="Zaloguj"/> 
      <a href="/app_dev.php/register/" class="btn btn-success">Rejestracja</a> 
     </div> 
    </fieldset> 
</form> 

回答

1

我今天找到了解決我的問題的方法。

確實問題出現在路徑函數中。 路徑功能應替換爲樹枝url功能。

有趣的是:改變功能爲url在表單action屬性不會幫助。在我的基地佈局我有:

<base href="{{ path('_default')}}"/> 

這一個行代碼導致的問題,它應該是:

<base href="{{ url('_default')}}"/> 

在此之後更改測試按預期工作。

1

在你的樹枝模板,當您創建login_check網址,你必須創建一個絕對URL(路徑的第三個參數,是真正創建一個絕對網址):

{{ path('route', {}, true) }} 
相關問題