Permalink
Browse files

Still rename stub stuff into prophet

  • Loading branch information...
1 parent 7e32c47 commit da38787ce49dff767aa2133f0393cd71e5464348 @MarcelloDuarte MarcelloDuarte committed Sep 11, 2012
@@ -14,7 +14,7 @@ function it_will_complain_if_no_matchers_registered()
}
/**
- * @param Prophet $matcher mock of PHPSpec2\Matcher\MatcherInterface
+ * @param Prophet $matcher dummy of PHPSpec2\Matcher\MatcherInterface
*/
function it_will_complain_if_matcher_is_not_found($matcher)
{
@@ -24,7 +24,7 @@ function it_will_complain_if_matcher_is_not_found($matcher)
}
/**
- * @param Prophet $matcher mock of PHPSpec2\Matcher\MatcherInterface
+ * @param Prophet $matcher stub of PHPSpec2\Matcher\MatcherInterface
*/
function it_will_return_matcher_if_found($matcher)
{
@@ -1,6 +1,6 @@
<?php
-namespace spec\PHPSpec2\Stub;
+namespace spec\PHPSpec2\Prophet;
use PHPSpec2\Specification;
@@ -7,7 +7,7 @@
use PHPSpec2\Event\ExampleEvent;
use PHPSpec2\Console\IO;
use Symfony\Component\Console\Helper\DialogHelper;
-use PHPSpec2\Exception\Stub\ClassDoesNotExistsException;
+use PHPSpec2\Exception\Prophet\ClassDoesNotExistsException;
class ClassNotFoundListener implements EventSubscriberInterface
{
@@ -22,7 +22,7 @@ public function resolveSingle($argument)
}
if ($argument instanceof Prophet) {
- $argument = $argument->getStubSubject();
+ $argument = $argument->getProphetSubject();
}
if ($argument instanceof MockProxyInterface) {
@@ -41,17 +41,17 @@ public function isAMockOf($classOrInterface)
public function should()
{
- return new Verification\Positive($this->getStubSubject(), $this->matchers, $this->resolver);
+ return new Verification\Positive($this->getProphetSubject(), $this->matchers, $this->resolver);
}
public function shouldNot()
{
- return new Verification\Negative($this->getStubSubject(), $this->matchers, $this->resolver);
+ return new Verification\Negative($this->getProphetSubject(), $this->matchers, $this->resolver);
}
- public function callOnStub($method, array $arguments = array())
+ public function callOnProphet($method, array $arguments = array())
{
- if (null === $this->getStubSubject()) {
+ if (null === $this->getProphetSubject()) {
throw new ProphetException(sprintf(
'Call to a member function <value>%s()</value> on a non-object.',
$method
@@ -63,42 +63,42 @@ public function callOnStub($method, array $arguments = array())
// if subject is an instance with provided method - call it and stub the result
if ($this->isSubjectMethodAccessible($method)) {
- $returnValue = call_user_func_array(array($this->getStubSubject(), $method), $arguments);
+ $returnValue = call_user_func_array(array($this->getProphetSubject(), $method), $arguments);
return new static($returnValue, $this->matchers, $this->mockers, $this->resolver);
}
// if subject is a mock - return method expectation stub
- if ($this->getStubSubject() instanceof MockProxyInterface) {
- return $this->getStubSubject()->mockMethod($method, $arguments, $this->resolver);
+ if ($this->getProphetSubject() instanceof MockProxyInterface) {
+ return $this->getProphetSubject()->mockMethod($method, $arguments, $this->resolver);
}
- throw new MethodNotFoundException($this->getStubSubject(), $method);
+ throw new MethodNotFoundException($this->getProphetSubject(), $method);
}
- public function setToStub($property, $value = null)
+ public function setToProphet($property, $value = null)
{
$value = $this->resolver->resolve($value);
if ($this->isSubjectPropertyAccessible($property, true)) {
- return $this->getStubSubject()->$property = $value;
+ return $this->getProphetSubject()->$property = $value;
}
- throw new PropertyNotFoundException($this->getStubSubject(), $property);
+ throw new PropertyNotFoundException($this->getProphetSubject(), $property);
}
- public function getFromStub($property)
+ public function getFromProphet($property)
{
if ($this->isSubjectPropertyAccessible($property)) {
- $returnValue = $this->getStubSubject()->$property;
+ $returnValue = $this->getProphetSubject()->$property;
return new static($returnValue, $this->matchers, $this->mockers, $this->resolver);
}
- throw new PropertyNotFoundException($this->getStubSubject(), $property);
+ throw new PropertyNotFoundException($this->getProphetSubject(), $property);
}
- public function getStubSubject()
+ public function getProphetSubject()
{
if (is_object($this->subject) && $this->subject instanceof LazySubjectInterface) {
$this->subject = $this->subject->getInstance();
@@ -107,17 +107,17 @@ public function getStubSubject()
return $this->subject;
}
- public function getStubMatchers()
+ public function getProphetMatchers()
{
return $this->matchers;
}
- public function getStubMockers()
+ public function getProphetMockers()
{
return $this->mockers;
}
- public function getStubResolver()
+ public function getProphetResolver()
{
return $this->resolver;
}
@@ -134,53 +134,53 @@ public function __call($method, array $arguments = array())
return call_user_func_array(array($this->shouldNot(), $matcherName), $arguments);
}
- return $this->callOnStub($method, $arguments);
+ return $this->callOnProphet($method, $arguments);
}
public function __set($property, $value = null)
{
- return $this->setToStub($property, $value);
+ return $this->setToProphet($property, $value);
}
public function __get($property)
{
- return $this->getFromStub($property);
+ return $this->getFromProphet($property);
}
private function isSubjectMethodAccessible($method)
{
- if (!is_object($this->getStubSubject())) {
+ if (!is_object($this->getProphetSubject())) {
return false;
}
- if (method_exists($this->getStubSubject(), '__call')) {
+ if (method_exists($this->getProphetSubject(), '__call')) {
return true;
}
- if (!method_exists($this->getStubSubject(), $method)) {
+ if (!method_exists($this->getProphetSubject(), $method)) {
return false;
}
- $methodReflection = new ReflectionMethod($this->getStubSubject(), $method);
+ $methodReflection = new ReflectionMethod($this->getProphetSubject(), $method);
return $methodReflection->isPublic();
}
private function isSubjectPropertyAccessible($property, $withValue = false)
{
- if (!is_object($this->getStubSubject())) {
+ if (!is_object($this->getProphetSubject())) {
return false;
}
- if (method_exists($this->getStubSubject(), $withValue ? '__set' : '__get')) {
+ if (method_exists($this->getProphetSubject(), $withValue ? '__set' : '__get')) {
return true;
}
- if (!property_exists($this->getStubSubject(), $property)) {
+ if (!property_exists($this->getProphetSubject(), $property)) {
return false;
}
- $propertyReflection = new ReflectionProperty($this->getStubSubject(), $property);
+ $propertyReflection = new ReflectionProperty($this->getProphetSubject(), $property);
return $propertyReflection->isPublic();
}
View
@@ -86,10 +86,10 @@ public function runExample(ReflectionMethod $example)
$className = substr($spec->getName(), (int)strrpos($spec->getName(), '\\') + 1);
$className = strtolower($className[0]) . substr($className, 1);
- $stub = new Prophet($subject, clone $this->matchers);
- $instance->$className = $instance->object = $stub;
+ $prophet = new Prophet($subject, clone $this->matchers);
+ $instance->$className = $instance->object = $prophet;
- $stubs = $this->getStubsForExample($instance, $example);
+ $prophets = $this->getProphetsForExample($instance, $example);
if (defined('PHPSPEC_ERROR_REPORTING')) {
$errorLevel = PHPSPEC_ERROR_REPORTING;
@@ -99,7 +99,7 @@ public function runExample(ReflectionMethod $example)
$oldHandler = set_error_handler(array($this, 'errorHandler'), $errorLevel);
try {
- $this->callMethodWithStubs($instance, $example, $stubs);
+ $this->callMethodWithProphets($instance, $example, $prophets);
Mockery::close();
$event = new ExampleEvent($example, ExampleEvent::PASSED);
@@ -149,59 +149,59 @@ public function wasAborted()
return $this->wasAborted;
}
- protected function getStubsForExample(Specification $instance, ReflectionMethod $example)
+ protected function getProphetsForExample(Specification $instance, ReflectionMethod $example)
{
- $stubs = array();
+ $prophets = array();
if (method_exists($instance, 'described_with')) {
$descriptor = new ReflectionMethod($instance, 'described_with');
- $stubs = $this->mergeStubsFromMethod($stubs, $descriptor);
- $this->callMethodWithStubs($instance, $descriptor, $stubs);
+ $prophets = $this->mergeProphetsFromMethod($prophets, $descriptor);
+ $this->callMethodWithProphets($instance, $descriptor, $prophets);
}
- return $this->mergeStubsFromMethod($stubs, $example);
+ return $this->mergeProphetsFromMethod($prophets, $example);
}
- protected function callMethodWithStubs(Specification $instance, ReflectionMethod $method, array $stubs)
+ protected function callMethodWithProphets(Specification $instance, ReflectionMethod $method, array $prophets)
{
$arguments = array();
foreach ($method->getParameters() as $parameter) {
- $arguments[] = $stubs[$parameter->getName()];
+ $arguments[] = $prophets[$parameter->getName()];
}
$method->invokeArgs($instance, $arguments);
}
- private function mergeStubsFromMethod(array $stubs, ReflectionMethod $method)
+ private function mergeProphetsFromMethod(array $prophets, ReflectionMethod $method)
{
- $stubs = $this->mergeStubsFromDocComment($stubs, $method->getDocComment());
+ $prophets = $this->mergeProphetsFromDocComment($prophets, $method->getDocComment());
foreach ($method->getParameters() as $parameter) {
- if (!isset($stubs[$parameter->getName()])) {
- $stubs[$parameter->getName()] = new Prophet(null, clone $this->matchers);
+ if (!isset($prophets[$parameter->getName()])) {
+ $prophets[$parameter->getName()] = new Prophet(null, clone $this->matchers);
}
}
- return $stubs;
+ return $prophets;
}
- private function mergeStubsFromDocComment(array $stubs, $comment)
+ private function mergeProphetsFromDocComment(array $prophets, $comment)
{
if (false === $comment || '' == trim($comment)) {
- return $stubs;
+ return $prophets;
}
foreach (explode("\n", $comment) as $line) {
$line = preg_replace('/^\/\*\*\s*|^\s*\*\s*|\s*\*\/$|\s*$/', '', $line);
- if (preg_match('#^@param(?: *[^ ]*)? *\$([^ ]*) *mock of (.*)$#', $line, $match)) {
- if (!isset($stubs[$match[1]])) {
- $stubs[$match[1]] = new Prophet(null, clone $this->matchers);
- $stubs[$match[1]]->isAMockOf($match[2]);
+ if (preg_match('#^@param(?: *[^ ]*)? *\$([^ ]*) *(double|mock|stub|fake|dummy|spy) of (.*)$#', $line, $match)) {
+ if (!isset($prophets[$match[1]])) {
+ $prophets[$match[1]] = new Prophet(null, clone $this->matchers);
+ $prophets[$match[1]]->isAMockOf($match[3]);
}
}
}
- return $stubs;
+ return $prophets;
}
private function isExampleTestable(ReflectionMethod $example)

0 comments on commit da38787

Please sign in to comment.