Skip to content

Commit

Permalink
Merge pull request mockery#70 from innsand/master
Browse files Browse the repository at this point in the history
Fix for \Mockery inclusion with setIncludePath.
  • Loading branch information
padraic committed Aug 11, 2012
2 parents ab9e69d + 08c6905 commit 6da54b5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,12 @@ replace the previously defined default. This is useful so you can setup default
mocks in your unit test setup() and later tweak them in specific tests as
needed.

mock()
getMock()

Returns the current mock object from an expectation chain. Useful where
you prefer to keep mock setups as a single statement, e.g.

$mock = \Mockery::mock('foo')->shouldReceive('foo')->andReturn(1)->mock();
$mock = \Mockery::mock('foo')->shouldReceive('foo')->andReturn(1)->getMock();


Argument Validation
Expand Down
15 changes: 13 additions & 2 deletions library/Mockery/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function unregister()
public function loadClass($className)
{
if ($className === 'Mockery') {
require 'Mockery.php';
require $this->getFullPath('Mockery.php');
return;
}
if (null === $this->_namespace
Expand All @@ -138,7 +138,18 @@ public function loadClass($className)
$fileName = str_replace($this->_namespaceSeparator, DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . $this->_fileExtension;
require ($this->_includePath !== null ? $this->_includePath . DIRECTORY_SEPARATOR : '') . $fileName;
require $this->getFullPath($fileName);
}
}

/**
* Returns full path for $fileName if _includePath is set, or leaves as-is for PHP's internal search in 'require'.
*
* @param string $fileName relative to include path.
* @return string
*/
private function getFullPath($fileName)
{
return ($this->_includePath !== null ? $this->_includePath . DIRECTORY_SEPARATOR : '') . $fileName;
}
}

0 comments on commit 6da54b5

Please sign in to comment.