@andfelzapata I don't think Behat is very well supported in Laravel. I only use the Laravel-integrated testing, but then I make sure that I do not use Javascript for the code under test. Is it essential that you test the Javascript part of the code (i.e. if it is Ajax, can you just test the Ajax calls etc.), and is it essential that you use Behat?
Functional test API using Behat.
Hey guys I'm having problems starting with behat to make functional test for an existing application. I was able to set up everything, initially installing mink, the mink extension and the behat-laravel package. I started with a simple feature to test some functionalities of the login page.
This is the context I currently have:
class FeatureContext extends MinkContext implements Context
{
use DatabaseTransactions;
protected $user;
protected $client;
protected $response;
protected $baseUri = 'http://supplycompany.app';
/**
* Initializes context.
*
* Every scenario gets its own context instance.
* You can also pass arbitrary arguments to the
* context constructor through behat.yml.
*/
public function __construct()
{
$this->client = new Client(['base_uri' => $this->baseUri]);
}
/**
* @Given there is an active user
*/
public function thereIsAnActiveUser()
{
$this->user = Factory::create('office', ['username' => 'jonsnow', 'active' => 1]);
PHPUnit::assertEquals($this->user->active, 1);
}
/**
* @When the user attempts login
*/
public function theUserAttemptsLogin()
{
$this->response = $this->client->request('POST', '/dashboard/login', ['form_params' => [
'username' => 'jonsnow', 'password' => '1q2w3e4r']
]);
}
/**
* @Then the user should be logged in
*/
public function theUserShouldBeLoggedIn()
{
echo $this->response->getBody();
}
Initially I started testing that page with mink, but since it used javascript, for my current needs it didn't work. So I started using guzzle to make request but this hasn't worked because there is an issue with the environments. For starters I havent been able to change the APP_ENV . I have it set inside my .env as 'development' but if I try to get it with App::environment() or env('APP_ENV') I get local. Which I suspected it was from the Homestead.yml file, removed that line, reloaded, provisioned and still get 'local'. The thing is that my current feature is failing because I cant find the created user inside the AuthController. The user does get persisted to the database but from some dd() statements I did, but is not available in my controller, if I try to return the user from the controller, hardcoding the credentials I get null. I suspected this had something to do with the environment. So I started printing the environments inside the context class and returned from the controller to guzzle request. Tried echoing APP_KEY and they were different.
Given that background. I'm looking for some technique to make functional tests for my application using behat without mink, things like hitting controllers and testing them most of the time. I saw a post that used laravel's testing framework within behat to do this, I haven't tried it yet.
Is there a way to make the testing work with guzzle, regarding the applicaiton environments ? Or is the laravel test framework better ? Or ! Is there another way to accomplish this.
Note: I want to continue using behat.
Please or to participate in this conversation.