A
A
azeke152019-05-23 07:21:32
PHP
azeke15, 2019-05-23 07:21:32

How to lock the called methods of another class?

Hello developers! I have a test question. Covering for the first time. Below is an example:

class Book
{
public function bookFunction()
{
$page = new Page();
$page->validate($params);
}
}

class Page
{
public function validate($params)
{
$model = new Model();
$model->getParams($params)
}
}

class Model
{
public function getParams($params)
{
//DB::query...
}
}

How can I lock the getParams method if I cover the Book class with tests?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kosarinin, 2019-05-23
@kosarinin

Create an object of the Page class through the factory and already return a mock of the Page class. If you're testing Book, you don't need to test Page and its other dependencies.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question