Skip to content

Instantly share code, notes, and snippets.

View jubianchi's full-sized avatar
🏳️‍🌈
nyan nyan nyan

Julien BIANCHI jubianchi

🏳️‍🌈
nyan nyan nyan
View GitHub Profile
@jubianchi
jubianchi / sf2_standalone_form.php
Created August 25, 2011 07:31
How to use Symfony2 Form Component Standalone
<?php
namespace Standalone\Form;
use \Symfony\Component\HttpFoundation as SHttp;
use \Symfony\Component\Form as SForm;
use \Symfony\Component\DependencyInjection as SDI;
use \Symfony\Bridge as SBridge;
//Register all your autoload function here
//...
@jubianchi
jubianchi / gist:1297545
Created October 19, 2011 05:44
Get the computed CSS styles of an element
(function(){
var sel = prompt('Selector...'),
elt = $(sel),
gcs = ('getComputedStyle' in window ? getComputedStyle : document.defaultView.getComputedStyle),
cs = gcs(elt.get(0), null),
css = [],
scss = ''
space = '&nbsp;&nbsp;&nbsp;&nbsp;';
if(window.console) console.group(sel);
@jubianchi
jubianchi / .gitconfig
Created October 31, 2011 16:43
My Git Aliases
[alias]
graph = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
summary = log --summary --name-only --abbrev-commit --color --color-words --date=relative
#If you are using Tig as your core.pager
[alias]
graph = log --graph --pretty=format:'%h -%d %s (%cr) <%an>' --abbrev-commit --no-color --date=relative
summary = log --summary --name-only --abbrev-commit --no-color --date=relative
@jubianchi
jubianchi / gist:1550214
Created January 2, 2012 10:33
Debugger vos script PHP-Cli avec XDebug à la demande
## Lancez cette commande dans un tertminal
echo -e '#!/bin/sh\nphp -dxdebug.remote_autostart=On $*' | sudo tee /usr/local/bin/xdebug && sudo chmod +x /usr/local/bin/xdebug
##Usage :
#Debugger un script PHP
xdebug mon_script.php
#Debugger une task Symfony
xdebug ./symfony ns:command
## Lancez cette commande dans un tertminal
cat <<EOT | sudo tee /usr/local/bin/which_sf && sudo chmod +x /usr/local/bin/which_sf
#!/bin/sh
./symfony | perl -ne 'if( /^([a-zA-Z0-9\-]+)/ ) { \$first = \$1; } elsif ( /^\s*(:[a-zA-Z0-9\-]+)/ ) { print \$first . \$1 . "\n"; }' | grep \$1
EOT
##
##Usage :
which_sf foo
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.jubianchi</groupId>
<artifactId>foo</artifactId>
<name>foo</name>
<version>0.1-alpha</version>
<packaging>pom</packaging>
<build>
@jubianchi
jubianchi / .atoum.php
Created July 30, 2012 20:30
atoum test
<?php
use \mageekguy\atoum;
$stdOutWriter = new atoum\writers\std\out();
$cliReport = new atoum\reports\realtime\cli();
$cliReport->addWriter($stdOutWriter);
$xunit = new atoum\reports\asynchronous\xunit();
$writer = new atoum\writers\file('atoum.xml');
$xunit->addWriter($writer);
@jubianchi
jubianchi / regexp
Created July 31, 2012 09:01
My Regexp
/^([^(?<!(?:ABC|DEF))\s].*)/
ABC|foo
DEF|foo
GHI|foo
JKL|foo
==> Matches all lines not starting with wors ABC or DEF
--------------------------------------------------------------------------------------
@jubianchi
jubianchi / .atoum.php-dist
Created August 7, 2012 12:18
Conditionnal configuration validation
<?php
use \mageekguy\atoum;
define('COVERAGE_TITLE', 'Config');
define('COVERAGE_DIRECTORY', './coverage');
define('COVERAGE_WEB_PATH', 'http://%host%/coverage');
if(false === is_dir(COVERAGE_DIRECTORY))
{
mkdir(COVERAGE_DIRECTORY, 0777, true);

Tests unitaires et Adapters en PHP avec atoum

Nous avons récemment eu quelques discussions sur les Adapters sur le salon IRC de atoum (pour rappel, celui-ci se trouve sur les serveurs Freenode, canal ##atoum). Plusieurs questions ont été traitées : nous avons parlé de l'utilité de ces Adapters, des possibilités qu'ils offrent dans le cadre de tests unitaires mais également des inconvénients et des bonnes pratiques à mettre en place pour bien les utiliser. Je vais donc tenter ici d'eclaircir ces quelques points à travers des exemples relativement simples. J'utiliserais atoum pour les tests qui seront écrits pour une classe gérant une connexion à un serveur FTP.

Le pattern Adapter

Avant de commencer, nous allons faire un petit rappel sur le design pattern Adapter. Voici un extrait de la définition donnée par Wikipedia :

"The adapter translates calls to its interface into calls to the original interface, and the amount of code necessary to do this is typically small."