J
J
jasonOk2018-03-12 22:29:30
PHP
jasonOk, 2018-03-12 22:29:30

How to properly test a method?

There is a very simplified method:

public function isAllowed (Dispatcher $dispatcher): bool
{    
    $module = $dispatcher->getModuleName();
    $controller = $dispatcher->getControllerName();
    $action = $dispatcher->getActionName();
    
     if ($module === 'main' && $controller === 'index') {
      return true;
     }
         
   return false;
}

How to mock Dispatcher and test different situations (e.g. $module is X or $action is Y)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Boris Korobkov, 2018-03-13
@BorisKorobkov

There is a very simplified answer:
1. Create a Dispatcher with the desired module / controller / action
2. Pass it to isAllowed
3. Compare answer
Without knowing your Dispatcher, only a clairvoyant can give a more detailed answer.

K
Kirill Nesmeyanov, 2018-03-13
@SerafimArts

mockery?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question