Last active
December 19, 2015 19:59
-
-
Save kevinjqiu/6010369 to your computer and use it in GitHub Desktop.
This file contains 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
<!-- product.php --> | |
<?php | |
class Product { | |
function __construct() { | |
} | |
} | |
?> | |
<!-- client.php --> | |
<?php | |
class Client { | |
public function __construct() { | |
$this->product = new Product(); <-- this is bad, because we can't mock it out in test | |
} | |
} | |
?> | |
<!-- factory.php --> | |
<?php | |
class Factory { | |
public function produce() { | |
return new Product(); | |
} | |
} | |
?> | |
<!-- client2.php --> | |
<?php | |
class Client2 { | |
public function __construct($factory=new Factory()) { | |
$this->product = $factory->produce(); | |
} | |
} | |
?> | |
<!-- test_client2.php --> | |
<?php | |
new Client2($someMockFactory); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment