Created
February 17, 2015 23:20
-
-
Save gabrieljmj/26fed8fff56e65cd8b4f to your computer and use it in GitHub Desktop.
Simple Should port for PHP - complete framework https://github.com/GabrielJMJ/ShouldPHP
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
<?php | |
class Environment | |
{ | |
private $shouldState; | |
private $verbs = array('be', 'have'); | |
private $toTest; | |
public function __construct($toTest, $shouldState = false, $verb = null) | |
{ | |
$this->toTest = $toTest; | |
$this->shouldState = $shouldState; | |
$this->verb = $verb; | |
} | |
public function __get($property) | |
{ | |
if ($property === 'should') { | |
return new Environment($this->toTest, true); | |
} elseif (in_array($property, $this->verbs)) { | |
return new Environment($this->toTest, true, $property); | |
} | |
} | |
public function __call($method, $params) | |
{ | |
if ($this->shouldState) { | |
$method = $this->verb . ucfirst($method); | |
return $this->{$method}($params); | |
} | |
} | |
private function beEquals(array $params) | |
{ | |
return $this->toTest === $params[0]; | |
} | |
private function beAnInstanceOf(array $params) | |
{ | |
return $this->toTest instanceof $params[0]; | |
} | |
} |
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
<?php | |
$e = new Environment(new stdClass); | |
var_dump($e->should->be->anInstanceOf('stdClass')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment