简体   繁体   English

集成Codeception以在laravel中使用

[英]Integrate Codeception to use in laravel

Is there any way of integrating codeception into laravel that i can use it in my Controllers? 有什么方法可以将Codeception集成到laravel中,以便我可以在Controller中使用它?

For instance let's assume I've got a route Route::post('/plugins/test', PluginController@test_plugins) 例如,假设我有一条路由Route::post('/plugins/test', PluginController@test_plugins)

In my PluginController class I want to test whether my app works correctly or not. 在我的PluginController类中,我想测试我的应用程序是否正常运行。 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 我正在使用Laravel 4.2

Cheers Jakob 干杯雅各布

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 调用./vendor/bin/codecept运行单元YourTestCest

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM