G
G
ganbatte2020-07-02 06:22:07
PHPUnit
ganbatte, 2020-07-02 06:22:07

In phpunit, is it possible to mock a future callable?

I have such a class, and in this class a method from another class is called, is it possible to override its result?

class Book {

public function getAuthorName($id)
  {
       $author = Author::model()->findByPk($id);
       return $author->name;
  }
}

I am writing a test
class BookTest{
  public function test()
   {
      $book = new Book();
      // Вот тут как то хочу переопределить возвращаемое значение Author::model()->findByPk($id);
     // Типа при вызове Author::model()->findByPk()->name ==  'Саня';
      $result = $book->getAuthorName(1);
       $this->assertEquals('Саня', result);
   }
}


Or is it unrealistic?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question