From 20bde16ba2db17fb646ba883b9c30482671dab21 Mon Sep 17 00:00:00 2001 From: "Herman J. Radtke III" Date: Mon, 27 Oct 2014 20:37:56 -0700 Subject: [PATCH] Resource class is not unit testable Hal\Resource should not directly call `new Link` in the constructor. Refactor class to use a factory method so the `Link` class can be mocked. Fixes #13 --- library/Hal/Resource.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/library/Hal/Resource.php b/library/Hal/Resource.php index 484a77b..450552c 100644 --- a/library/Hal/Resource.php +++ b/library/Hal/Resource.php @@ -59,6 +59,7 @@ class Resource extends AbstractHal * @var bool */ protected $jsonNumericCheck = self::JSON_NUMERIC_CHECK_OFF; + /** * * @param string $href @@ -70,11 +71,19 @@ class Resource extends AbstractHal public function __construct($href, array $data = array(), $title = null, $name = null, $hreflang = null) { $this->setLink( - new Link($href, 'self', $title, $name, $hreflang) + $this->createLink($href, 'self', $title, $name, $hreflang) ); $this->setData($data); } + /** + * @return Link + */ + protected function createLink($href, $rel, $title, $name, $hreflang) + { + return new Link($href, $rel, $title, $name, $hreflang); + } + /** * @return Link */