This is a brief introduction to Unit Testing with PHPUnit and is based on a lightening talk I gave at Sheffield PHP on the 18th January 2018. We’ll take a look at what unit testing and PHPUnit are, why we would use them and finally look at how we can start writing tests.
PHP traits provide a convenient means of sharing methods between classes. There are times though that we may need to override or extend a method defined in a trait attached to a class. Let’s take a look at how we can achieve this.
I’m a keen advocate for following coding standards. They help maintain consistency in code, especially when developing with others, and can generally help you to write better code. I work with Sublime Text for developing in PHP and have it set up to check against whichever coding standard I am currently using as I code. For PHP development the tool to use is PHP CodeSniffer which I’ve previously written about setting up for Sublime Text 3 on this site.
A couple of years ago I wrote about Exporting Data to a Downloadable CSV File with CakePHP which is still getting a lot of interest; however, at the time it was pointed out that a better way of handling CSVs in Cake was using a View Class.
Now that CakePHP 3 is out I thought it would be a good idea to write an updated piece on exporting data to a CSV using the excellent CsvView plugin.
I recently found myself needing to change the user-group for file permissions depending on the connection being deployed to via Rocketeer. Rather than completely override the permissions
callback defined in remote.php for the specific context I wanted to be able to define the user-group as a configuration option that could be overridden contextually. It turns out this is pretty simple to achieve.
Wouldn’t it be great if deploying changes to a server was as simple as typing the command
rocketeer deploy? Well with Rocketeer it is!
Rocketeer is a task runner and deployment package. It is an alternative to the popular Capistrano.
If you need to connect to SFTP using PHP then the simplest approach I’ve found is to use phpseclib, a library of functions for secure communications.
I’ve recently noticed a number of people trying to use CakePHP 2’s
updateAll() method very badly.
Let’s first get one thing straight:
updateAll() is not the intended way of updating a record in CakePHP, use
save() for that!
This is a kind of follow-up to my recent article on Essential Sublime Text 3 Plugins for PHP Developers to explain how to install and configure Sublime-phpcs for the CakePHP code standard. Although I’m describing how to configure phpcs specifically for Cake it will hopefully be of use to anyone wanting to get started with phpcs in Sublime Text and start developing better code.
Sublime Text has got to be one of the most popular text editors out there for coding. Although still in beta, Sublime Text 3 is a relatively stable and very usable. I’ve personally been successfully using it for over 2 years now both at work and at home. It’s sophisticated, lightweight and easy to use. It also works on all the major platforms: Windows, OSX and Linux.
Sublime Text is not quite an IDE (Integrated Development Environment), but with the installation of a handful of packages/plugins you can really make it the ideal editor for developing PHP in.