Skip to content

Conversation

@Bilge
Copy link
Contributor

@Bilge Bilge commented Jan 21, 2017

There does not seem to be any compelling reason why void magic methods such __construct, __destruct or __clone should not be mockable. However, this PR only seeks to add __clone support.

As a bonus, added test namespace (MockeryTest) to Composer autoloader to save manually including test fixtures (and other test files) in tests.

Resolves #669.

Added test namespace to Composer autoloader.
@davedevelopment
Copy link
Collaborator

As mentioned on IRC in regards to BC, anyone currently cloning a Mockery mock would have to fix up their tests:

<?php

require "vendor/autoload.php";

class Foo {
    function __clone() {}
}

$double = Mockery::mock(Foo::class);

$second = clone ($double);
// PHP Fatal error:  Uncaught BadMethodCallException: Received Mockery_0_Foo::__clone(), but no expectations were specified in /Users/davem/src/mockery/library/Mockery/Loader/EvalLoader.php(34) : eval()'d code:774

You mentioned __destruct, doing the same for __destruct would have a similar behaviour. Any mock that mocks a type that defines __destruct would have to have a $mock->shouldReceive('__destruct') somewhere.

@patzerr
Copy link

patzerr commented Aug 25, 2017

hi,
@davedevelopment
the possibility to mock __construct on overloaded classes without breaking other unittests is possible, see the changes in library/Mockery/Mock.php::_mockery_constructorCalled in Pull Request #781
I guess doing the same for __cone could be done in the same way

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.

3 participants