Skip to content

Commit

Permalink
Refactor away InstanceSubject
Browse files Browse the repository at this point in the history
Added unnecessary complexity to the interceptor and
partial components.
  • Loading branch information
dancras committed Aug 30, 2012
1 parent 610fcff commit 0101826
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 39 deletions.
32 changes: 0 additions & 32 deletions src/Doubles/Core/InstanceSubject.php

This file was deleted.

5 changes: 5 additions & 0 deletions src/Doubles/Core/Subject.php
Expand Up @@ -62,6 +62,11 @@ public function exists()
return interface_exists($this->fullyQualifiedName);
}

public static function fromInstance($object)
{
return new static('\\' . get_class($object), T_CLASS);
}

public function __construct($fullyQualifiedName, $type)
{
if ($type !== T_CLASS && $type !== T_INTERFACE) {
Expand Down
7 changes: 4 additions & 3 deletions src/Doubles/Doubles.php
Expand Up @@ -6,6 +6,7 @@
namespace Doubles;

use Doubles\Expectation\ExpectationComponent;
use Doubles\Partial\PartialComponent;
use Doubles\Stub\StubComponent;

/**
Expand Down Expand Up @@ -52,7 +53,7 @@ public static function noConstruct($fullyQualifiedTypeName)
*/
public static function partial($object)
{
$subject = new Core\InstanceSubject($object);
$subject = Core\Subject::fromInstance($object);

$testDouble = new Core\TestDouble;

Expand All @@ -61,13 +62,13 @@ public static function partial($object)
$expectationComponent = new ExpectationComponent;
$stubComponent = new StubComponent;
$mockComponent = new Mock\MockComponent;
$interceptorComponent = new Partial\InterceptorComponent($subject);
$interceptorComponent = new Partial\InterceptorComponent($object);

$expectationComponent->addExpecter($stubComponent);
$expectationComponent->addExpecter($mockComponent);
$expectationComponent->addExpecter($interceptorComponent);

$testDouble->addComponent(new Partial\PartialComponent($subject, $expectationComponent));
$testDouble->addComponent(new PartialComponent($object, $expectationComponent));
$testDouble->addComponent($expectationComponent);
$testDouble->addComponent($stubComponent);
$testDouble->addComponent($mockComponent);
Expand Down
4 changes: 2 additions & 2 deletions src/Doubles/Partial/InterceptorComponent.php
Expand Up @@ -41,9 +41,9 @@ public function isExpecting($methodName)
return array_key_exists($methodName, $this->callbacks);
}

public function __construct(\Doubles\Core\InstanceSubject $subject)
public function __construct($subjectInstance)
{
$this->instance = $subject->getInstance();
$this->instance = $subjectInstance;
}
}

4 changes: 2 additions & 2 deletions src/Doubles/Partial/PartialComponent.php
Expand Up @@ -28,10 +28,10 @@ public function whenMethodCalled($methodName, array $arguments)
}

public function __construct(
\Doubles\Core\InstanceSubject $subject,
$subjectInstance,
ExpectationComponent $expectationComponent
) {
$this->instance = $subject->getInstance();
$this->instance = $subjectInstance;
$this->expectationComponent = $expectationComponent;
}
}
Expand Down

0 comments on commit 0101826

Please sign in to comment.