Skip to content

Instantly share code, notes, and snippets.

View gpaddis's full-sized avatar

Gianpiero Addis gpaddis

View GitHub Profile
@gpaddis
gpaddis / with_counts.rb
Last active September 5, 2020 13:36
WithCounts - dynamic parameterized scope to add count fields for has_many relations.
# frozen_string_literal: true
# A dynamic parameterized scope to add a count field. Works with
# direct and polymorphic has_many relations.
#
# Example:
# > post = Post.with_counts(:comments, :likes).first
# > post.comments_count # contains the count of associated comments
# > post.likes_count # contains the count of associated likes
#
@gpaddis
gpaddis / modpath.py
Created October 15, 2019 16:18
Create pathMappings based on modman files for Magento 1 modules
#!/usr/bin/env python3
"""
Create a path mapping for VS Code (Xdebug) based on the modman file in the current module directory.
Pass the destination Magento directory (without / at the end) as first argument.
See: https://github.com/felixfbecker/vscode-php-debug#remote-host-debugging
"""
import sys
import os
@gpaddis
gpaddis / mage-run-unittests.sh
Last active February 8, 2019 16:00
Deploy your Magento 1 module to a custom shop with modman and run the unit tests there with EcomDev_PHPUnit
#!/bin/bash
checkFileOrExitWithMessage() {
local filePath="$1"
local message="$2"
test -f $filePath || {
echo "$message"
exit 1
}
}
@gpaddis
gpaddis / mage-install-ecomdev-phpunit.sh
Last active February 8, 2019 15:58
Setup EcomDev_PHPUnit in a Magento 1.x directory
#!/bin/bash
if [[ $# -ne 2 ]]; then
echo "Usage: $0 db_name base_url"
exit 1
fi
dbName="$1"
baseUrl="$2"
@gpaddis
gpaddis / Helper.php
Last active June 16, 2018 10:25
Magento 1 - Module Unit Testing
<?php
class Some_Module_Helper_Data extends Mage_Core_Helper_Abstract
{
/**
* This method interacts with the database, so it will be mocked for the unit test.
*/
public function queryDatabase()
{
return $this->getSomeDbData();