Last active
December 25, 2015 14:09
-
-
Save mnapoli/6988778 to your computer and use it in GitHub Desktop.
Anonymous classes FTW
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MyTest extends PHPUnit_Framework_TestCase | |
{ | |
public function testSomeStuff() | |
{ | |
// Build my mock | |
$mock = new class extends CrawlerInterface { | |
public function crawl($url) { | |
return ['some', 'data']; | |
} | |
} (); | |
// Do my test | |
$myService = new MyService($mock); | |
$this->assertTrue($myService->foo()); | |
} | |
} |
MarcelloDuarte
commented
Oct 16, 2013
phpspec/prophecy could take advantage of anon classes in its class generator, in that it would not have to find unique mock class names.
@docteurklein no it cannot, as the RFC has been rejected
@stof yeah :) I should have said: "could have had".
cause mt_rand is definitly not the best: https://github.com/phpspec/prophecy/blob/master/src/Prophecy/Doubler/NameGenerator.php#L48
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment