PHPUnit and Mock Object Exactly Method

November 1st, 2009

<?php
$mapper
->expects($this->exactly(‘2′))->method(‘delete’);
$mapper->expects($this->exactly(2))->method(‘delete’);

?>


The two above lines of code don’t behave the same. When passing in 2 as a string instead of a number, PHPUnit declares it a failure:

Em_Model_Collection_MapperTest::testDeleteCollectionWithJoinTable
Expectation failed for method name is equal to  when invoked 2 time(s).
Method was expected to be called 2 times, actually called 2 times.

MooTools, form send function and b.lastIndexOf is not a function error

October 15th, 2009

I am new to MooTools and was using MooTools 1.2.3 to submit a form via Ajax - pretty standard stuff. When trying to put in callbacks for onSuccess,onRequest, etc… I kept getting JavaScript errors (b.lastIndexOf is not a function). Looks like you need to use set() function first, then call send(). MooTools must have been updated, because there are a lot of examples on the intraweb that do not do this, but work in my browser. To add to my confustion, you can call send() on the form without set first as long as you don’t pass an object with callbacks as a parameter in send().
This works

            window.addEvent('domready', function() {
                $('myForm').addEvent('submit',function(event) {
                    event.preventDefault();
                    this.send();
                })
            });

This does not work

            window.addEvent('domready', function() {
                $('myForm').addEvent('submit',function(event) {
                    event.preventDefault();
                    this.send({onComplete:function(){alert('this');}});
                })
            });

This works with callbacks

            window.addEvent('domready', function() {
                $('myForm').addEvent('submit',function(event) {
                    event.preventDefault();
                    this.set('send',{onComplete:function(){
                            alert('this');
                        }
                    }).send();
                })
            });

Anyways, after a day of playing with MooTools, I have say I am impressed. Not sure why, but I think this is my favorite framework. I can’t say I have much experience with JS frameworks, and my JavaScript is pretty bad these days, but I am impressed with MooTools so far.

symlink with FTP

September 28th, 2009

Apparently you can’t use FTP for symlinks? It’s been so long since I have mucked around with FTP, that I didn’t realize you could not create symlinks. I have an old site I still maintain and had to move it to a new hosting provider and the new provider did not give SSH access (well at least without charging for it). PHP to the rescue:


<?php
symlink
(‘../gallery’,‘gallery’);

?>


Use the symlink command in PHP. Obviously you need to have the proper permissions, and since PHP may be running as a different user, your mileage may very. But it worked for me…

Zend_Acl with User Specific Permissions

August 23rd, 2009

There are many articles around explaining Zend_Acl and how to use it within a CMS like system where generic roles apply - i.e. an admin can do anything, a guest can leave a comment and an author can write articles. But I was having a hard time figuring out how to elegantly enforce user specific permissions in addition to generic permissions For example, an author can save a new article, but can only update or delete an article that they “own”. I was trying to use assertions, but the role object in the assertion was turned into a generic Zend_Acl_Role object, even though I was using my own role object that implemented Zend_Acl_Role_Interface. Therefore, I couldn’t check the userId of the role in the assertion and was trying to pass responsibility back onto the object that was checking the acl.

It looks like this has all been fixed in 1.9.1, and Ralph does a good job of explaining the details. I have yet to try the improvements, but looking forward to refactoring my code to use the new and improved assertions.

Slicehost VPS

July 7th, 2009

I signed up for a VPS on Slicehost today, and am very impressed. The interface is refreshingly basic and I was up and running in no time. Their articles are absolutely amazing, and worth the read even if you don’t use their services. I know Ubuntu somewhat, but am far from an expert. Using the Ubuntu set up guide, I was up and running in under an hour. I made a stupid mistake when copying my public key and had to rebuild my slice. But that’s the beauty of the cloud, just hit a button, start with a fresh install and go again.

I am testing it out, as I have a dedicated server which costs too much for the small number of low traffic sites I maintain. After going through all the articles on getting the basics set up, I altered my /etc/hosts file on my desktop to point to the IP address of my new slice, updated the ServerAlias in the Apache vhosts file to include the “slice” domain name in my /etc/hosts file, and then finally enabled mod_rewite (sudo a2enmod rewrite) so I could test out a site that was running Zend_Framework without having to actual point production traffic at it.

I then set up rysnc and get some database permission set up and tables copied over, and it was live. Talk about easy….

I looked at Amazon, and while it offers a lot of flexibility and they are developing more and more tools (instead of APIs), it just seemed like way to much work for my limited needs. Anyways, really impressed with Slicehost after just one day, we’ll see how it goes in the next week or so. This blog may be moving over next…