{"id":56,"date":"2014-02-24T21:18:23","date_gmt":"2014-02-24T21:18:23","guid":{"rendered":"http:\/\/david.lidstone.me\/blog\/?p=56"},"modified":"2022-05-31T22:09:46","modified_gmt":"2022-05-31T21:09:46","slug":"setting-up-a-php-development-environment-part-2","status":"publish","type":"post","link":"https:\/\/david.lidstone.me\/blog\/?p=56","title":{"rendered":"Setting up a PHP Development Environment &#8211; Part 2"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p><mark style=\"background-color:#ffe2c7\" class=\"has-inline-color\">Note that this was published back in 2014 and is obsolete. I plan on doing a more modern development environment tutorial at a later date. Images are missing from this entry.<\/mark><\/p>\n\n\n\n<p>In the <a title=\"Setting up a PHP Development Environment \u2013 Part 1\" href=\"http:\/\/david.lidstone.me\/blog\/setting-up-php-development-environment-p1\/\">last part<\/a>, I showed you how to set up your basic development environment using Eclipse and The Uniform Server, but we didn&#8217;t really go into configuring PEAR or any more advanced functionality. We will start with adding PHPUnit2 so that we can write tests to help prevent bugs.<br><\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">1. Install PEAR module<\/h2>\n\n\n\n<p>Make sure your Apache service is started in The Uniform Server and then, still in the Uniform Server GUI go to <em>Server Configuration -&gt; PHP -&gt; Pear control panel<\/em> or go direct to <em>http:\/\/localhost\/us_pear\/index.php<\/em><br><span style=\"color: #0000ff;\">NOTE:<\/span> Do not add the PHPUnit package which is available in the package manager when you first start. This is the old PHPUnit and should not be used. Follow the steps below to get PHPUnit2.<br>Click on the <em>Channel Management<\/em> button and, at the bottom, add two new channel servers:&nbsp;<em>pear.symphony.com<\/em> and <em>pear.phpunit.de<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image alignnone\"><a href=\"http:\/\/david.lidstone.me\/blog\/wp-content\/uploads\/2014\/02\/p2_pear_channels.png\"><img decoding=\"async\" src=\"http:\/\/david.lidstone.me\/blog\/wp-content\/uploads\/2014\/02\/p2_pear_channels.png\" alt=\"PEAR Channels\" class=\"wp-image-57\"\/><\/a><figcaption>PEAR Channels installed (other modules are also installed)<\/figcaption><\/figure>\n\n\n\n<p><br>Go back to the Package Management page and add <em>pear.phpunit.de\/PHPUnit&nbsp; <\/em>You should end up with PHPUnit2 installed OK, but if you have any error messages, try installing <em>pear.symfony.com\/Yaml&nbsp;<\/em> first and then try PHPUnit again.<br>PHPUnit2 is now installed, but needs to be configured in Eclipse.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Set up in Eclipse<\/h2>\n\n\n\n<p>If you don&#8217;t have the Eclipse module MakeGood already installed, you will need to install it via the Eclipse Marketplace (<em>Help -&gt; Eclipse Marketplace<\/em>). After searching for MakeGood, you may have several results. Install the version with the green logo.<\/p>\n\n\n\n<figure class=\"wp-block-image alignnone\"><a href=\"http:\/\/david.lidstone.me\/blog\/wp-content\/uploads\/2014\/02\/p2_makegood_installed.png\"><img decoding=\"async\" src=\"http:\/\/david.lidstone.me\/blog\/wp-content\/uploads\/2014\/02\/p2_makegood_installed.png\" alt=\"MakeGood installed\" class=\"wp-image-58\"\/><\/a><figcaption>MakeGood already installed. Note the green version is the one used.<\/figcaption><\/figure>\n\n\n\n<p><br>I&#8217;m going to use an example to show you how to configure MakeGood to run your unit tests, but you can modify the paths etc to suit your own needs. How to write tests and the advanced features of PHPUnit2 are beyond the scope of this post.<br>Create a file <em>ExampleClass.php<\/em> in your lib folder and put the code for a simple class in it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&amp;lt;?php\nclass ExampleClass {\n\tpublic static function MakeUpperCase($string) {\n\t\tif (is_object($string)) return false;\n\t\treturn strtoupper($string);\n\t}\n}\n?&gt;\n<\/pre><\/pre>\n\n\n\n<p><br>Create a folder to hold your tests and create another PHP file in it called <em>ExampleClassTest.php<\/em><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&amp;lt;?php\nrequire_once(__DIR__ . &#039;\/..\/lib\/ExampleClass.php&#039;);\nclass ExampleClassTest extends PHPUnit_Framework_TestCase {\n\tpublic function testMakeUpperCase() {\n\t\t$this-&gt;assertTrue(ExampleClass::MakeUpperCase(&#039;SomeMixedText&#039;) === &#039;SOMEMIXEDTEXT&#039;);\n\t}\n}\n?&gt;;\n<\/pre><\/pre>\n\n\n\n<figure class=\"wp-block-image alignnone\"><a href=\"http:\/\/david.lidstone.me\/blog\/wp-content\/uploads\/2014\/02\/p2_example_files.png\"><img decoding=\"async\" src=\"http:\/\/david.lidstone.me\/blog\/wp-content\/uploads\/2014\/02\/p2_example_files.png\" alt=\"File Structure\" class=\"wp-image-62\"\/><\/a><figcaption>File structure used by this example<\/figcaption><\/figure>\n\n\n\n<p><br>Open the MakeGood View in Eclipse. You will notice that in the top left corner of the window is some red text informing you that MakeGood is not configured yet. Click the link to &#8216;fix&#8217; it. This will bring up the Properties window with the MakeGood tab selected. Ensure that PHPUnit is selected as the Testing Framework and use the Add button to add your tests folder.<\/p>\n\n\n\n<figure class=\"wp-block-image alignnone\"><a href=\"http:\/\/david.lidstone.me\/blog\/wp-content\/uploads\/2014\/02\/p2_makegood_test_run.png\"><img decoding=\"async\" src=\"http:\/\/david.lidstone.me\/blog\/wp-content\/uploads\/2014\/02\/p2_makegood_test_run.png\" alt=\"MakeGood Test Run\" class=\"wp-image-63\"\/><\/a><figcaption>A completed MakeGood Test Run<\/figcaption><\/figure>\n\n\n\n<p><br>You can now run the test by pressing the icon with the play symbol in the MakeGood view, although the tests were probably run automatically for you as the default is set to Continuous Testing. You can change this with the drop-down arrow next to the icon which looks like a power button.<br>You can also see the actual output of PHPUnit in the Console view.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>You should now be able to use PHPUnit2 from within Eclipse. If you have any problems, check that you have followed all the steps in <a title=\"Setting up a PHP Development Environment \u2013 Part 1\" href=\"http:\/\/david.lidstone.me\/blog\/setting-up-php-development-environment-p1\/\" target=\"_blank\" rel=\"noopener\">part 1<\/a>. For instance, did you add the PEAR library to your project?<br>As above, the details of how to write tests properly is outside the scope of this post. The <a title=\"PHPUnit2 Documentation\" href=\"http:\/\/phpunit.de\/\" target=\"_blank\" rel=\"noopener\">documentation for PHPUnit2<\/a> is excellent.<br>In part 3, we will cover adding PHPDoc.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Note that this was published back in 2014 and is obsolete. I plan on doing a more modern development environment tutorial at a later date. Images are missing from this entry. In the last part, I showed you how to set up your basic development environment using Eclipse and The Uniform Server, but we [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[5,9,12,13,17],"class_list":["post-56","post","type-post","status-publish","format-standard","hentry","category-programming","tag-eclipse","tag-makegood","tag-php5","tag-phpunit2","tag-the-uniform-server"],"_links":{"self":[{"href":"https:\/\/david.lidstone.me\/blog\/index.php?rest_route=\/wp\/v2\/posts\/56","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/david.lidstone.me\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/david.lidstone.me\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/david.lidstone.me\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/david.lidstone.me\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=56"}],"version-history":[{"count":2,"href":"https:\/\/david.lidstone.me\/blog\/index.php?rest_route=\/wp\/v2\/posts\/56\/revisions"}],"predecessor-version":[{"id":72,"href":"https:\/\/david.lidstone.me\/blog\/index.php?rest_route=\/wp\/v2\/posts\/56\/revisions\/72"}],"wp:attachment":[{"href":"https:\/\/david.lidstone.me\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=56"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/david.lidstone.me\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=56"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/david.lidstone.me\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=56"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}