-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from Textalk/mockclasses
Added mock classes for better testing.
- Loading branch information
Showing
6 changed files
with
78 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Textalk\WebshopClient; | ||
|
||
/** | ||
* Interface for API Connections. | ||
*/ | ||
interface ConnectionInterface { | ||
public function getApiClass($class); | ||
public function getApiInstance($class, $uid); | ||
public function getUri(); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Textalk\WebshopClient\Mock; | ||
|
||
/** | ||
* A mock connection to be used when testing. | ||
*/ | ||
class ConnectionMock implements \Textalk\WebshopClient\ConnectionInterface { | ||
|
||
public $classes = array(); // Array of ApiClassMock instances | ||
public $instances = array(); // Array of ApiInstanceMock instance | ||
|
||
public function getApiClass($class) { | ||
if (isset($this->classes[$class])) return $this->classes[$class]; | ||
throw new Exception("Unexpected class: $class"); | ||
} | ||
|
||
public function getApiInstance($class, $uid) { | ||
if (isset($this->instances[$class][$uid])) return $this->classes[$class][$uid]; | ||
throw new Exception("Unexpected instance. Class: $class UID: $uid"); | ||
} | ||
|
||
public function getUri() { return 'mock://mock'; } | ||
|
||
public function __get($key) { | ||
if (isset($this->classes[$key])) return $this->classes[$key]; | ||
throw new Exception("Unexpected get: $key"); | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
namespace Textalk\WebshopClient\Mock; | ||
|
||
/** | ||
* A mock Tivoka client request class. | ||
*/ | ||
class RequestMock extends \Tivoka\Client\Request { | ||
|
||
public $target = null; | ||
|
||
/** | ||
* Mock sending data to target. | ||
* @param mixed $target Remote end-point definition | ||
*/ | ||
public function sendTo($target) { | ||
$this->target = $target; | ||
} | ||
|
||
} |
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