Skip to content

Instantly share code, notes, and snippets.

View wowo's full-sized avatar

Wojciech Sznapka wowo

View GitHub Profile
<?php
function closureTest(callable $callback) {
printf("Look, I'm running callback! '%s'\n", $callback());
}
closureTest(function() { return 'foo'; });
<?php
function dereference() {
$arr = ['php', '5.4', 'looks', 'nice'];
return $arr;
}
printf("%s - %s\n", dereference()[1], dereference()[3]);
// will echo:
// 5.4 - nice
<?php
trait Loggable {
public function log($event) {
printf("Event: '%s', source: '%s'\n",
event, get_class($this));
}
}
class User {
use Loggable;
@wowo
wowo / bundles.txt
Created December 9, 2011 13:31
Bulk Symfony2 bundles generation.sh
FirstBundle
SecondBundle
AnotherBundle
<?php
if (is_array($limiters['organization_unit']) && !empty($limiters['organization_unit']))
{
$query->andWhere($query->expr()->in('si.organizationUnitCode', $limiters['organization_unit']));
}
<?php
if (is_array($limiters['organization_unit']))
{
if (!empty($limiters['organization_unit']))
{
$units_conditions = '';
$first = true;
@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'),
@wowo
wowo / PHPUnit way to mock Doctrine2 Entity Manager.php
Created November 1, 2011 20:22
PHPUnit's way to mock Doctrine2 Entity Manager
<?php
class AbstractManagerBase extends \PHPUnit_Framework_TestCase
{
protected function getEmMock()
{
$emMock = $this->getMock('\Doctrine\ORM\EntityManager',
array('getRepository', 'getClassMetadata', 'persist', 'flush'), array(), '', false);
$emMock->expects($this->any())
->method('getRepository')
@wowo
wowo / phpunit.xml
Created November 1, 2011 20:19
PHPUnit xml config with Mockery listener
<phpunit>
<!-- snip... -->
<listeners>
<listener class="\Mockery\Adapter\Phpunit\TestListener"
file="Mockery/Adapter/Phpunit/TestListener.php">
</listener>
</listeners>
</phpunit>
@wowo
wowo / autoload.php
Created November 1, 2011 20:16
Symfony2 autoload prepared for Mockery
<?php
// [...]
// you can put it on bottom of the autoload.php
if (class_exists('PHPUnit_Runner_Version')) {
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__.'/../vendor/mockery/library/');
require_once('Mockery/Loader.php');
$loader = new \Mockery\Loader;
$loader->register();
}