Ejemplo n.º 1
0
 public function testCallCreatesResponse()
 {
     $testOpts = array();
     $this->mockClient->shouldReceive('get')->with('/data/2.5/weather', $testOpts)->once()->andReturn($this->getMockResponseInterface());
     $response = $this->requester->call($testOpts);
     $this->assertInstanceOf('JCrowe\\OpenWeather\\Response', $response);
 }
Ejemplo n.º 2
0
 /**
  * 给某个mock的stub桩件增加新的mock方法
  * @param mock $stub
  * @param array $returns  ['methodname'=>ret] 格式
  * @return stub
  */
 protected function mockMethod($stub, $returns)
 {
     foreach ($returns as $method => $ret) {
         $stub->method($method)->will($this->returnCallback(function () use($ret) {
             if (is_callable($ret)) {
                 $arg = func_get_args();
                 return call_user_func_array($ret, $arg);
             } else {
                 return $ret;
             }
         }));
     }
     return $stub;
 }
Ejemplo n.º 3
0
 /**
  * tests the server responding to a cmd=lock when the account doesn't exist
  */
 public function testRespondsToLockUnknownAccount()
 {
     $this->validator->expects($this->once())->method('validateServer')->with($this->equalTo(array('ver' => '1', 'nut' => 'newNut', 'tif' => '4', 'qry' => 'sqrl?nut=newNut', 'sfn' => 'Example Server')), $this->equalTo('newNut'), $this->equalTo("1"))->will($this->returnValue(true));
     $this->validator->expects($this->once())->method('validateNut')->with($this->equalTo('newNut'), $this->equalTo('validIdentityKey'))->will($this->returnValue(\Trianglman\Sqrl\SqrlValidateInterface::VALID_NUT));
     $this->validator->expects($this->once())->method('validateSignature')->with($this->equalTo($this->base64UrlEncode("ver=1\r\ncmd=lock\r\nidk=" . $this->base64UrlEncode('validIdentityKey')) . $this->base64UrlEncode("ver=1\r\nnut=newNut\r\ntif=4\r\nqry=sqrl?nut=newNut\r\nsfn=Example Server")), $this->equalTo('validIdentityKey'), $this->equalTo('valid signature'))->will($this->returnValue(true));
     $this->validator->expects($this->once())->method('nutIPMatches')->with($this->equalTo('newNut'), $this->equalTo('192.168.0.5'))->will($this->returnValue(true));
     $this->storage->expects($this->once())->method('checkIdentityKey')->with($this->equalTo('validIdentityKey'))->will($this->returnValue(\Trianglman\Sqrl\SqrlStoreInterface::IDENTITY_UNKNOWN));
     $this->storage->expects($this->never())->method('lockIdentityKey');
     $this->storage->expects($this->never())->method('endSession');
     $this->generator->expects($this->once())->method('getNonce')->with($this->equalTo(0xc4), $this->equalTo('validIdentityKey'), $this->equalTo('newNut'))->will($this->returnValue('newerNut'));
     $this->generator->expects($this->once())->method('generateQry')->will($this->returnValue('sqrl?nut=newerNut'));
     $this->handler->parseRequest(array('nut' => 'newNut'), array('server' => $this->base64UrlEncode("ver=1\r\nnut=newNut\r\ntif=4\r\nqry=sqrl?nut=newNut\r\nsfn=Example Server"), 'client' => $this->base64UrlEncode("ver=1\r\ncmd=lock\r\nidk=" . $this->base64UrlEncode('validIdentityKey')), 'ids' => $this->base64UrlEncode('valid signature')), array('REMOTE_ADDR' => '192.168.0.5', 'HTTPS' => '1'));
     $this->assertEquals($this->base64UrlEncode("ver=1\r\nnut=newerNut\r\ntif=C4\r\nqry=sqrl?nut=newerNut\r\nsfn=Example Server"), $this->handler->getResponseMessage());
 }
Ejemplo n.º 4
0
    function testDateExpiry()
    {
        $cookie = new SimpleCookie("name", "value", "/path", "Mon, 18 Nov 2002 15:50:29 GMT");
        $this->assertTrue($cookie->isExpired("Mon, 18 Nov 2002 15:50:30 GMT"));
        $this->assertFalse($cookie->isExpired("Mon, 18 Nov 2002 15:50:28 GMT"));
    }
    function testAging()
    {
        $cookie = new SimpleCookie("name", "value", "/path", 200);
        $cookie->agePrematurely(199);
        $this->assertFalse($cookie->isExpired(0));
        $cookie->agePrematurely(2);
        $this->assertTrue($cookie->isExpired(0));
    }
}
mock::generatePartial('SimpleHttpRequest', 'PartialSimpleHttpRequest', array('_createSocket'));
class TestOfHttpRequest extends UnitTestCase
{
    function TestOfHttpRequest()
    {
        $this->UnitTestCase();
    }
    function testReadingBadConnection()
    {
        $socket =& new MockSimpleSocket($this);
        $socket->setReturnValue("isError", true);
        $request =& new PartialSimpleHttpRequest($this);
        $request->setReturnReference('_createSocket', $socket);
        $request->SimpleHttpRequest(new SimpleUrl("http://a.bad.page/"));
        $reponse =& $request->fetch();
        $this->assertTrue($reponse->isError());
Ejemplo n.º 5
0
 *
 * You should have received a copy of the GNU General Public License
 * along with Tuleap; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
class SVN_Apache_SvnrootConfTestEventManager extends EventManager
{
    public function processEvent($event_name, $params)
    {
        $project_row = array();
        $params['svn_apache_auth'] = null;
    }
}
require_once 'common/svn/SVN_Apache_SvnrootConf.class.php';
mock::generate('EventManager');
class SVN_Apache_SvnrootConfTest extends TuleapTestCase
{
    function setUp()
    {
        ForgeConfig::store();
        $GLOBALS['sys_name'] = 'Platform';
        $GLOBALS['sys_dbhost'] = 'db_server';
        $GLOBALS['sys_dbname'] = 'db';
        $GLOBALS['svn_prefix'] = '/bla';
        $GLOBALS['sys_dbauth_user'] = '******';
        $GLOBALS['sys_dbauth_passwd'] = 'dbauth_passwd';
    }
    function tearDown()
    {
        ForgeConfig::restore();