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 / 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 / M2 acl.xml
Last active October 17, 2023 05:38
My current Magento 2 PHPStorm File Templates (Feb 2016)
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
<resources>
<resource id="Magento_Backend::admin">
</resource>
</resources>
</acl>
</config>
@Vinai
Vinai / manage-workers.sh
Last active January 29, 2016 13:20
Little worker management UI script, just for fun. Ideas for improvements welcome!
#!/usr/bin/env bash
########################################################
declare -a workers=(commandConsumer.php eventConsumer.php)
########################################################
function main() {
init_vars
@Vinai
Vinai / or-example.php
Last active September 28, 2021 20:48
SearchCriteria OR Example for Magento 2
<?php
declare(strict_types = 1);
namespace Training5\VendorRepository\Controller\Test;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\Api\Filter;
use Magento\Framework\Api\FilterBuilder;
@Vinai
Vinai / Magento_IntegrationTest_Config.php
Last active October 18, 2016 17:16
Simple Magento 1 bootstrap for PHPUnit.
<?php
class Magento_IntegrationTest_Config extends Mage_Core_Model_Config
{
private $modelTestDoubles = [];
private $resourceModelTestDoubles = [];
public function setModelTestDouble($modelClass, $testDouble)
{
@Vinai
Vinai / protected-execute-reasoning.md
Last active October 6, 2015 19:19
The reasons why or why not \Magento\Framework\App\Action\Action::execute should be used as a plugin extension point

To plug into or not plug into execute?

Background

Cyrill Schumacher asked in a tweet

Ur change to add abstract protected fnc exec() conflicts with the Plugin System or am I missing smthng?

This is about the protected visiblity of the method \Magento\Framework\App\Action\Action::execute().

@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 / MockTraitMethodTest.php
Created November 12, 2014 16:48
How to mock a trait method using getMockForTrait()
class MockTraitMethodTest extends \PHPUnit_Framework_TestCase
{
public function testTraitMock()
{
// Inspect getMockForTrait signature for what the other arguments do.
$methodsToMock = ['getBar'];
$mockTrait = $this->getMockForTrait('\Example\Foo', [], '', true, true, true, $methodsToMock);
$mockTrait->expects($this->any())
->method('getBar')
->willReturn('buz');
@Vinai
Vinai / .n98-magerun.yaml
Created November 11, 2014 10:08
How can the configured sample data package for a magento package be changed via ~/.n98-magerun.yaml?
# I want to change the configured sample data name for a given magento package.
#
# (Alternatively I would like to change the source URL for a sample data package.)
#
# The following does not work as I intend it to.
# It adds a new record to the $this->commandConfig['magento-packages']
# array instead of overwriting the extra sample-data value.
#
# Can this be done?