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 #4 from facile-it/refactor/proxy-interface
Define new Stub object for methods and relative return values
- Loading branch information
Showing
21 changed files
with
384 additions
and
18 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,8 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Moka\Exception; | ||
|
||
class InvalidArgumentException extends \InvalidArgumentException | ||
{ | ||
} |
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,35 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Moka\Factory; | ||
|
||
use Moka\Exception\InvalidArgumentException; | ||
use Moka\Stub\Stub; | ||
use Moka\Stub\StubSet; | ||
|
||
/** | ||
* Class StubFactory | ||
* @package Moka\Factory | ||
*/ | ||
class StubFactory | ||
{ | ||
/** | ||
* @param array $methodsWithValues | ||
* @return StubSet|Stub[] | ||
* | ||
* @throws InvalidArgumentException | ||
*/ | ||
public static function fromArray(array $methodsWithValues): StubSet | ||
{ | ||
$stubSet = new StubSet(); | ||
foreach ($methodsWithValues as $methodName => $methodValue) { | ||
try { | ||
$stubSet->add(new Stub($methodName, $methodValue)); | ||
} catch (\Error $error) { | ||
throw new InvalidArgumentException($error->getMessage()); | ||
} | ||
} | ||
|
||
return $stubSet; | ||
} | ||
} |
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,45 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Moka\Stub; | ||
|
||
class Stub | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $methodName; | ||
|
||
/** | ||
* @var mixed | ||
*/ | ||
private $methodValue; | ||
|
||
/** | ||
* Stub constructor. | ||
* @param string $methodName | ||
* @param mixed $methodValue | ||
*/ | ||
public function __construct(string $methodName, $methodValue) | ||
{ | ||
$this->methodName = $methodName; | ||
$this->methodValue = $methodValue; | ||
} | ||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getMethodName(): string | ||
{ | ||
return $this->methodName; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getMethodValue() | ||
{ | ||
return $this->methodValue; | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Moka\Stub; | ||
|
||
use Moka\Exception\InvalidArgumentException; | ||
use PhpCollection\Set; | ||
|
||
/** | ||
* Class StubSet | ||
* @package Moka\Stub | ||
*/ | ||
final class StubSet extends Set | ||
{ | ||
/** | ||
* @param Stub $elem | ||
* @return void | ||
* | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function add($elem) | ||
{ | ||
if (!$elem instanceof Stub) { | ||
throw new InvalidArgumentException( | ||
sprintf( | ||
'The first parameter must be an instance of %s, %s given', | ||
Stub::class, | ||
gettype($elem) | ||
) | ||
); | ||
} | ||
|
||
parent::add($elem); | ||
} | ||
} |
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
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
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
Oops, something went wrong.