Skip to content

Get parameters don't get through from the test? #4

@origal

Description

@origal

Hi,

Consider this route:

$app->get('/say-hello',function() use ($app){
   $name = $app->request->params()['name'];
   if (is_null($name)){
       echo "Hello John Doe!";
   } else {
       echo "Hello ".$name."!";
   }

Trying http://slim-api.com/say-hello from a browser echos Hello John Doe!
Trying http://slim-api.com/say-hello?name=Craig echos Hello Craig! respectively.

So, here's the test for it:

public function testSayHello()
    {
        $parameters = array('name'=>'Craig Davis');
        $this->get('/say-hello',$parameters);
        $this->assertEquals(200, $this->response->status());
        $this->assertSame("Hello Craig Davis!",$this->response->body());
    }

This test fails:

oris@oris:~/slim-api$ phpunit tests/MyTest.php 
PHPUnit 3.7.29 by Sebastian Bergmann.

Configuration read from /home/oris/slim-api/phpunit.xml

F

Time: 31 ms, Memory: 5.00Mb

There was 1 failure:

1) MyTest::testSayHello
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-Hello Craig Davis!
+Hello John Doe!

/home/oris/slim-api/tests/MyTest.php:31
/usr/share/php/PHPUnit/TextUI/Command.php:192
/usr/share/php/PHPUnit/TextUI/Command.php:130

FAILURES!
Tests: 1, Assertions: 2, Failures: 1.

Also, consider my addition to your tests/bootstrap.php updating the request globals. (As written in issue #3 ) Maybe we need to improve it somehow?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions