-
Notifications
You must be signed in to change notification settings - Fork 3
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
Request cookie parser #50
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,9 @@ public function createQueryParser(); | |
* @return RequestParser | ||
*/ | ||
public function createBodyParser(); | ||
|
||
/** | ||
* @return RequestParser | ||
*/ | ||
public function createCookieParser(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might break existing classes implementing the interface. What do you think about creating a second interface There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, true 👍 will change that |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,22 +5,30 @@ abstract class AbstractIntegrationTest extends \PHPUnit_Framework_TestCase | |
abstract public function controllersProvider(); | ||
|
||
/** | ||
* @param AbstractIntegrationTestController $controller | ||
* | ||
* @dataProvider controllersProvider | ||
*/ | ||
public function testStringAction(AbstractIntegrationTestController $controller) | ||
{ | ||
$this->assertEquals('Test', $controller->testString()); | ||
$this->assertEquals('Test', $controller->testString(true)); | ||
} | ||
|
||
/** | ||
* @param AbstractIntegrationTestController $controller | ||
* | ||
* @dataProvider controllersProvider | ||
*/ | ||
public function testIntAction(AbstractIntegrationTestController $controller) | ||
{ | ||
$this->assertEquals(1, $controller->testInt()); | ||
$this->assertEquals(1, $controller->testInt(true)); | ||
} | ||
|
||
/** | ||
* @param AbstractIntegrationTestController $controller | ||
* | ||
* @dataProvider controllersProvider | ||
*/ | ||
public function testNotFoundActionThrowsException(AbstractIntegrationTestController $controller) | ||
|
@@ -40,23 +48,27 @@ public function __construct($request) | |
$this->request = $request; | ||
} | ||
|
||
protected function parameter($name) | ||
protected function parameter($name, $cookie = false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we split this into two functions ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was actually wondering about it, good point, this discussion solves my conflict :-) good point |
||
{ | ||
if ($this->request->getMethod() === 'GET') { | ||
return $this->queryParameter($name); | ||
if (!$cookie) { | ||
if ($this->request->getMethod() === 'GET') { | ||
return $this->queryParameter($name); | ||
} else { | ||
return $this->bodyParameter($name); | ||
} | ||
} else { | ||
return $this->bodyParameter($name); | ||
return $this->cookieParameter($name); | ||
} | ||
} | ||
|
||
public function testString() | ||
public function testString($fromCookie = false) | ||
{ | ||
return $this->parameter('string')->string()->required(); | ||
return $this->parameter('string', $fromCookie)->string()->required(); | ||
} | ||
|
||
public function testInt() | ||
public function testInt($fromCookie = false) | ||
{ | ||
return $this->parameter('int')->int()->required(); | ||
return $this->parameter('int', $fromCookie)->int()->required(); | ||
} | ||
|
||
public function testNotFound() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a
string
typehint here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍