-
-
Notifications
You must be signed in to change notification settings - Fork 57
Fixes #9 Bridge error when no file is selected #10
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
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 |
---|---|---|
|
@@ -161,4 +161,38 @@ public function testCreateResponseFromBinaryFile() | |
|
||
$this->assertEquals('Binary', $psrResponse->getBody()->__toString()); | ||
} | ||
|
||
public function testUploadErrNoFile() | ||
{ | ||
$file = new UploadedFile(null, null, null, 0, UPLOAD_ERR_NO_FILE, true); | ||
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. the $path parameter must be a string according to phpdoc, so passing null is invalid |
||
$this->assertEquals(0,$file->getSize()); | ||
$this->assertEquals(UPLOAD_ERR_NO_FILE,$file->getError()); | ||
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. missing space after comma |
||
|
||
// SplFile returns false on error | ||
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 should be the 3rd argument to assertFalse |
||
$this->assertEquals('boolean',gettype(($file->getSize()))); | ||
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. not needed as the assertion below is enough |
||
$this->assertFalse($file->getSize()); | ||
|
||
// This is an integer, oddly enough internally size is declared as a string | ||
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 comment use useless here as you are not testing UploadedFile here, thus the assertion below is awkward as well 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->assertTrue(is_int($file->getClientSize())); | ||
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. please use assertInternalType |
||
|
||
$request = new Request(array(),array(),array(),array(), | ||
array( | ||
'f1' => $file, | ||
'f2' => array('name' => null, 'type' => null, 'tmp_name' => null, 'error' => UPLOAD_ERR_NO_FILE, 'size' => 0), | ||
), | ||
array( | ||
'REQUEST_METHOD' => 'POST', | ||
'HTTP_HOST' => 'dunglas.fr', | ||
'HTTP_X_SYMFONY' => '2.8', | ||
), | ||
'Content' | ||
); | ||
|
||
$psrRequest = $this->factory->createRequest($request); | ||
|
||
$uploadedFiles = $psrRequest->getUploadedFiles(); | ||
|
||
$this->assertEquals(UPLOAD_ERR_NO_FILE, $uploadedFiles['f1']->getError()); | ||
$this->assertEquals(UPLOAD_ERR_NO_FILE, $uploadedFiles['f2']->getError()); | ||
} | ||
} |
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.
YODA: null === $value
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.
I've always been curious why the Symfony source prefers
null
to come first. What's the reasoning?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.
https://en.wikipedia.org/wiki/Yoda_conditions