summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authorDaniel Kesselberg <mail@danielkesselberg.de>2019-11-14 19:57:43 +0100
committerDaniel Kesselberg <mail@danielkesselberg.de>2019-11-16 00:39:48 +0100
commita27c10daa66a38c453393fcaf0c545d60f041f30 (patch)
tree25eb759f6a1856feebb1ef99556543910aa64064 /tests/lib
parent51d3f98bfb83b632be6223a5d928d57e8e52e942 (diff)
downloadnextcloud-server-a27c10daa66a38c453393fcaf0c545d60f041f30.tar.gz
nextcloud-server-a27c10daa66a38c453393fcaf0c545d60f041f30.zip
Make isXXX available for bool properties only
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/AppFramework/Db/EntityTest.php43
1 files changed, 35 insertions, 8 deletions
diff --git a/tests/lib/AppFramework/Db/EntityTest.php b/tests/lib/AppFramework/Db/EntityTest.php
index c9a90da7c59..49ecad0b561 100644
--- a/tests/lib/AppFramework/Db/EntityTest.php
+++ b/tests/lib/AppFramework/Db/EntityTest.php
@@ -25,6 +25,7 @@ namespace Test\AppFramework\Db;
use OCP\AppFramework\Db\Entity;
+use PHPUnit\Framework\Constraint\IsType;
/**
@@ -38,18 +39,28 @@ use OCP\AppFramework\Db\Entity;
* @method void setEmail(string $email)
* @method string getPreName()
* @method void setPreName(string $preName)
+ * @method bool getTrueOrFalse()
+ * @method bool isTrueOrFalse()
+ * @method void setTrueOrFalse(bool $trueOrFalse)
+ * @method bool getAnotherBool()
+ * @method bool isAnotherBool()
+ * @method void setAnotherBool(bool $anotherBool)
*/
class TestEntity extends Entity {
protected $name;
protected $email;
protected $testId;
protected $preName;
+ protected $trueOrFalse;
+ protected $anotherBool;
- public function __construct($name=null){
+ public function __construct($name = null) {
$this->addType('testId', 'integer');
+ $this->addType('trueOrFalse', 'bool');
+ $this->addType('anotherBool', 'boolean');
$this->name = $name;
}
-};
+}
class EntityTest extends \Test\TestCase {
@@ -73,7 +84,7 @@ class EntityTest extends \Test\TestCase {
public function testFromRow(){
$row = array(
- 'pre_name' => 'john',
+ 'pre_name' => 'john',
'email' => 'john@something.com'
);
$this->entity = TestEntity::fromRow($row);
@@ -93,21 +104,21 @@ class EntityTest extends \Test\TestCase {
public function testColumnToPropertyNoReplacement(){
$column = 'my';
- $this->assertEquals('my',
+ $this->assertEquals('my',
$this->entity->columnToProperty($column));
}
public function testColumnToProperty(){
$column = 'my_attribute';
- $this->assertEquals('myAttribute',
+ $this->assertEquals('myAttribute',
$this->entity->columnToProperty($column));
}
public function testPropertyToColumnNoReplacement(){
$property = 'my';
- $this->assertEquals('my',
+ $this->assertEquals('my',
$this->entity->propertyToColumn($property));
}
@@ -137,7 +148,6 @@ class EntityTest extends \Test\TestCase {
/**
* @expectedException \BadFunctionCallException
*/
-
public function testSetterShouldFailIfAttributeNotDefined(){
$this->entity->setTest();
}
@@ -208,7 +218,9 @@ class EntityTest extends \Test\TestCase {
$entity = new TestEntity();
$this->assertEquals(array(
'id' => 'integer',
- 'testId' => 'integer'
+ 'testId' => 'integer',
+ 'trueOrFalse' => 'bool',
+ 'anotherBool' => 'boolean',
), $entity->getFieldTypes());
}
@@ -226,5 +238,20 @@ class EntityTest extends \Test\TestCase {
$this->assertEquals(0, count($entity->getUpdatedFields()));
}
+ public function testIsGetter() {
+ $entity = new TestEntity();
+ $entity->setTrueOrFalse(false);
+ $entity->setAnotherBool(false);
+ $this->assertThat($entity->isTrueOrFalse(), new IsType(IsType::TYPE_BOOL));
+ $this->assertThat($entity->isAnotherBool(), new IsType(IsType::TYPE_BOOL));
+ }
+ /**
+ * @expectedException BadFunctionCallException
+ */
+ public function testIsGetterShoudFailForOtherType() {
+ $entity = new TestEntity();
+ $entity->setName('hello');
+ $this->assertThat($entity->isName(), new IsType(IsType::TYPE_BOOL));
+ }
}