Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

added missing return $this to setValue method. #7114

Closed
wants to merge 5 commits into from

Conversation

matwright
Copy link
Contributor

added return $this to the setValue method to implement fluid interface like other setters in this class.

added return $this to the setValue method to implement fluid interface like other setters in this class.
@Ocramius
Copy link
Member

Ocramius commented Jan 9, 2015

Requires a test case to prevent regressions.

@@ -112,6 +112,7 @@ public function setValue($value)
$this->yearElement->setValue($value['year']);
$this->monthElement->setValue($value['month']);
$this->dayElement->setValue($value['day']);
return $this;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docblock of the method should also be modified

@matwright
Copy link
Contributor Author

ok, will do that shortly.

@matwright
Copy link
Contributor Author

DocBlock has been updated. For the regression test, as this method had no previous return value I'm not sure what to test exactly. This update cannot impact existing functionality and all current test cases are passing.

@Ocramius
Copy link
Member

Ocramius commented Jan 9, 2015

@matwright the test should simply assert that the return value is the same of the object the method is called upon

@@ -89,7 +89,7 @@ public function getDayAttributes()
/**
* @param string|array|\ArrayAccess|PhpDateTime $value
* @throws \Zend\Form\Exception\InvalidArgumentException
* @return void|\Zend\Form\Element
* @return DateSelect
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@return self imo for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samsonasik The other setters in this class use @return DateSelect
would you like me to update this and the other setter docblocks to show return self ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change only for this method i think because it is new introduced docblock. there is inconsistencies about it in other files too. i created PR in the past but can't finish to update all.

@samsonasik
Copy link
Contributor

you can use :

$this->assertInstanceOf('Zend\Form\Element\DateSelect', $element->setValue('now'));

@Ocramius
Copy link
Member

Ocramius commented Jan 9, 2015

@samsonasik should be assertSame

public function testValueSetterReturnsSameObjectType()
{
$element = new DateSelectElement();
$this->assertInstanceOf(get_class($element), $element->setValue('hello world'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setValue('hello world') must be end up with Exception because of this https://github.com/matwright/zf2/blob/master/library/Zend/Form/Element/DateSelect.php#L97-L101

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @samsonasik just updated that to a valid date string

@samsonasik
Copy link
Contributor

👍

@Ocramius Ocramius added this to the 2.3.4 milestone Jan 10, 2015
@Ocramius Ocramius self-assigned this Jan 10, 2015
Ocramius added a commit that referenced this pull request Jan 12, 2015
Ocramius added a commit that referenced this pull request Jan 12, 2015
@Ocramius Ocramius closed this in d76734a Jan 12, 2015
Ocramius added a commit that referenced this pull request Jan 12, 2015
@Ocramius
Copy link
Member

Merged, thanks @matwright and @samsonasik!

master: d76734a
develop: 4567312

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

Successfully merging this pull request may close these issues.

None yet

3 participants