Router icon indicating copy to clipboard operation
Router copied to clipboard

Write tests

Open osaris opened this issue 10 years ago • 5 comments

Hello !

I want to write tests for Hoa\Router but I don't know how to start :)

Can you help me ? /ping @Hywan

Thx !


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

osaris avatar Nov 19 '14 09:11 osaris

Having this example https://github.com/hoaproject/Iterator/blob/master/Test/Unit/Append.php helps?

Hywan avatar Nov 19 '14 10:11 Hywan

Well, I finally manage to run my own tests but I'm now stuck on "how to test". Here is my first test :

    $this
        ->given(
          $r = new CUT(),
          $r->get('u', '/hello', function ( ) {
            echo 'world!', "\n";
          })
        )
        ->when(
          $result = $r->route('/hello')
        )
        ->then(

        );

but I don't know what to write in the then part ? Test if a rule matched ? Test the rule ?

osaris avatar Nov 19 '14 16:11 osaris

Maybe with

->then($rule = $r->getTheRule()):
$this->array($rule)->string[\Hoa\Router::RULE_CALL]->isEqual('...')

Or anything like that, your test its more for test Router + Dispatcher for the test the "ouput" of the route

thehawk970 avatar Nov 19 '14 18:11 thehawk970

Just calling getTheRule is fine I think. And use CUT::RULE_CALL instead of Hoa\Ruler by the way ;-).

Hywan avatar Nov 20 '14 07:11 Hywan

(but :+1: for @camael24!)

Hywan avatar Nov 20 '14 07:11 Hywan