Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
origal opened this issue Feb 12, 2014 · 3 comments
Closed

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

origal opened this issue Feb 12, 2014 · 3 comments

Comments

@origal
Copy link

origal commented Feb 12, 2014

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?

@origal
Copy link
Author

origal commented Feb 12, 2014

Fixed. I have added this line to the request method on tests/bootstrap.php:

'QUERY_STRING' => http_build_query($options)

@there4
Copy link
Collaborator

there4 commented Feb 19, 2014

Thanks for taking the time to keep me updated for this, much appreciated. I think this should solve the issue you were having, let me know if it doesn't. I'll look at issue 3 next.

@there4 there4 closed this as completed Feb 19, 2014
@origal
Copy link
Author

origal commented Feb 19, 2014

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant