-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make isXXX available for bool properties only
Signed-off-by: Daniel Kesselberg <[email protected]>
- Loading branch information
Showing
2 changed files
with
53 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
|
||
|
||
use OCP\AppFramework\Db\Entity; | ||
use PHPUnit\Framework\Constraint\IsType; | ||
|
||
|
||
/** | ||
|
@@ -38,18 +39,28 @@ | |
* @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 @@ public function testResetUpdatedFields(){ | |
|
||
public function testFromRow(){ | ||
$row = array( | ||
'pre_name' => 'john', | ||
'pre_name' => 'john', | ||
'email' => '[email protected]' | ||
); | ||
$this->entity = TestEntity::fromRow($row); | ||
|
@@ -93,21 +104,21 @@ public function testGetSetId(){ | |
|
||
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 @@ public function testGetterShouldFailIfAttributeNotDefined(){ | |
/** | ||
* @expectedException \BadFunctionCallException | ||
*/ | ||
|
||
public function testSetterShouldFailIfAttributeNotDefined(){ | ||
$this->entity->setTest(); | ||
} | ||
|
@@ -208,7 +218,9 @@ public function testGetFieldTypes() { | |
$entity = new TestEntity(); | ||
$this->assertEquals(array( | ||
'id' => 'integer', | ||
'testId' => 'integer' | ||
'testId' => 'integer', | ||
'trueOrFalse' => 'bool', | ||
'anotherBool' => 'boolean', | ||
), $entity->getFieldTypes()); | ||
} | ||
|
||
|
@@ -226,5 +238,20 @@ public function testFieldsNotMarkedUpdatedIfNothingChanges() { | |
$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)); | ||
} | ||
} |