Skip to content

Instantly share code, notes, and snippets.

View shupp's full-sized avatar

Bill Shupp shupp

  • MasterClass
  • South San Francisco, CA
View GitHub Profile
<?php
/**
* Cookie helper for dealing with Zend Http responses.
*
* @author Bill Shupp <hostmaster@shupp.org>
* @copyright 2010 Bill Shupp
* @license http://www.opensource.org/licenses/bsd-license.php FreeBSD
*/
class MS_Cookie
diff --git a/public_html/index.php b/public_html/index.php
index 2d6a659..9fba63c 100644
--- a/public_html/index.php
+++ b/public_html/index.php
@@ -3,9 +3,26 @@
require_once '../RandomString.php';
require_once 'HTML/QuickForm.php';
+
+
@shupp
shupp / gist:310433
Created February 21, 2010 18:00
Dependecy Injection Example1
<?php
// WRONG
class Foo1
{
public function bar()
{
$cache = Cache::singleton('Memcached');
$result = $cache->get('keyname');
// do some stuff with the result
}
@shupp
shupp / gist:310459
Created February 21, 2010 18:51
Example for attaching mocked dependencies
<?php
class Auth_Driver_OpenIDTest extends PHPUnit_Framework_TestCase
{
protected function getCache()
{
return $this->getMock('stdClass', array('get', 'set'));
}
protected function getUserClient()
{
@shupp
shupp / gist:310488
Created February 21, 2010 19:35
Example of code coverage igore annotations
<?php
class Foo
{
// @codeCoverageIgnoreStart
protected function getCache()
{
return Cache::singleton('MyCacheDriver');
}
// @codeCoverageIgnoreEnd
}
<?php
$base = dirname(__FILE__);
set_include_path("{$base}:{$base}/tests:" . get_include_path());
require_once 'PHPUnit/Util/Filter.php';
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
require_once 'PHPUnit/TextUI/Command.php';
php runTests.php --coverage-html coverage OpenID_AllTests
<?php
// PHP version of SimpleGeo's foursquare integration example:
// http://blog.simplegeo.com/2010/07/09/explore-your-foursquare-checkins-on-a-map-with-simplegeo/
//
// by Bill Shupp
// http://blog.shupp.org/2010/07/10/importing-foursquare-checkins-into-simplegeo-with-php/
require_once 'Services/SimpleGeo.php';
<?php
require_once 'ControllerTestCase.php';
require_once APPLICATION_PATH . '/controllers/ErrorController.php';
class ErrorControllerTest extends ControllerTestCase
{
public function test404Action()
{
$this->getRequest()->setMethod('GET');
<?php
// Example check at the top of your application for enabling profiling
if (isset($_SERVER['WWW_PROFILE']) && extension_loaded('xhprof')) {
$xproflib = APPLICATION_PATH . '/../public/build/xhprof/xhprof_lib';
include_once $xproflib . '/utils/xhprof_lib.php';
include_once $xproflib . '/utils/xhprof_runs.php';
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
function stop_xhprof_profiling()