Skip to content

Instantly share code, notes, and snippets.

@guiled
guiled / testMultiMock
Created July 3, 2012 21:59
atoum and mock power! how to pass the same mocked method to different mocked classes
// code sample to instantiate a mock with the same method mocks from an other mocked class
function testMultiMock() {
$this
->if($test = new \mock\author\project\class)
->and($controller = $test->getMockController())
->and($test->getMockController()->instantiate = function () use ($controller) {
$instance = new \mock\author\project\class;
$instance->setMockController($controller);
return $instance;
@guiled
guiled / calledoncemock.php
Created August 16, 2012 09:34
Atoum, test if a mocked method is called only once
$this->assert
->if($mock = new \mock\MyClassToMock())
->if($test = myTestedClass($mock))
->and($myCounter = 0)
->and($mock->getMockController()->mockedMethod = function () use(&$myCounter) {doWhatever();$myCounter++;})
->and($test->myMethodThatUsesMockedMethod())
->number($myCounter)
->isEqualTo(1);
@guiled
guiled / testWithThen.php
Created August 23, 2012 15:45
Atoum and then feature
<?php
$this->assert
->if($inc = function (&$i) { $i++; return $i})
->and($i=0)
->then('test the inc')
->number($inc($i))
->isEqualTo(1)
->then('and test it with same context')
->number($inc($i))
<?php
namespace Application\Controller {
use Sohoa\Framework\Kit;
class Main extends Kit {
public function indexAction() {
@guiled
guiled / Application\Controller\Main.php
Created January 15, 2014 22:34
Custom Kit example in Sohoa Framework
namespace Application\Controller {
use Sohoa\Framework\Kit;
class Main extends Kit
{
public function indexAction()
{
$this->customKit->print();
@guiled
guiled / gist:498e1f613547266dbbce
Created June 20, 2014 15:06
Appcelerator good way to know if in portrait
// WTF On iOS for horizontal positions (iPad on a table) there are some bugs : in portrait mode e.source.isPortrait = false, Ti.Gesture.isPortrait = false and Ti.Gesture.orientation = 0 or 5 (even in portrait or landscape) !!!
// so take the old fashioned screen dimensions
Ti.Gesture.addEventListener('orientationchange', function (e) {
Alloy.Globals.isPortrait = (Ti.Platform.displayCaps.platformHeight > Ti.Platform.displayCaps.platformWidth);
});
global NMEs = [];
global ID = 0;
global FORCE = 1;
var enemies = getEnemies();
for (var nme in enemies) {
debug(nme + ' ' + getName(nme) + ' ' + getForce(nme));
@guiled
guiled / anim.js
Last active November 11, 2015 17:23 — forked from skypanther/anim.js
A fixed version for animated color in Titanium
// next two from http://stackoverflow.com/a/5624139/292947
function componentToHex(c) {
var hex = c.toString(16);
return hex.length == 1 ? "0" + hex : hex;
}
function rgbToHex(r, g, b) {
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}
@guiled
guiled / explode.php
Created November 25, 2014 09:04
IncredibleLines/UselessExplode
<?php
list($useless, $useless, $uesless, $code) = explode('/', $base);
@guiled
guiled / test.js
Created March 26, 2015 15:26
Appcelerator iOS calendar access crash with promises
// The following code doesn't work and makes your app crashes
// Because you MUST NOT use deferred code that access to calendar
Ti.Calendar.requestEventsAuthorization(function(e) {
Ti.API.info('Authorizations success : ' + e.success);
if (e.success) {
new Promise(function (resolve) {
Ti.API.info('A');
var cal = Ti.Calendar.getDefaultCalendar();
Ti.API.info('A cal id' + cal.id);
resolve(cal);