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 / git-cstats
Created November 26, 2012 13:18
Get your git usage stats
#!/usr/bin/env php
<?php
$output = $commands = $status = null;
exec('ls /usr/lib/git-core', $commands, $status);
$commands = array_map(function($v) { return str_replace('git-', '', $v); }, $commands);
$output = $reflog = $status = null;
exec('git reflog', $reflog, $status);
printf(" \033[0;34m%s\033[0;32m" . PHP_EOL, 'Git Command Stats v0.1 - Stats computation based on git\'s reflog');
<?php
use
mageekguy\atoum,
mageekguy\atoum\report\fields\runner\failures\execute\macos
;
$script->addTestAllDirectory(__DIR__ . '/tests');
$cloverWriter = new atoum\writers\file('target/logs/atoum.coverage.xml');
$cloverReport = new atoum\reports\asynchronous\clover();
<?php
namespace PMSIpilot\Bundle\StambiaTestBundle\Console\Helper;
use Symfony\Component\Console\Helper\Helper;
class TableFormatterHelper extends Helper
{
/**
* @return string
*/
@jubianchi
jubianchi / 000-stdout.php
Created October 24, 2012 13:11
PHP & STDOUT
#!/usr/bin/env php
<?php
var_dump(defined('STDOUT'));
var_dump(@fopen('php://stdout', 'w'));
@jubianchi
jubianchi / lime.php
Created August 24, 2012 10:49
A tiny hacky loop mode for Lime
#!/usr/bin/env php
<?php
if(count($_SERVER['argv']) === 1 || null === getPath()) {
fwrite(STDOUT, "---> \033[0;31mUsage :\033[0m lime [--quiet] [--no-loop] <path/to/[test_file.php|test_directory]>" . PHP_EOL);
exit(1);
}
function getPath() {
$index = count($_SERVER['argv']) - 1;

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."

@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);
@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
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);
<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>