V
V
Vladislav Aleinikov2020-09-15 14:12:14
PHPUnit
Vladislav Aleinikov, 2020-09-15 14:12:14

How to stub methods from a called phpunit method?

There is a method that requests json from an external API. I simulate a call to this method, and I muffle inside this method, the method that calls the api, but for some reason I run into an error: Protocol "" not supported or disabled in libcurl
In the getTasksData () method, a connection to the api occurs that does not need to be done in tests . Why is the original getTasksData() called and not its replacement?

public function testCreateTasks()
{
  $mock = Mockery::mock(MyClass::class)->makePartial();
  $mock->shouldReceive('getTasksData')->andReturn(false);
  $result = $mock->createTasks();
  
  $this->assertSame(false, $result);

}

method from class
public function createTasks()
{
  $tasks = self::getTasksData();
  // создать задачу
  return true;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tendor, 2020-09-15
@Tendor

$mock->shouldReceive('getTasksData')->never();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question