I have a Macbook with OS El Capitan. In my new Laravel application (created by
$ composer create-project laravel/laravel my_app
), I type:
$ php artisan serve
And in the browser (Safari or Chrome) on localhost:8000 I successfully see black text "Laravel 5" on the webpage.
I have a hometest.feature file in features/ that looks like:
Feature:
In order to prove that Behat works as intended
We want to test the home page for a phrase
Scenario: Root Test
When I am on the homepage
Then I should see "Laravel 5"
I have a /features/bootstrap/FeaturesContext.php file which looks like:
<?php
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
/**
* Defines application features from the specific context.
*/
class FeatureContext extends Behat\MinkExtension\Context\MinkContext implements Context, SnippetAcceptingContext
{
/**
* 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()
{
}
}
I have a behat.yml file that looks like:
default:
extensions:
Laracasts\Behat:
# env_path: .env.behat
Behat\MinkExtension:
default_session: laravel
base_url: http://localhost:8000
laravel: ~
When I run (localhost running or not running = doesn't differ result):
$ vendor/bin/behat
The console output is:
Feature:
In order to prove that Behat works as intended
We want to test the home page for a phrase
Scenario: Root Test # features/hometest.feature:5
When I am on the homepage # FeatureContext::iAmOnHomepage()
Then I should see "Laravel 5" # FeatureContext::assertPageContainsText()
The text "Laravel 5" was not found anywhere in the text of the current page. (Behat\Mink\Exception\ResponseTextException)
--- Failed scenarios:
features/hometest.feature:5
1 scenario (1 failed)
2 steps (1 passed, 1 failed)
0m0.12s (20.26Mb)
Why does my simple "I should see 'Laravel 5' test fail? If the localhost needs to be running, how do I run my test at the same time? When I start up the local host, nothing I type in the terminal receives a response anymore.
My directory structure of applicable folders:
app/
bootstrap/
...
features/
bootstrap/
FeatureContext.php
hometest.feature
...
.env.behat
behat.yml
composer.json
...
etc.
Thank you!
Finally! I found via my server logs (storage/logs/laravel.log) that the page rendered contained the text "Whoops, looks like something went wrong." (obviously the wrong page). The error was "development.ERROR: exception 'RuntimeException' with message 'No supported encrypter found. The cipher and / or key length are invalid.'" There are about 50 questions and answers on StackOverflow for this, and none of them worked. After researching for days, finally I found my solution. It may be a combination of previous changes I had made, or the success could entirely be due to this command. In any case, try:
php artisan config:cache
Phew!