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

Easy testing for traits #685

Merged
merged 7 commits into from
Jan 31, 2017

Conversation

davedevelopment
Copy link
Collaborator

@davedevelopment davedevelopment commented Jan 29, 2017

Thought I'd have a crack at this to see what it looked like, a few people have whined about it in #200. It's not really what I'd consider a responsibility of a test double framework, but we have the tools to do it...

<?php

require "vendor/autoload.php";

Mockery::globalHelpers();

trait Foo {
    function foo() {
        return $this->doFoo();
    }

    abstract function doFoo();
}

$mock = mock(Foo::class);
$mock->allows()->doFoo()->andReturns('wooop');

var_dump($mock->foo());
  • Tests
  • Docs
  • Changelog

@davedevelopment davedevelopment changed the title Easy testing for traits WIP Easy testing for traits Jan 29, 2017
@davedevelopment davedevelopment mentioned this pull request Jan 30, 2017
@@ -467,6 +498,14 @@ protected function getAllMethods()
$methods = array_merge($methods, $class->getMethods());
}

foreach ($this->getTargetTraits() AS $trait) {
foreach ($trait->getMethods() as $method) {
if ($method->isAbstract()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been a while since I last looked at mockery's internals, but shouldn't you call isTrait here? If not, why do we need the isTrait method? I don't see it called anywhere.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't need calling there and therefore you are right, we don't need it for this implementation. I put it in there thinking I would, will back it out.

@davedevelopment
Copy link
Collaborator Author

I don't think this has any bearing on this functionality, but maybe someone else might think of something, there is an RFC currently under discussion to bring interfaces to traits - https://wiki.php.net/rfc/traits-with-interfaces.

@davedevelopment davedevelopment changed the title WIP Easy testing for traits Easy testing for traits Jan 30, 2017
@coveralls
Copy link

coveralls commented Jan 30, 2017

Coverage Status

Coverage increased (+0.9%) to 78.075% when pulling 8524260 on davedevelopment:testing-traits into 3c90be8 on padraic:master.

@davedevelopment davedevelopment merged commit ffc49d8 into mockery:master Jan 31, 2017
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

3 participants