Skip to content
This repository has been archived by the owner on Nov 29, 2017. It is now read-only.

Fixes #3 Add possibility to pass construct argument #11

Open
wants to merge 1 commit into
base: behat3
Choose a base branch
from
Open
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ $mockGoutte = $this->mocker->mockService(
);
```

Usage with construct argument
```php
use Rezzza\MockExtension\Adapter\AtoumAdapter;

$mockGoutte = $this->mocker->mockService(
'my.goutte_driver',
new AtoumAdapter(
'\Behat\Mink\Driver\GoutteDriver',
null,
array($client)
)
);
```

Then follow the instructions of your mock engine to use the result

## Contribute
Expand Down
9 changes: 7 additions & 2 deletions src/Adapter/AtoumAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ class AtoumAdapter implements MockEngine

private $mockGenerator;

public function __construct($className, $config = null)
private $constructorArguments;

public function __construct($className, $config = null, array $constructorArguments = array())
{
$mockGenerator = new \mageekguy\atoum\mock\generator;

$this->className = $mockGenerator->getDefaultNamespace().$className;
$this->config = $config;
$this->constructorArguments = $constructorArguments;

$mockNamespacePattern = '/^' . preg_quote($mockGenerator->getDefaultNamespace()) . '\\\/i';

Expand All @@ -42,7 +45,9 @@ public function createMock()
call_user_func($this->config, $this->mockGenerator);
}

return new $this->className;
$class = new \ReflectionClass($this->className);

return $class->newInstanceArgs($this->constructorArguments);
}

private function hasConfig()
Expand Down