Magento Extension GitIgnore Stub

As you may or may not know, I’ve been working with Magento lately. In the past few months, one thing I’ve found that I needed is a stock .gitignore file for when making extensions. Haven’t found one so I made one on github and will also post here for anyone else in need site. I’m still relatively new at working with Magento and in someways git/github so please feel free to critique/streamline.


# replace {company} and {extension} placeholders with your information

# ignore phpstorm files
/.idea

# Ignore all not in app & skin
/*
!/app/
!/js/

# ignore all in js, except module files for this module
/js/*
!/js/{company}/

# Ignore all in app, except code & etc
# Ignore all in app/code except /local/{company}
/app/*
!/app/code/
!/app/etc/
!/app/design/

# Ignore all in app/code/local except {company}
/app/code/core
/app/code/community
/app/code/local/*
!app/code/local/{company}/
# use lines below if you have multiple company extensions
# and want to just commit a specific one
#/app/code/local/{company}/*
#!app/code/local/{company}/{extension}

# Ignore all of app/etc except our specific module files
/app/etc/*
!/app/etc/modules/
/app/etc/modules/*
!/app/etc/modules/{company}_{package}.xml

#Ignore all of app/design except for our files
/app/design/*
!app/design/frontend/
!app/design/adminhtml/
/app/design/frontend/*
!/app/design/frontend/base/
/app/design/frontend/base/default/etc/
/app/design/frontend/base/default/template/*
!/app/design/frontend/base/default/template/{extension}/
/app/design/frontend/base/default/layout/*
!/app/design/frontend/base/default/layout/{extension}/*
/app/design/adminhtml/*
!/app/design/adminhtml/default/
/app/design/adminhtml/default/find/
/app/design/adminhtml/default/default/etc/
/app/design/adminhtml/default/default/locale/
/app/design/adminhtml/default/default/template/*
!/app/design/adminhtml/default/default/template/{extension}/
/app/design/adminhtml/default/default/layout/*
!/app/design/adminhtml/default/default/layout/{extension}/*

Enhanced by Zemanta

Using MySQL Workbench with MAMP

Recently I’ve started working locally due to the PHPStorm IDE. In order to work locally, I invested in MAMP Pro to make use of their GUI interface for configuring vhosts. I also like to use MySQL Workbench for my database work, unfortunately these 2 items never seemed to work together for me before. After a brief google search I was able to find out how to connect to MAMP’s MySQL install to do SQL Development, which is by done by choosing the local socket connection method and using the value /Applications/MAMP/tmp/mysql/mysql.sock for the connection.

MySQL Workbench MAMP Socket Connection Settings
MySQL Workbench MAMP Connection Settings

After setting that up, I got to thinking, “I’m already using an IDE for code convenience and a GUI for vhost convenience, I should set up Server Administration with MySQL Workbench too!” So after some googling, I found an article to help me set up Server Administration with MAMP. Unfortunately the article only got things partially working and has no way to comment on it to have it corrected. So I’m going to outline the steps. Also I just noticed that the images with the article are updated correctly but it’s hard to cut and paste an image of something someone has done so I’ll just give you the value pairs

  • Configuration File: /Applications/MAMP/tmp/mysql/my.cnf
  • Start: /Applications/MAMP/bin/startMysql.sh –
  • Stop: /Applications/MAMP/bin/stopMysql.sh –
  • Check MySQL Status: ps -xa | grep “/Applications/MAMP/Library/bin/[m]ysqld”
If the check status doesn’t work, just do a
ps -xa | grep MAMP
and find the correct path to mysqld
And that’s all you need to know.
MySQL Workbench MAMP System Profile Settings Tab
Enhanced by Zemanta

expected exceptions annotations, mocked object calls, oh my.

Note: I have tested this in PHPUnit 3.4.1 and haven’t tried it out in 3.5.
Anyone who has worked with PHPUnit has most likely worked with expected exceptions and mock objects. The nice thing about working with expected exceptions is that we have access to a handy @expectedException annotation. I’ve gotten into the habit of using this for exceptions my fixtures should throw but also for when I’m using a mock object to verify a method call. So my tests usually expect foo_exception for fixture throws and when i’m testing method calls via a mock, they expect Exception. Therein lies my problem. Because all my custom class exceptions obviously extend the Exception class, I can get some false positives in testing.

require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
require_once('foo.php');
class tmpTest extends PHPUnit_Framework_Testcase
{

    /**
     * @expectedException Exception
     */
    public function testFooBar()
    {
        $foo=new foo();
        $foo->bar();
    }

    /**
     * @expectedException Exception
     */
    public function testBarBaz()
    {
        $mock=$this->getMock('foo',array('baz'));
        $mock->expects($this->any())
         ->method('baz')
         ->will($this->throwException(new Exception('baz')));
        $mock->barbaz();
    }
}
class foo_exception extends Exception{}

class foo
{
    public function bar()
    {
        throw new foo_exception('bar');
    }

    public function baz()
    {
        echo "bwahn";
    }

    public function barbaz()
    {
        $this->bar();
        $this->baz();
    }
}

So here we have an expectation for Exception but if we look at the code, we see that the bar method throws a foo_exception and the testBarBaz test is trying to test for the baz call via a mock that throws an Exception. if we change the annotation to expect foo_exception, the test still passes. This leads me to believe the best way to isolate the behavior we wish to test is to not use annotation for these sorts of tests. Or if you want to use annotation, be sure to use a unique exception for the mock. This means, unfortunately for me, that I’ll have to go back through all my tests and ensure there’s no false positives.

Lesson learned: be careful using shortcuts (and don’t stand in the fire).

On a side note, this part of PHPUnit is why those tests will behave that way. The behavior is completely my fault but I wanted to confirm it was behaving because of how it was verifying the expected exception.

Enhanced by Zemanta

fun with arrays and requirement chains

Recently, I had to figure out if a given set of features contained all of their necessary requirements.

For better or worse, the table was modeled so that the feature table referenced itself so that it could create a parent/child requirement chain. For example:

feature_id requirement_id
2 null
5 2
7 null
11 5

So my problem is to find out if a given set of requested features, make sure that the requirements are also present. This includes any requirements the requirement feature may have. In this example, 11 requires 5 which requires 2.
Let’s take $featureRequest1=array(2,5,7,11) and $featureRequest2=array(7,5,11). If I were to run a look up of requirements, I would find that we have

$requirements=array(2,5).

I tried to use the php in_array function but it didn’t work as I expected it to.

in_array($requirements,$featureRequest1); // i expect true
var_dump(in_array($requirements,$featureRequest1)); // false
in_array($requirements,$featureRequest2); // i expect false
var_dump(in_array($requirements,$featureRequest2)); // false

I then realized what I need is for there to be a clear intersection between the requirements and the request.

$requirements==array_intersect($requirements,$featureRequest1); // expect true
var_dump($requirements==array_intersect($requirements,$featureRequest1)); // true
$requirements==array_intersect($requirements,$featureRequest2); // expect false
var_dump($requirements==array_intersect($requirements,$featureRequest2)); // false

I should probably note that array_interest will preserve the array keys. To fix it, you can either flip the 2 arguments or pass the return array to array_values

Meet the PHP Dev Derby Team

I liked how the Dev Derby website did team leader profiles and decided to try to do something similar. No one provided any pictures but most did answer some questions I asked so without much further ado, meet the PHP Dev Derby Team.

The team consists of

  • Dennis Rogers (@_drogers)
  • Max Beatty (@maxbeatty)
  • Matthew Haralovich (aka zon)
  • Grant Simpson (@grantls)
  • Ryan Dagey (@dageytech)

Update: added in Ryan Dagey’s answers. And photo.

Continue reading