Sequel Pro.app for Mac with Vagrant

You can use Sequel Pro with Vagrant by setting up SSH under ‘SSH’ on the connections page.

The MySQL credentials will be the ones used inside of the Guest VM.

For example; Host, Port etc won’t be the same on your host machine, so use the host and port number that MySQL recognizes inside of the VM.

For your SSH, use the Host that you specified in your Vagrantfile, and the SSH user unless changed should be ‘vagrant’. Then for the password (unless changed in your Vagrantfile) you are going to need to click on the key icon in the password field. This will open a dialog to open a file, so then find the private key that vagrant created and select that.

Usually the private key can be found at ~/.vagrant.d/insecure_private_key

Deleting remote git tags.

I did a bit of googling on how to delete remote git tags and there was a lot of options, some of which seemed a bit risky.

Turns out there is a really simple way of doing this.

Just do something like:

So first we just remove our tag locally, then push the empty tag to the remote end and it knows its empty and so remove its.

So the trick to removing a tag is essentially sending the empty tag to the remote after its removes, so even if you already deleted it, no worries, just push it out there and your done.

And that is all there is to it!

Behat and “The current node list is empty.” error.

If your receiving the error “The current node list is empty” while using Behat, then likely your project is returning an HTTP 500 error. This may be because your bundle depends on some other bundle not available in your test environment. This was the case when for me when testing a bundle on travis-ci and i was not able to find documentation on this error.

One solution as suggested on github is to try dumping the contents of the scraper/browser to see what kind of error your getting.

However that will likely not give you any output if the server is returning an HTTP 500 internal server error. Your best bet is to just check your logs and do a search for any errors.

If your trying to run your functional tests on travis-ci then you might want to check out this great article on running Behat scenarios in isolation of your project.

Best of luck.

Set date (x)days from now in Behat with Symfony2 forms

Using Behat i needed to be able to set a date in a form (x) number of days from the current date. This however is a problem as Behat cannot set a date (x) number of days from now as it does not know the current date. So a simple solution is to create a Behat step definition that takes the field name and a number of days. My step definition looks something like this:

The reason i went with a CSS selector is because Behat supports this anyway, and Symfony2 can create a date form by splitting the field into 3 separate fields, for Month/Day and Year respectively. So we will need to identify 3 fields in our form. Symfony2 will label them with each with the overall field name with an additional underscore and designation. Each field will be a select field.

For example, if my field is called Post_unlockedUntilDate (which was a real field i needed this test case for [the Post_ designation came from symfony based on the entity the form related to), then the 3 fields i would need to find (as created by symfony) would be:

  • Post_unlockedUntilDate_year
  • Post_unlockedUntilDate_month
  • Post_unlockedUntilDate_day

So i created a step definition that takes the CSS and finds the fields by the given selector. Then identifies each field in the results and assigns them to an array with a key for ‘day’, ‘month’ and ‘year’. Then all we need to do is create a new datetime object set (x) number of days from now and then apply that to each field.

So to use it we just call:

Hope this helps. Good luck.

Simple Method for Checking for Order With Behat

While needing to write a test to check the order of 2 items (within a given CSS query) in Behat, I did a little googling and came across this website here.

The tutorial is great and i just wanted to give a shout out to the author for their great content. I also made a slight change to include testing for the existing of the 2 items.

Here is my slightly updated version:

You can see an example of the test i wrote using this method here.

Sorting/Reording Symfony2 Entities Display Order.

So i had to implement a mechanism to re-order Categories and also Boards for my forum bundle, and with though there are many ways to go about it, here is how i solved the problem of reordering them. The reordering functionality is circular so last items getting pushed down end up on the top of the list, and top items getting pushed up end up on the bottom of the list.

What do you guys think? Know of a better approach? Let me know!

Stylish Pure CSS 3 Bread Crumb Bar.

I was wanting a new bread crumb bar for my site CodeConsortium and i spent considerable time looking for a pre made solution that did the following:

  1. Used no images at all including background images
  2. Tag shaped and overlapped like in the google style on their docs pages
  3. Used very lean and semantically correct HTML

After failing to find anything on google, i decided i would need to write my own and so i did just that. One of the things i found was that most of the bread crumbs i found either used background images, or used psuedo-selectors to fake the triangular end which unfortunately was being done using the border trick instead of the rotation trick. Those using the rotation however were bland as they could not use images, and did not use gradients to make it all stylish.

The solution i came up with is to use the psuedo div (:before and :after) at a -45 degree angle and use a proportionally rotated gradient to match that of the main crumb. It was very tricky but here is what i came up with looks like:

Screen Shot 2013-02-27 at 04.43.23

and when you hover over a section:

Screen Shot 2013-02-27 at 04.43.48

Not bad huh? The last section is indented to convey that it is the current milestone along the path of bread crumbs.

After deciding that the best balance between lean html and a semantically correct bread crumb navigation would be to use just an ordered list inside a nav element, i came up with the following html:

Thats fairly lean, and still reasonably ‘semantically correct’. Now to add the CSS to style this puppy:

Oh one note, i have not tested this yet in IE (sorry), but if you do find an issue in IE, or you can improve upon this in some small way, let me know and ill fix it.

Symfony2 Voter Access Decision Strategy Explained!

The voter access decision strategy can be set in your Symfony2 app/config/security.yml. You have the choice of 3 approaches (Unanimous, Affirmative, Consensus). Set your strategy to  1 of them 3.

The approach of each is explained below.

  • Unanimous = 1 single voter denies access.
  • Affirmative = 1 single voter grants access.
  • Consensus = Majority wins.

So in Unanimous, if a single voter denies access, all other voters decisions are overridden and the bottom line is you will be denied access. If however you use Affirmative, a single voter only needs to grant access to override and the regardless of how many voters block you, you will always be granted access so long as a single voter permits it. Consensus, lastly; will weigh up and balance the number of denies or accesses being granted and decide that with the most voters wins. To put the Consensus another way, if more than half the voters grant access, then you have access. If more than half the voters deny access, then access will be denied.

Remember to return 1 of the 3 access types, the choices you have are:

Abstain will be impartial when using the consensus strategy for your security configuration.

You can set your class to be used, and listened for by the voting service in your bundles config, like so:

Setting up LAMP and PHPUnit on CentOS for staging.

I needing to setup a staging environment that more or less emulates the platform of your deployment system, i needed to setup a LAMP stack with PHPUnit for testing on the target platform.

Using CentOS and help from my good friend Cordoval (you can check out his cutting edge blog at http://www.craftitonline.com) we setup using Apache, PHP and MySQL.

We used the yum package manager to get things up and running:

First we needed to setup php :

and mysql:

With that done, we needed to then setup PEAR:

Then i followed the guides found here: (http://ulaptech.blogspot.co.uk/2011/07/install-phpunit-in-rhel-centos-or.html)

I will copy the instructions but all credit goes to the link above:

1. Make sure that you’re PEAR is version 1.9.2 or above. 

2. Discover all channels required.

3. Install PHPUnit with all the dependencies

<–

optional, at the time of writing this is beta so I had to force install it

4. Done. Test PHPUNIT.