Skip to content

Instantly share code, notes, and snippets.

View clemherreman's full-sized avatar

Clement Herreman clemherreman

  • Exotec
  • Lille, France
View GitHub Profile
@clemherreman
clemherreman / Company.php
Created August 26, 2010 09:16
Symfony getter overloading
<?php
/**
* Company
*
* This class has been auto-generated by the Doctrine ORM Framework
*
* @package winston
* @subpackage model
* @author Clement Herreman <clement@activcompany.fr>
@clemherreman
clemherreman / dateproblem.php
Created April 4, 2011 08:02
Date WTF in PHP
<?php
$badDate = '2010-13-03';
$date = DateTime::createFromFormat('Y-m-d', $badDate);
var_dump($date);
/*
object(DateTime)#284 (3) {
["date"]=>
string(19) "2011-01-03 10:01:20"
@clemherreman
clemherreman / 1_Person.class.php
Created April 22, 2011 09:50
PHP WTF of the day
<?php
class Person
{
private $phone;
private $name;
public function __construct($name, $phone)
{
var_dump($name);
var_dump($phone);
@clemherreman
clemherreman / DocumentIdentificationForm.php
Created May 5, 2011 12:04
How to add business logic on form save
<?php
class DocumentIdentificationForm extends DocumentForm
{
protected function doUpdateObject($values)
{
parent::doUpdateObject($values);
if ($values['author_id'])
$this->getObject()->setStatusId(Doctrine_Core::getTable('Status')->getIdentifiedStatus());
else
@clemherreman
clemherreman / wtf.php
Created May 6, 2011 14:30
PHP WTF of the day #2
<?php
function foo()
{
return bar;
}
echo foo(); // outputs 'bar'. And no error/exception, only a small warning.
@clemherreman
clemherreman / BatchDownloadTest.php
Created May 10, 2011 15:35
Unit testing exceptions
<?php
$t->diag('->run()');
$message = "->run() lance une exception si le BatchDownload n'est pas initialisé";
try
{
$bd->run();
$t->fail($message);
}
catch (Exception $e)
{
@clemherreman
clemherreman / test.php
Created May 13, 2011 13:39
How to partially mock an existing object
<?php
$documentExtractor = new DocumentExtractor(
$ftpDir,
sfConfig::get('sf_test_dir').'/web/documents'
);
$mock = m::mock($documentExtractor);
$mock->shouldReceive('getDistantControlDir')
->with(true)
->andThrow('sfException', 'Mock exception');
@clemherreman
clemherreman / gist:1025057
Created June 14, 2011 14:57
example of DI
<?php
class webserviceMagento {
public construct($dependency = null)
{
if (is_null($dependency))
{
// Instanciate your dependencies by yourself!
}
}
}
@clemherreman
clemherreman / Test.class.php
Created June 15, 2011 13:56
Static using non-static
<?php
class Test
{
private $message;
public function __construct()
{
$this->message = 'Omg this can be called?';
}
@clemherreman
clemherreman / CapWebndfTestFunctionnal.class.php
Created June 21, 2011 15:12
Login during functional test on symfony1.4
<?php
class CapWebndfTestFunctionnal extends sfTestFunctional
{
/**
* Login as a user
* @param string $username User's username
*/
public function signInAs($username)
{