Last active
June 9, 2019 14:30
-
-
Save tzmfreedom/18b784df85559b2ba90ce99a27185f95 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 MailMockStreamWrapper | |
{ | |
private $content = ''; | |
private $position = 0; | |
public function stream_open($path) | |
{ | |
stream_wrapper_restore("file"); | |
$content = file_get_contents($path); | |
$this->content = str_replace("mail", "Mock::mail", $content); | |
return true; | |
} | |
public function stream_read($count) | |
{ | |
$ret = substr($this->content, $this->position, $count); | |
$this->position += strlen($ret); | |
return $ret; | |
} | |
public function stream_stat() | |
{ | |
return []; | |
} | |
public function stream_eof() | |
{ | |
return $this->position >= strlen($this->content); | |
} | |
} | |
class Mock | |
{ | |
public static function mail($to, $subject) | |
{ | |
echo "to => $to, subject => $subject"; | |
} | |
} | |
stream_wrapper_unregister("file"); | |
stream_wrapper_register("file", "MailMockStreamWrapper"); | |
require_once 'mail.php'; // => to => hoge, subject => fuga |
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 | |
mail("hoge", "fuga"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment