Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework method stubbing, mocking #37

Merged
merged 8 commits into from
Oct 7, 2016
Merged

Rework method stubbing, mocking #37

merged 8 commits into from
Oct 7, 2016

Conversation

tomaszdurka
Copy link
Owner

@tomaszdurka tomaszdurka commented Oct 5, 2016

Allow more flexible method/function stubbing and mocking.

Allow:

$instance = new Foo();
$mocka->stubMethod($instance, 'bar');

EDIT:

Original idea has been postponed. It requires runkit support plus some preparations. Instead I went with preparations only. All the mechanics of how methods are overridden and where overrides are stored have been reworked.

There is central place (Manager) for all overrides. It will allow redefining single methods/functions in future using runkit. Code looks more understandable now.

Deprecation notes:

Some methods like #mockMethod, #unmockMethod are deprecated now. New way to override method is:

$mocka = new \Mocka\Mocka();
$date = $mocka->mockObject(\DateTime::class);
$spy = $date->getOverrides()->spy('add');
$stub = $date->getOverrides()->stub('format')->set('formatted');
/** @var DateTime $date */
$date->add(new DateInterval('PT1H'));
echo $date->format('U');
$this->assertSame(1, $spy->getCallCount());
$this->assertSame(1, $stub->getCallCount());
$this->assertSame('U', $stub->getInvocations()->getLast()->getArgument(0));

@tomaszdurka
Copy link
Owner Author

@alexispeter wanna review? :)

@tomaszdurka tomaszdurka self-assigned this Oct 5, 2016
@alexispeter
Copy link
Contributor

Sure

@tomaszdurka
Copy link
Owner Author

Will go ahead and merge this one. Release a tag and test it, please let me know if I should adjust some fixes - it's a but off-topic project so no priority.

@tomaszdurka tomaszdurka merged commit ce6e3cf into master Oct 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants