Skip to content

Instantly share code, notes, and snippets.

@Vinai
Vinai / install-mage2.sh
Created April 25, 2016 12:54
Steps I use to install Magento 2 community edition
#!/bin/bash
FOLDER=example
DB_NAME=magento2
DB_USER=m2
DB_PWD=wiener
BASE_URL=http://example.dev/
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition $FOLDER
@Vinai
Vinai / bootstrap.php
Last active January 29, 2019 22:50
Simple Magento integration test PHPUnit bootstrap
<?php
/**
* Simple Magento integration test PHPUnit bootstrap
*/
chdir(__DIR__ . '/../..');
$mageFile = 'htdocs/app/Mage.php';
umask(0);
@Vinai
Vinai / phpunit.xml
Created February 17, 2016 20:42
Magento 2 integration test phpunit.xml file with Mage2Katas testsuite configuration.
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
colors="true"
bootstrap="./framework/bootstrap.php"
>
<!-- Test suites definition -->
<testsuites>
<!-- Memory tests run first to prevent influence of other tests on accuracy of memory measurements -->
<testsuite name="Memory Usage Tests">
@Vinai
Vinai / CartController.php
Created July 11, 2012 14:57
Your/Ext/etc/config.xml and Your/Ext/controllers/Checkout/CartController.php
<?php
// Your/Ext/controllers/Checkout/CartController.php
class Your_Ext_Checkout_CartController extends Mage_Checkout_CartController
{
public function yourNewAction()
{
}
}
#!/bin/bash
# CREATE BACKUPS BEFORE RUNNING THIS SCRIPT!
for m in $(locate Mage.php | grep -v downloader); do
cd $(dirname $(dirname $m)) || (echo && continue) # old locate db
MAGE_VERSION=$(php -d error_reporting=0 -r "require 'app/Mage.php'; Mage::app(); echo Mage::getVersion();")
if echo $MAGE_VERSION | egrep -q "^[0-9.]+$"; then
if [ $MAGE_VERSION "<" 1.4.0.0 ] || [ $MAGE_VERSION ">" 1.7.0.1 ]; then
echo -e "No patch available for version $MAGE_VERSION in $(pwd)\n"
@Vinai
Vinai / setup.php
Created November 8, 2011 20:35
Example EAV setup script using createEntityTables(), installEntities() and addAttribute()
<?php
/* @var $installer Mage_Eav_Model_Entity_Setup */
$installer = Mage::getModel('eav/entity_setup', 'default_setup');
$installer->startSetup();
// Example createEntityTables() call
$installer->createEntityTables('example_supplier');
#!/bin/bash
current=$(php --version | head -1 | cut -f2 -d' ')
current=$(echo "${current%.*}")
php_head=$(brew info php | head -1 | cut -f3 -d' ')
from=$([ "${current}" = "${php_head%.*}" ] && echo "php" || echo "php@${current}")
to=$([ "${1}" = "${php_head%.*}" ] && echo "php" || echo "php@${1}")
echo "Switching from $from to $to"
@Vinai
Vinai / example.clj
Last active July 22, 2019 13:48
Example of property based tests for a simple algorithm in Clojure and in PHP.
(ns example.core
(:require [clojure.test :refer :all]
[clojure.test.check :as tc]
[clojure.test.check.generators :as gen]
[clojure.test.check.properties :as prop]))
;; -----------------------------------------------------------------------
;; Application code to test
(defn includes? [needle haystack]
@Vinai
Vinai / install-and-run-phpcs.sh
Created November 13, 2014 13:40
Example for automating phpcs with a custom coding standard. Run this in a magento project dir (for example).
#/bin/bash
CODING_STANDARD_DIR="../Coding-Standards/Ecg"
[ ! -e "$CODING_STANDARD_DIR" ] && git clone https://github.com/magento-ecg/coding-standard.git "$CODING_STANDARD_DIR"
phpcs --standard="$CODING_STANDARD_DIR/ruleset.xml" "$1"
@Vinai
Vinai / 2016-48.md
Last active January 13, 2020 09:25
List of past code katas. The file names are the [year]-[week-of-year].md. I'll try to update the list each week.

The first kata is the classic BowlingGame Kata from Uncle Bob.

Write a class named Game that has two methods

  • roll(pins : int) is called each time the player rolls a ball. The argument is the number of pins knocked down.
  • score() : int is called only at the very end of the game. It returns the total score for that game.

Here is the original PowerPoint from Uncle Bob with the instructions including the solution steps. The PPT file also includes the rules for the scoring of a bowling game.