Skip to content

Instantly share code, notes, and snippets.

@wowo
wowo / ModelTestCase.php
Created June 14, 2011 21:26
Model Test Case, which loads fixtures and builds database before each test
<?php
require_once(__DIR__ . "/../../../../app/AppKernel.php");
class ModelTestCase extends \PHPUnit_Framework_TestCase
{
protected $_application;
public function getContainer()
{
@wowo
wowo / config_test.yml
Created June 14, 2011 21:28
Doctrine sqlite in memory for tests purposes
doctrine:
dbal:
driver: pdo_sqlite
path: :memory:
memory: true
orm:
auto_generate_proxy_classes: true
auto_mapping: true
@rponte
rponte / gist:1051135
Last active March 10, 2023 00:08
A test is not a unit test if
A test is not an unit test if:
* it talks to the database
* it communicates across the network
* it touches the file system
* it can’t run at the same time as any of your other unit tests
* you have to do special things to your environment (such as editing config files) to run it
Tests that do these things aren’t bad. Often they are worth writing, and they can be written in a unit test harness. However, it is important to keep them separate from true unit tests so that we can run the unit tests quickly whenever we make changes.
--
by Michael Feathers
@mmacia
mmacia / test_undefined_offset_exception.php
Created July 5, 2011 10:31
How to catch an invalid array index offset as a native exception in PHP
<?php
/**
* this class shows how to override default PHP handler to catch undefined index errors
* and throw it as native exceptions, much more convenient way to work with object
* oriented programs.
*
* @author Moisés Maciá <[email protected]>
* @see http://codeup.net
*/
@neotohin
neotohin / php.snippets
Created August 12, 2011 17:46 — forked from aaroneaton/php.snippets
CodeIgniter PHP snippets for the VIM plugin SnipMate
# SnipMate is required to use snippets
# Download SnipMate: http://www.vim.org/scripts/script.php?script_id=2540
# Put this file in ~/.vim/snippets/ then restart vim
# This snippet file includes many useful snippets for CodeIgniter. Please feel free to fork and contribute!
snippet php
<?php
${1}
snippet ec
echo "${1:string}"${2};
snippet inc
@beberlei
beberlei / MyWebTestCase.php
Created September 17, 2011 12:14
Easily Inject authenticated Symfony User into functional test
<?php
use Liip\FunctionalTestBundle\Test\WebTestCase;
use Symfony\Component\HttpKernel\Profiler\Profiler;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @group functional
*/
@Ocramius
Ocramius / User.php
Created October 23, 2011 14:22
Doctrine 2 @onetomany @manytoone example
<?php
namespace HelloWorld;
use InvalidArgumentException;
/**
* This class is somewhere in your library
* @Entity
* @Table(name="users")
*/
<?php
/**
* Executes a mysql 5.5 safe truncate against all tables in a dataset.
*
* @package DbUnit
* @author Mike Lively <[email protected]>
* @copyright 2011 Mike Lively <[email protected]>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: @package_version@
@wowo
wowo / Mockery way to mock Doctrine2 Entity Manager.php
Created November 1, 2011 20:24
Mockery's way to mock Doctrine2 Entity Manager
<?php
class AbstractManagerBase extends \PHPUnit_Framework_TestCase
{
protected function getEmMock()
{
$emMock = \Mockery::mock('\Doctrine\ORM\EntityManager',
array(
'getRepository' => new FakeRepository(),
'getClassMetadata' => (object)array('name' => 'aClass'),
@mjuneja
mjuneja / get_my_access.sh
Created December 14, 2011 15:23
Shell script to get my public key from a url and append to authorized_keys to grant access
#! /bin/bash
if [ ! -d $HOME/.ssh ]; then
`mkdir $HOME/.ssh`
`touch $HOME/.ssh/authorized_keys`
`chmod 0600 $HOME/.ssh/authorized_keys`
else
if [ ! -d $HOME/.ssh/authorized_keys ]; then
echo "Creating authorized_keys file"
`touch $HOME/.ssh/authorized_keys`
`chmod 0600 $HOME/.ssh/authorized_keys`