Skip to content

Instantly share code, notes, and snippets.

@ngyuki
Created April 23, 2013 14:43
Show Gist options
  • Save ngyuki/5444130 to your computer and use it in GitHub Desktop.
Save ngyuki/5444130 to your computer and use it in GitHub Desktop.
LegacyProxyTest.php
<?php
namespace ngyuki\example\LegacyProxy;
class LegacyProxy
{
public static function classof()
{
return get_called_class();
}
public function __call($name, $args)
{
return call_user_func_array($name, $args);
}
public function __get($name)
{
return constant($name);
}
}
class HogeClass
{
protected $legacyProxy;
public function setLegacyProxy(LegacyProxy $legacyProxy)
{
$this->legacyProxy = $legacyProxy;
}
public function now()
{
return date('Y-m-d H:i:s', $this->legacyProxy->time());
}
public function isCli()
{
return $this->legacyProxy->PHP_SAPI == 'cli';
}
}
class HogeTest extends \PHPUnit_Framework_TestCase
{
public function test_now()
{
$legacyProxy = \Phake::mock(LegacyProxy::classof());
$hoge = new HogeClass();
$hoge->setLegacyProxy($legacyProxy);
\Phake::when($legacyProxy)->time()->thenReturn(strtotime("2012-01-02 03:04:05"));
assertSame("2012-01-02 03:04:05", $hoge->now());
}
public function test_isCli()
{
$legacyProxy = \Phake::mock(LegacyProxy::classof());
$hoge = new HogeClass();
$hoge->setLegacyProxy($legacyProxy);
$legacyProxy->PHP_SAPI = 'cli';
assertTrue($hoge->isCli());
$legacyProxy->PHP_SAPI = 'apache2handler';
assertFalse($hoge->isCli());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment