Skip to content

Instantly share code, notes, and snippets.

@matsu-chara
Created April 26, 2016 10:25
Show Gist options
  • Save matsu-chara/b203978ed269f14393ca5781c8799722 to your computer and use it in GitHub Desktop.
Save matsu-chara/b203978ed269f14393ca5781c8799722 to your computer and use it in GitHub Desktop.
<?php
abstract class Mofu {
abstract protected function isNyan();
public function mofureyo() {
if($this->isNyan() === true) {
return "mofure";
} else {
return "mofuruna";
}
}
}
trait Nyan {
protected function isNyan() {
return true;
}
}
class MofuImpl extends Mofu {
use Nyan;
}
echo "普通のコード\n";
$mofu = new MofuImpl();
echo $mofu->mofureyo()."\n";
trait MockNyan {
protected function isNyan() {
return false;
}
}
class MockMofuImpl extends Mofu {
use MockNyan;
}
echo "テストコード\n";
$mofu = new MockMofuImpl();
echo $mofu->mofureyo()."\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment