You are awesome. I've been hoping for this. I'll try it out today.
Laravel 5 codeception module
I created a Codeception module for Laravel 5, you can find it here:
https://github.com/janhenkgerritsen/codeception-laravel5
I modified the existing Laravel 4 module so that it now works with the Laravel 5 development version. I use the module for my own tests without problems. But if you run into any problems just let me know.
Nice! Was hoping that someone would tackle this sooner than later.
Did you tell Davert? He'll probably want to reference it on the Codeception site, once L5 is officially out.
@JeffreyWay Yeah I have sent him an email.
@JanHenkG thanks dude. Can confirm this has been working well for me as well.
That was fast!
I can't make it work! I installed Codeception phar file on my Homestead box, I added your package via composer, run all (I think) required commands and I'm stuck on "codeception build" which is giving me "Codeception\Exception\Configuration Laravel5 could not be found and loaded".
I checked the sample project on github, I can't find anything that I'm missing. I guess it has to be some kind of latest L5 change that's affecting your package. I hope I'm wrong. Help anyone?!
Nevermind! It's all working now, but just to share my recent discovery (and it might be a silly one): you have to use codecept file from your project's vendor folder, not the global one.
I have codeception installed globally via phar archive as described on their website, but it didn't work with my Laravel 5.0 project and JanHenkG's package. Everything's working when I go into my project's folder and run
php ./vendor/codeception/codeception/codecept run
Glad to hear you figured it out!
@JanHenkG Awesome man!
Hi @JanHenkG, I am just trying to complete the Larabook series but I got stuck with chapter 8 'Users'. Your module worked fine until now, but I don't get it managed to write a record to the database.
My testcase says the form has been submitted (I am checking whether 'Welcome to Larabooks' is displayed) but nothing has been written to the DB. It works fine if I submit the form manually from within the browser!
Any ideas?
I hope you or anybody else can help me out there...
UPDATE: Guess it is related to the XSRF-TOKEN. Found the following discussion: https://laracasts.com/discuss/channels/general-discussion/latest-v5-laravelframework-csrfmiddleware-changes-broke-codeception-functional-tests
@jacojo Better post a new topic including your code.
Is it possible to set an sqlite memory database with codeception? If yes how?
@JanHenkG Hey man, nice work! I've been running my unit tests with great success, but my functional/acceptance tests (basically, all tests which involve the database) are not working correctly. For my project, I have a development database and a separate database for testing. Your package sets the environment to "testing" as you'd expect, but it doesn't trigger the config modifications which have been entered in my phpunit.xml file. Because of this, Codeception runs all tests using my local database for testing purposes and thus overrides all data I have in there.
Any ideas how to work around that?
@hfalucas You can configure an in-memory sqlite database for your testing environment. I have not done this myself, I just use a normal sqlite database and this is fast enough for all my purposes. But for more information you could look at http://code.tutsplus.com/tutorials/testing-like-a-boss-in-laravel-models--net-30087 or https://laracasts.com/discuss/channels/general-discussion/use-sqlite-in-memory-db-with-codeception?page=1.
@Elimentz As far as I know Codeception does not use the phpunit.xml file, this is used if you run tests with PHPUnit. So you should make your config changes for testing in the Laravel testing environment configuration.
@JanHenkG See that's the thing: I tried making a new database config file in the config/testing environment, Taylor has removed the overriding config option from Laravel. Because of this, Laravel uses this testing config setup for both testing as well as local environment.
I also tried injecting a new env.testing file into the application when running unit tests but this was not possible since the environment config is loaded while the application is booted in /bootstrap/app.php so no luck there either.
The phpunit.xml file is the only way I got it to work so far and if that doesn't work, I'm afraid we're pretty much stuck
I haven't updated the sample app in a while, I plan to do that this week. I will also look into this issue when I do that.
I found a solution to the problem. The Laravel Application class has a method loadEnvironmentFrom($file) with which you can specify which environment file to load. It defaults to .env. I updated the module so that you can now specify a specific environment file to load for the test suites:
class_name: FunctionalTester
modules:
enabled: [Laravel5, FunctionalHelper]
config:
Laravel5:
environment_file: .env.testing
With this configuration for your suite the .env.testing file will be loaded instead of the default .env file.
You can check the sample app at https://github.com/janhenkgerritsen/codeception-laravel5-sample to see how I configured everything to use another database for testing. The most important thing to notice here is that I created another database connection sqlite_testing for the testing database. If you do not do this, you cannot migrate your testing database, because the environment parameter to the php artisan migrate command is ignored. But if you use a connection you can use the --database parameter as follows:
php artisan migrate --database=sqlite_testing
@JanHenkG Thanks for the effort, works like a charm now!
thank you very much
Great, thanks, this worked for me also. I am using mysql for testing. The only thing is that I had to hard code some database values in database.php to get mysql testDB to migrate. Do not really understand why the .env file can not be overridden in a simple way like in 4.2.. Not sure when to use "php artisan migrate --env=testing" anymore
@JanHenkG When I run the tests with Laravel 5.0 inside homestead both functional tests from HelperCest will fail.
As far as I understand it, if we run Laravel from the console the value url from config/app.php will be used to build the correct url with helpers like route() or url().
I assume this is also the case when we run the functional tests.
It looks to me like this is not working and it's always returning localhost no matter what value I set in config/app.php.
@all: Has anybody experienced the same problem and maybe a solution ?
Thanks
@pixelpeter There is a fix for the route() and url() functions in the HEAD of the 2.0 branch of Codeception, this fix will be released with Codeception 2.0.15.
Also, please report issues on the issue tracker of the Codeception project on Github. That's the only place where I will check for issues regularly.
@JanHenkG Thank you for your reply
I wasn't sure if it's a bug and I wasn't sure if it was Laravel or Codeception related. Otherwise I would have posted it on Github.
Thanks again
@JanHenkG @raffw7912 I am receiving that same error.
What about support for Laravel's expectsEvents ?
@Elimentz I solve it this way, I create a new environment in example for the functional tests
codecept generate:environment functional
then I create some directory within _envs directory, as example named "files" , and then just add this string to functional.yml file
modules:
config:
Laravel5:
environment_file: tests/_envs/files/.functional
and finally I create tests/_envs/files/.functional file with my environment configuration
Now I can run codeception with desired environment
codecept run --env=functional
@JanHenkG I followed your repo exactly and I can't get Laravel to use any .env at all! Here's my api.suite.yml
class_name: ApiTester
modules:
enabled:
- \Helper\Api
- REST:
depends: Laravel5
- Laravel5:
environment_file: .env.testing
What am I missing?! Been at this like two days :)
Please or to participate in this conversation.