Skip to content

Instantly share code, notes, and snippets.

View mmenozzi's full-sized avatar
💻
CTO at Webgriffe®

Manuele Menozzi mmenozzi

💻
CTO at Webgriffe®
View GitHub Profile
<?php
/**
* @author Manuele Menozzi <[email protected]>
*/
namespace Erica\EricaBundle\EventListener;
use Doctrine\Common\EventArgs;
use Gedmo\Timestampable\TimestampableListener;
<?php
/**
* @author Manuele Menozzi <[email protected]>
*/
include 'VendingMachine.php';
class VendingMachineTest extends PHPUnit_Framework_TestCase
{
/**
<?php
/**
* @author Manuele Menozzi <[email protected]>
*/
class VendingMachine
{
private $availableItems = array('coffe' => 0.38);
private $credit = 0;
<?php
/**
* @author Manuele Menozzi <[email protected]>
*/
namespace Acme\DemoBundle\EventListener;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Response;
@mmenozzi
mmenozzi / xhprof.php
Last active August 29, 2015 14:01
Profiling with xhprof
$profilingEnabled = extension_loaded('xhprof') && isset($_GET['xhprof']);
if ($profilingEnabled) {
include_once '/Users/manuele/Work/Projects/xhprof-0.9.3/xhprof_lib/utils/xhprof_lib.php';
include_once '/Users/manuele/Work/Projects/xhprof-0.9.3/xhprof_lib/utils/xhprof_runs.php';
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
register_shutdown_function(
function() {
$profiler_namespace = 'xxx'; // namespace for your application
$xhprof_data = xhprof_disable();
$xhprof_runs = new XHProfRuns_Default();
@mmenozzi
mmenozzi / dev_install.sh
Created June 24, 2014 07:43
Magento Dev Install
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
MAGENTO_DIR="${SCRIPT_DIR}/.."
COMPOSER_DIR=${MAGENTO_DIR}
source ${SCRIPT_DIR}/config.sh
cd ${MAGENTO_DIR}
@mmenozzi
mmenozzi / .gitignore
Created June 24, 2014 08:23
Magento gitgnore
/.idea
/bin/config.sh
# Magento
/magento/var/*
!/var/.htaccess
/magento/media/*
/magento/app/etc/local.xml
/magento/downloader/.cache
/magento/downloader/cache.cfg
@mmenozzi
mmenozzi / SessionStartMock.md
Created July 20, 2015 09:37
Magento - Ecomdev_PHPUnit

When testing stuff with Ecomdev_PHPUnit the following error could occur:

Exception: Warning: session_start(): Cannot send session cookie - headers already sent by (output started at [...]/vendor/phpunit/phpunit/src/Util/Printer.php:172)  in [...]/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php on line 123

This error happens because somewhere in your tested code there is an itialization to a Magento's session singleton/model that casues a session_start which in turn needs to set the related cookie/session header. The error is thrown because the output has already started due to PHPUnit initial output.

The architecture of these Magento models sucks and there is no separation between domain session logic and PHP session_* functions but fortunately we can mock session calls through Ecomdev_PHPUnit.

@mmenozzi
mmenozzi / 0_reuse_code.js
Last active September 1, 2015 15:12
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@mmenozzi
mmenozzi / docker-compose.yml
Last active January 12, 2016 07:51
MySQL from Docker or from the Host
php:
image: webgriffe/magento1-dev
volumes_from:
- unison
links:
- mysql
- memcached
- blackfire_agent:blackfire
environment:
HOST_IP: 192.168.99.1