Sequel 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

Installing Ansible on a fresh Mavericks system.

I recently purchased a new Retina Macbook Pro, and was surprised that Ansible did not install as easily as it did before. Looking back through the output on the CLI we see it is trying to use Apples CLANG. Which unfortunately has some deprecated stuff. I guess i had already installed the correct GCC etc manually on my older machines.

No worries though, this is the simplest way i have found to power through this.

Firstly, install apples developer tools. Likely you will just download XCode through the App Store. Then once you have opened it at least once to agree to the terms and conditions, you will also need to go to the xcode preferences and ‘Locations’ tab, to select the latest ‘Command Line Tools’ version. Then you will need to run this on the command line.

This will install some additional command line tools which you will need. It will open a GUI prompt to install them, so just go ahead with that.

With XCode installed we can now install Homebrew, a package manager for mac, which will make installing the non Apple version of GCC much easier. To install Homebrew, run the following on the CLI.

Then run this, which will tell us if Homebrew is working correctly, or if there are any issues.

Now we must install the correct GCC via Homebrew.

With that now installed, we must move Apples GCC aside so that we can use the correct one.

Then, we are good to go ahead and run the steps on Ansibles installation page found here

Problems that were occurring previously with CLANG and the like should now be gone.

Credit where credit is due, these 2 sites documented the steps i followed:
[1] Installing Homebrew on OS X Mavericks 10.9, Package Manager for Unix Apps
[2] Paul Crawford : Installing gcc on Mavericks

Symfony2 and “ContextErrorException: Warning: SessionHandler::read()” Exception

I just upgraded to Symfony 2.4, and started randomly getting this error:

ContextErrorException: Warning: SessionHandler::read(): open(/var/lib/php/session/sess_3cq63tff1lhbghus3o9jsh26j4, O_RDWR) failed: No such file or directory (2) in /var/www/ line 69

Which was pretty odd, as there is a discussion about this, which you can find here on symfony/symfony github, However the issue seems to be in part with PHP, but it was for me already patched. As the issue is introduced in 5.4 somewhere and fixed in 5.4.11.

It seems that everything was fixed, and i was many versions ahead. So why was this cropping up randomly now? I had not changed my PHP version or my OS version, just symfony.

It seems some config changed, which i show below. If you do not have this set, then i believe it falls back on the default php.ini setting of session.cookie_path, which if blank causes this. Add this config below will fix the issue.

I hope this helps.

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!

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: