Skip to content

Commit

Permalink
Fix isset magic function for Getter method and add test for setter trait
Browse files Browse the repository at this point in the history
  • Loading branch information
soheilrt committed Sep 23, 2019
1 parent 51f5187 commit 9ba72a4
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Client/Traits/Setter.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private function getQualifiedSetterMethodName($name): string
public function __isset($name)
{
if ($this->hasGetter($name)) {
return $this->${$this->getQualifiedGetterMethodName($name)} === null;
return !empty($this->{$this->getQualifiedGetterMethodName($name)}());
}
if (isset($this->attributes[$this->getQualifiedAttributeName($name)])) {
return true;
Expand Down
44 changes: 44 additions & 0 deletions tests/Unit/Traits/SetterTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Soheilrt\AdobeConnectClient\Tests\Unit\Traits;

use PHPUnit\Framework\TestCase;

class SetterTraitTest extends TestCase
{
private $setter;

public function test_has_property()
{
$this->assertTrue(isset($this->setter->privateProperty));
$this->assertEquals('private property', $this->setter->privateProperty);

$this->assertFalse(isset($this->setter->NotAvailableProperty));
$this->assertNull($this->setter->NotAvailableProp);
}

public function test_has_attribute()
{
$this->assertTrue(isset($this->setter->property_attribute));
$this->assertEquals('attribute value', $this->setter->property_attribute);

$this->assertFalse(isset($this->setter->not_exists_attribute));
$this->assertNull($this->setter->Not_exists_attribute);
}

public function test_getter()
{
$this->assertTrue(isset($this->setter->propertyGetter));
$this->assertEquals('getter value', $this->setter->PropertyGetter);

$this->assertFalse(isset($this->setter->propertyNotExistsGetter));
$this->assertNull($this->setter->propertyNotExistsGetter);
}

protected function setUp(): void
{
parent::setUp();
$this->setter = new SetterTraitTestClass();
}
}

25 changes: 25 additions & 0 deletions tests/Unit/Traits/SetterTraitTestClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php


namespace Soheilrt\AdobeConnectClient\Tests\Unit\Traits;


use Soheilrt\AdobeConnectClient\Client\Traits\Setter;

class SetterTraitTestClass
{
use Setter;

private $privateProperty='private property';

public function __construct()
{
$this->{$this->getQualifiedAttributeName('property_attribute')}='attribute value';
}

public function getPropertyGetter():string
{
return 'getter value';
}

}

0 comments on commit 9ba72a4

Please sign in to comment.