Skip to content

Instantly share code, notes, and snippets.

@icambridge
icambridge / gist:1652433
Created January 21, 2012 11:25
Mock Response
<?php
namespace app\tests\mocks\action;
class MockControllerResponse extends \lithium\action\Response {
public $hasRendered = false;
public function render() {
$this->hasRendered = true;
@icambridge
icambridge / gist:1652436
Created January 21, 2012 11:29
Controller Test
<?php
namespace app\tests\cases\controllers;
use app\controllers\ArticlesController;
use app\tests\mocks\controllers\MockArticlesController;
use lithium\action\Request;
class ArticlesControllerTest extends \lithium\test\Unit {
@icambridge
icambridge / gist:1652444
Created January 21, 2012 11:32
Mock Model
<?php
protected $_classes = array(
'media' => 'lithium\net\http\Media',
'router' => 'lithium\net\http\Router',
'response' => 'lithium\action\Response',
'articles' => '\app\models\Articles'
);
public function archives() {
$articlesClass = $this->_classes['articles'];
<?php
protected $_classes = array(
'media' => 'lithium\net\http\Media',
'router' => 'lithium\net\http\Router',
'response' => 'app\tests\mocks\action\MockControllerResponse',
'articles' => '\app\tests\mocks\models\Articles'
);
@icambridge
icambridge / gist:1652449
Created January 21, 2012 11:34
Mock Model Class
<?php
namespace app\tests\mocks\models;
use lithium\data\collection\RecordSet;
class Articles extends \app\models\Articles {
public static function find($type = 'all', array $options = array()) {
@icambridge
icambridge / gist:1654260
Created January 21, 2012 22:22
Mock Request
<?php
namespace app\tests\mocks\action;
class Request extends \lithium\action\Request
{
public function _base() {
$this->_base = '/';
}
@icambridge
icambridge / gist:1654434
Created January 21, 2012 23:01
Phing build file
<?xml version="1.0"?>
<project name="lithium-app" default="main">
<target name="main">
<taskdef classname="Li3_TestTask" name="li3test" />
<li3test li3Base="." tests="app\tests" />
</target>
</project>
@icambridge
icambridge / worker.php
Created February 5, 2012 11:22
Basic Worker
<?php
define('NET_GEARMAN_JOB_PATH', __DIR__);
require_once ('Net/Gearman/Worker.php');
try
{
print("[Gearman] starting worker...");
$worker = new Net_Gearman_Worker(array('127.0.0.1:4730'));
$worker->addAbility('Example');
$worker->beginWork();
@icambridge
icambridge / Example.php
Created February 5, 2012 11:31
Example Gearman Job
<?php
class Net_Gearman_Job_Example extends Net_Gearman_Job_Common
{
public function run ($arg)
{
print $arg.PHP_EOL;
}
}
@icambridge
icambridge / client.php
Created February 5, 2012 11:36
Gearman Client
<?php
require_once ('Net/Gearman/Client.php');
$client = new Net_Gearman_Client(array('127.0.0.1:4730'));
$client->Example("Hello Universe");