phpspec/phpspec — pull request #335 by damonjones (2014-03-22 21:07:56+00:00)
Title: Allow instantiation via a static factory method

It's not currently possible to use a factory method to instantiate a subject (useful when you have a private constructor).

This PR addresses that, by introducing the new `beConstructedThrough()` method, which requires a callable and optional constructor arguments.

Example class:

```php
final class Example
{
private $name;

private function __construct($name)
{
$this->name = $name;
}

public static function createWithName($name)
{
return new self($name);
}

public function getName()
{
return $this->name;
}
}
```

```php
function it_can_be_constructed()
{
$this->beConstructedThrough('Example::createWithName', ['Damon']);
$this->shouldHaveType('Example');
$this->getName()->shouldEqual('Damon');
}
```

This implements the WIP feature/pull request that was originally made to the phpspec2 repository by @mathiasverraes: https://github.com/phpspec/phpspec2/pull/95