Created
June 22, 2016 19:45
-
-
Save fesor/c643e11a3191949642b90e9260163da1 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
<?php | |
class DefaultMyStuffMaker implements MyStuffMaker | |
{ | |
private $dependency; | |
public function __construct(SomeDependency $dependency) | |
{ | |
$this->dependency = $dependency; | |
} | |
public function makeStuff(string $someArg) : SomeResult | |
{ | |
// do some stuff | |
} | |
} |
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
<?php | |
class DefaultMyStuffMakerSpec extends ObjectSpec | |
{ | |
public function let(SomeDependency $dependency) | |
{ | |
$this->beConstructedWith($dependecy); | |
} | |
public function it_makes_stuff() | |
{ | |
$this->makeStuff()->shouldReturnAnInstanceOf(SomeResult::class) | |
} | |
} |
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
<?php | |
class LoggableMyStuffMaker implements MyStuffMaker | |
{ | |
private $next; | |
private $logger; | |
public function __construct(MyStuffMaker $maker, Logger $logger) | |
{ | |
$this->next = $next; | |
$this->logger = $logger; | |
} | |
public function makeStuff(string $someArg) : SomeResult | |
{ | |
$this->logger->log("Maker called") | |
$result = $this->next->makeStuff($someArg); | |
$this->logger->log("Maker return result"); | |
return $result; | |
} | |
} |
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
<?php | |
class DefaultMyStuffMakerSpec extends ObjectSpec | |
{ | |
public function let(MyStuffMaker $maker, Logger $logger) | |
{ | |
$this->beConstructedWith($maker, $logger); | |
} | |
public function it_makes_stuff(MyStuffMaker $maker, Logger $logger) | |
{ | |
$maker->makeStuff('stuff')->shouldBeCalled()->willReturn(new SomeResult()); | |
$logger->log(Argument::type('string'))->shouldBeCalledTimes(2); | |
$this->makeStuff('stuff'); | |
} | |
} |
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
<?php | |
interface MyStuffMaker | |
{ | |
public function makeStuff(string $someArg) : SomeResult | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment