Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
refs #67: add test to validate ObjectHydrateHelperTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
mavimo committed Apr 28, 2018
1 parent 95a3969 commit 4554aef
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 0 deletions.
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;
}
}
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());
}
}

0 comments on commit 4554aef

Please sign in to comment.