1

Is there any way of integrating codeception into laravel that i can use it in my Controllers?

For instance let's assume I've got a route Route::post('/plugins/test', PluginController@test_plugins)

In my PluginController class I want to test whether my app works correctly or not. In my case, I wanna check this after updating a plugin by using the same semantics for acceptance tests in codeception, something like:

public function test_plugins(){
 $I = new AcceptanceTester($scenario);
 $I->wantTo('check that ... ');
 $I->amOnPage('/plugins');
 $I->seeInDatabase( ... );
 ....

 return "site works (not) correctly";
}

I am using Laravel 4.2

Cheers Jakob

1
  • Did you have any progress on this? Commented May 2, 2017 at 4:11

1 Answer 1

2

I think you are trying to do it in the wrong way. Controller never should test anything. Controller is a thing that just know what to do when the route were called. This means that you may want to call console command from the controller which will run your tests but not write testing code in controller itself.

So the steps to achieve what do you want to do are:

  1. Create test suit as usual in your tests folder
  2. Create the controller
  3. Call the ./vendor/bin/codecept run unit YourTestCest
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks, so that is actually possible! But what,if i want any user of my app to be able to create custom tests? I cannot setup predefined tests then, right?
I think its really uncommon case to allow users to create tests by their own because they can write some destructive code there which will break everything. It's OK only if your users are working in some kind of isolated playground which is creating before running tests and destroying after tests complete.
And in this case you still can just allow users to run console command by API which will generate empty test suite. Then allow them to edit and run this suites just as I described before. You are trying to make chimera because your test cases are using your application but you want your application to use tests which are using your application :)
maybe it is a bit missunderstood.. I want to use the syntax from codeception in my laravel controller to provide users of my app, to create custom test cases. E.g: the appliaction maintaince multiple wordpress site. Lets assume the user updates a plugin via the dashboard. After that he wants to know whether the site is still working or not. Therefore the user should be able to create custom tests, for his wordpress site. $I->amOnPage('/shop'); $I->see(...) ... The Parameter should be loaded from DB. In the final result, the user should be able to built tests by drag'n'drop.
I would suggest you using symfony.com/doc/current/components/browser_kit.html And build a classy on top of the browser kit client. The thing you want to implement is not the case for codeception. But I'm not sure, just an opinion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.