php - Mocking an object with internal dependencies in PHPUnit -


I am new to testing and I would like to understand how the tests are implemented in real world scenario. For example, this is the code that implements an internal structure, and chains the method. At first glance I joked that this will be the best way to go, but most examples come in such a way:
  public functions some functions (A $ a) {return $ a * b; }   

However, I'm testing the code goes like this:

  public function deleteUser ($ user_id) {$ user_id = (int) $ User_id; $ Flag = framework :: match () - & gt; Request-> Receive ('delete') || false; If ($ $-> user_id) is present ($! - $ user_id) (delete new user exception (UserException :: NOT_EXIST);} $ $ - (array ('id' = & gt; $ user_id)) ;}   

How will you test it? I have seen [1]: Testing of objects with dependency in PHPUnit

but its Modifying the actual code is not an option.

short answer: you do not test that code for the unit Can be in framework class due to static method calls Theode is paired, so that you can not test the method in the deleteUser () isolation. The test code that uses Singletons describes the situation well.

The long answer is that the unit can not test that code, but you can still test which are useful, such as integration testing or functional testing you can use as a reference, but Basically, Ekikkar In the test you work together in many parts of your code simultaneously. In such tests, you can test the expected behavior for this method, which is being removed without worrying about the dependence of your class. You want to test both the classes working together (class under the testing and framework classes), so you do not have to joke anything.

After saying this, why can not you change the code? I strongly suggest that instead of using a code, inject your dependence on the code (said in the first article).

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -