Tuesday, 15 September 2015

testing - CakePHP 3 integeration test without a model/entity -


I am trying to test a controller function ... I want to test some things: a) It throws an invalid request exception when a specific logic is used. B) It works correctly when the right logic is correct.

I have written a few unit tests and they all seem cool, only one can get me the documentation, but the integration test is interesting and potentially useful, I do not think I should join it Imagine applying it without (which I do not want to necessarily).

  Namespace App \ Test \ Testicles \ Controller; Use cake \ ORM \ TableRegistry; Use cake \ TestSuite \ IntegrationTestCase; The class is expanded into Muster Controllant Accountant Season {Public Function Testin ()) ($ -> (-); $ This-> Set Estimated Exception ('Invalid Request');}  
< P>} MusterController AppController {public $ helpers = array ('address') is expanded; Filters before the public function (event $ event) {$ this-> AUTH- & Gt; Permission ('In'); $ This-> Layout = 'Empty'; $ This- & gt; Autorender = Wrong; $ this-> LoadComponent ('Rule'); Parents :: BeforeFilter ($ event);} $ Function- ($ param = null) {if! ($! - this- & gt; Request-> (Array ('post', 'put')) $ $ - this- & gt; Request- & gt; Data ('Proc')! = 'More' || is_null ($ absolute)) {put new exception notwithstanding (__ ('Invalid Requests')); $ $ - Procedure Request ($ this-> Request-> Data ('Hit'), $ this-> Request-> Data ('Proc'), $ param);}

Indicators appreciated.

integration seasons class, as its name implies, for integration testing. That is, it will test the interaction between the controller and any other class who uses the feedback.

There is another way of testing controller, which is more difficult to complete, but allows you to test the controlling methods in isolation:

  public function testMyControllerMethod () {$ Request = $ this- & gt; GetMock ('cake \ network \ request'); $ Response = $ this- & gt; GetMock ('cake \ network \ response'); $ Controller = new MyController ($ request, $ response); $ Controller- & gt; StartupProcess (); // Add some logic and expectations here. For example, you have $ controller-gt; Call the name of the tag in a counterfeit class / $ method that you would get $ controller- & gt; Want to test myMethod ('param1', 'param2'); }  

No comments:

Post a Comment