Код: Выделить всё
public function testMergedDocumentsWithSuccessfulInit() {
$params = new \Buan\Request\Parameters([], [], [], []);
$mockAdminView = m::mock(AdminView::class);
// The mocking of init method will consider the inheritance from Ias\AdminController.
$controller = m::mock('DocumentsController', [$params])
->makePartial()
->shouldAllowMockingProtectedMethods();
// Mock the 'init' method which is inherited from Ias\AdminController
$controller->shouldReceive('init')
->with($mockAdminView)
->andReturn(true)
->once(); // Ensure the init method is mocked to return true once
echo "Mock setup complete, testing init call\n";
$initResult = $controller->init($mockAdminView); // This should print true as the init method is mocked
echo "init called, result: " . ($initResult ? "true" : "false") . "\n";
// Execute the mergedDocuments method and check the result
$result = $controller->mergedDocuments();
Код: Выделить всё
public function mergedDocuments(): AdminView
{
// Init
$view = new AdminView();
$initResult = $this->init($view);
if (!$initResult) {
return $view;
}
Код: Выделить всё
class DocumentsController extends Ias\AdminControllerЧто бы я ни делал установите для "->andReturn(...)" значение, возвращаемый $view всегда достигается, т.е. метод 'init' не перехватывается и работает как обычно, всегда возвращая false.
Код: Выделить всё
protected function init(AdminView $view, bool $bypassAuthCheck = false): boolЯ ожидал, установив для параметра andReturn значение false что ранний возврат не будет достигнут в моем методе mergeDocuments.
Подробнее здесь: https://stackoverflow.com/questions/784 ... mocked-cla
Мобильная версия