Skip to content
This repository has been archived by the owner on Mar 24, 2020. It is now read-only.

Inheriting specifications #96

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/PHPSpec2/Runner/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function runSpecification(Node\Specification $specification)

public function runExample(Node\Example $example, Matcher\MatchersCollection $matchers)
{
$context = $example->getFunction()->getDeclaringClass()->newInstance();
$context = $this->getExampleContext($example);
$collaborators = new Prophet\CollaboratorsCollection($this->presenter);

foreach ($this->getExampleInitializers() as $initializer) {
Expand Down Expand Up @@ -231,4 +231,20 @@ final public function errorHandler($level, $message, $file, $line)
// error reporting turned off or more likely suppressed with @
return false;
}

/**
* Returns an instance of the class in which context we run the example
* @param \PHPSpec2\Loader\Node\Example $example
* @return mixed
*/
private function getExampleContext(Node\Example $example)
{
if (null !== $example->getSpecification()){
$declaringClass = $example->getSpecification()->getClass();
}
else {
$declaringClass = $example->getFunction()->getDeclaringClass();
}
return $declaringClass->newInstance();
}
}