Skip to content

Commit

Permalink
Fix fluent interface, method setValue on elements (Checkbox, Select, …
Browse files Browse the repository at this point in the history
…Textarea).
  • Loading branch information
Michał Lipek committed Oct 9, 2014
1 parent e00e512 commit 0b825e4
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 2 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"satooshi/php-coveralls": "dev-master",
"phpunit/phpcov": "*",
"phpunit/phpunit": "*",
"sebastian/phpcpd": "*"
"sebastian/phpcpd": "*",
"pdepend/pdepend" : "1.1.0",
"squizlabs/php_codesniffer": "1.*"
},
"autoload": {
"psr-0": {
Expand Down
5 changes: 5 additions & 0 deletions src/Impreso/Element/Checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ public function isChecked()
return (bool)$this->get('checked');
}

/**
* @param $value
* @return $this
*/
public function setValue($value)
{
$this->set('checked', (bool)$value);
return $this;
}

public function getValue()
Expand Down
7 changes: 7 additions & 0 deletions src/Impreso/Element/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,11 @@ private function isSimple()
}
return true;
}

public function testFluentInterface()
{
$element = new Select('test');
$element->setOptions(array('test' => 'Test'));
$this->assertEquals($element, $element->setValue('test'));
}
}
6 changes: 5 additions & 1 deletion src/Impreso/Element/TextArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ public function render()
return (string)(new HtmlElement('textarea', $this->getValue(), $attributes));
}

/**
* @param $value
* @return $this
*/
public function setValue($value)
{
$this->value = $value;
return $this;
}

public function getValue()
Expand All @@ -34,5 +39,4 @@ function getRawValue()
{
return $this->value;
}

}
6 changes: 6 additions & 0 deletions tests/Impreso/Element/ButtonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ public function testFilter()
$element->setValue(' Click this BUTTON!');
$this->assertEquals('CLICK THIS BUTTON!', $element->getValue());
}

public function testFluentInterface()
{
$element = new Button('test');
$this->assertEquals($element, $element->setValue('test'));
}
}
6 changes: 6 additions & 0 deletions tests/Impreso/Element/CheckboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,10 @@ public function testFilter()
$element->setValue(false);
$this->assertEquals("0", $element->getValue());
}

public function testFluentInterface()
{
$element = new Checkbox('test');
$this->assertEquals($element, $element->setValue(1));
}
}
20 changes: 20 additions & 0 deletions tests/Impreso/Element/InputTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Created by PhpStorm.
* User: Michał Lipek
* Date: 09.10.14
* Time: 17:27
*/

namespace Tests\Impreso\Element;


class InputTest extends \PHPUnit_Framework_TestCase
{

public function testFluentInterface()
{
$element = $this->getMockForAbstractClass('\Impreso\Element\Input', array('test'));
$this->assertEquals($element, $element->setValue('test'));
}
}
7 changes: 7 additions & 0 deletions tests/Impreso/Element/TextAreaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@ public function testFilter()
$element->setValue(' Python ');
$this->assertEquals('PYTHON', $element->getValue());
}


public function testFluentInterface()
{
$element = new TextArea('test');
$this->assertEquals($element, $element->setValue('test'));
}
}

0 comments on commit 0b825e4

Please sign in to comment.