Going to cover:
- Jenkins
- Code sniffer
- Unit testing
Jenkins
It's nothing more than a bit of java software designed to run lots of modules to do different little things - or a continuous integration server to the nerd. More info: http://jenkins-ci.org/. Basically add plugins to do your tasks (i.e. 1. Git clone your repo, 2. scan for code syntax errrors, 3. scan for coding standards, 4. Make you a coffee, 5. Email you the results, 6. Deploy ..... i think you get the picture.). You can do most things with Jenkins INCLUDING unit tests, selenium etc etc. Honestly have a play, run it in a VM (we use a 1GB 1 core Hyper-V on our Windows 2012 server and its plenty, but FYI an Amazon Micro instance isn't lol).
Code Sniffer
My favorite test tool for PHP! Even your IDE will support it (NetBeans, PHP Storm and if you really must, Sublime)
Anyone noticed my random commits that have spotted silly coding standard errors? That is code sniffer at work telling us that some code got added that was bad. Here is one:
https://github.com/opencart/opencart/co ... 9120089460
Code sniffer just checks your code to match it against the coding standards of a project, set what ever you want and even create your own rules! A list is here though:
http://pear.php.net/package/PHP_CodeSni ... s/2.0.0a2/
If you have XAMPP installed just use shell to install in about 2 mins.
As a second line of defense our Jenkins server even runs sniffer on the WHOLE OpenCart project on demand.
Maybe soon we will even configure Jenkins to scan through each Pull Request to ensure it passes the standards tests and it can even comment back on GitHub with a pass or fail! All without any admins even looking at the code
Unit Testing
To start with, credit goes to: https://github.com/Beyond-IT/opencart-test-suite - seems they started and abandoned the project which is a MASSIVE shame. I sent them an email a while back but no response So the solution that has been created has been adapted from an existing source, updated and finished - and importantly it is easy to use.
A new branch has been created on GitHub, forked from the current OC master (please do not submit PR's to it as it is for the test-suite only):
https://github.com/opencart/opencart/tr ... ting-suite
It now has a /test/ folder - this is where anything and everything related to unit testing will live.
If you don't know what unit testing is then you should! In a nut shell it is a way to give your application some thing and expect a specific result in return - i.e. testing it works as it should. Here is an example:
Code: Select all
class CatalogControllerCheckoutCartTest extends OpenCartTest {
/**
* @before
*/
public function setupTest() {
$this->cart->clear();
}
public function testAddProduct() {
$this->request->post['product_id'] = 28;
$this->request->post['quantity'] = 1;
$response = json_decode($this->dispatchAction("checkout/cart/add")->getOutput(), true);
$this->assertTrue(!empty($response['success']) && !empty($response['total']));
$this->assertEquals(1, preg_match('/HTC Touch HD/', $response['success']));
$this->assertEquals(1, preg_match('/119\.50/', $response['total']));
}
}
Imagine you change something, a method, controller, model whatever - or you even add a new module - the idea is that you can run ONE command and it will report syntax, unit test fails, coding violations (and even what file too)
The good news is that we're already doing the unit tests - and hopefully people will read the readme (yes there is one and will be expanded even more soon!!)...then start using the testing tool.
As always, love to get feedback!
Anyone with some knowledge of the above with some additions?
But a final word...yes I will also look into Selenium and Vagrant....it would be pretty cool to run Jenkins, do all the code tests, boot up a VM, install OpenCart, run Selenium tests - then send us a pretty email (never know might even make it a responsive email lol), but we are a long way off that just yet.
J