This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs #67: add test to validate ObjectHydrateHelperTrait
- Loading branch information
Showing
2 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
tests/LooplineSystems/CloseIoApiWrapper/Library/Fake/ObjectHydrateHelperDemo.php
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
/** | ||
* Close.io Api Wrapper - LLS Internet GmbH - Loopline Systems | ||
* | ||
* @link https://github.com/loopline-systems/closeio-api-wrapper for the canonical source repository | ||
* @copyright Copyright (c) 2014 LLS Internet GmbH - Loopline Systems (http://www.loopline-systems.com) | ||
* @license https://github.com/loopline-systems/closeio-api-wrapper/blob/master/LICENSE (MIT Licence) | ||
*/ | ||
|
||
namespace Tests\LooplineSystems\CloseIoApiWrapper\Library\Fake; | ||
|
||
use LooplineSystems\CloseIoApiWrapper\CloseIoRequest; | ||
use LooplineSystems\CloseIoApiWrapper\CloseIoApiWrapper; | ||
use LooplineSystems\CloseIoApiWrapper\CloseIoConfig; | ||
use LooplineSystems\CloseIoApiWrapper\Library\ObjectHydrateHelperTrait; | ||
|
||
class ObjectHydrateHelperDemo | ||
{ | ||
use ObjectHydrateHelperTrait; | ||
|
||
private $first; | ||
|
||
private $second; | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getFirst() | ||
{ | ||
return $this->first; | ||
} | ||
|
||
/** | ||
* @param mixed $first | ||
*/ | ||
public function setFirst($first) | ||
{ | ||
$this->first = $first; | ||
} | ||
/** | ||
* @return mixed | ||
*/ | ||
public function getSecond() | ||
{ | ||
return $this->second; | ||
} | ||
|
||
/** | ||
* @param mixed $second | ||
*/ | ||
public function setSecond($second) | ||
{ | ||
$this->second = $second; | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
tests/LooplineSystems/CloseIoApiWrapper/Library/ObjectHydrateHelperTraitTest.php
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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
/** | ||
* Close.io Api Wrapper - LLS Internet GmbH - Loopline Systems | ||
* | ||
* @link https://github.com/loopline-systems/closeio-api-wrapper for the canonical source repository | ||
* @copyright Copyright (c) 2014 LLS Internet GmbH - Loopline Systems (http://www.loopline-systems.com) | ||
* @license https://github.com/loopline-systems/closeio-api-wrapper/blob/master/LICENSE (MIT Licence) | ||
*/ | ||
|
||
namespace Tests\LooplineSystems\CloseIoApiWrapper\Library; | ||
|
||
use Tests\LooplineSystems\CloseIoApiWrapper\Library\Fake\ObjectHydrateHelperDemo; | ||
|
||
class ObjectHydrateHelperTraitTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var ObjectHydrateHelperDemo | ||
*/ | ||
private $testObject; | ||
|
||
public function setUp() | ||
{ | ||
$this->testObject = new ObjectHydrateHelperDemo(); | ||
} | ||
|
||
public function testHydrateWithoutData() | ||
{ | ||
$data = []; | ||
|
||
$this->testObject->hydrate($data); | ||
|
||
$this->assertNull($this->testObject->getFirst()); | ||
$this->assertNull($this->testObject->getSecond()); | ||
} | ||
|
||
public function testHydratePartialData() | ||
{ | ||
$data = [ | ||
'first' => 10, | ||
]; | ||
|
||
$this->testObject->hydrate($data); | ||
|
||
$this->assertEquals(10, $this->testObject->getFirst()); | ||
$this->assertNull($this->testObject->getSecond()); | ||
} | ||
|
||
public function testDoNotHydrateFalsyData() | ||
{ | ||
$this->testObject->hydrate(['first' => false]); | ||
$this->assertNull($this->testObject->getFirst()); | ||
|
||
$this->testObject->hydrate(['first' => 0]); | ||
$this->assertNull($this->testObject->getFirst()); | ||
|
||
$this->testObject->hydrate(['first' => null]); | ||
$this->assertNull($this->testObject->getFirst()); | ||
} | ||
|
||
public function testHydrateAllData() | ||
{ | ||
$data = [ | ||
'first' => 10, | ||
'second' => 'test', | ||
]; | ||
|
||
$this->testObject->hydrate($data); | ||
|
||
$this->assertEquals(10, $this->testObject->getFirst()); | ||
$this->assertEquals('test', $this->testObject->getSecond()); | ||
} | ||
|
||
public function testNonHydrateNonExistingData() | ||
{ | ||
$data = [ | ||
'third' => 10, | ||
]; | ||
|
||
$this->testObject->hydrate($data); | ||
|
||
$this->assertNull($this->testObject->getFirst()); | ||
$this->assertNull($this->testObject->getSecond()); | ||
} | ||
|
||
public function testHydrateWithCustomMappingData() | ||
{ | ||
$data = [ | ||
'third' => 10, | ||
]; | ||
|
||
$this->testObject->hydrate($data, [], ['setThird' => 'setFirst']); | ||
|
||
$this->assertEquals(10, $this->testObject->getFirst()); | ||
$this->assertNull($this->testObject->getSecond()); | ||
} | ||
} |