archive-com.com » COM » S » STUARTHERBERT.COM

Total: 477

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".
  • Stuart on PHP - » Phix 0.15 Released
    to me A big thanks to everyone who attended my workshop at PHPNW11 in October for their feedback and feature requests for this release How To Install To install Phix we have handy one line install scripts on the Phix project homepage And I ve put together a screencast of how to install Phix on Ubuntu It s my first ever screencast so please be gentle How To Upgrade To upgrade from an earlier release of Phix please do the following sudo pear clear cache sudo pear upgrade phix phix4componentdev Once you ve upgraded phix itself don t forget to go into each of your components and run phix php library upgrade to upgrade all of the skeleton files build xml et al for your component What s Coming In Phix 0 16 Windows support hasn t happened yet but I hopefully have a volunteer who is going to look into that during February My priority for phix 0 16 is to make it easy to build phix based components in Jenkins based on Sebastian s Jenkins Template I m doing this next because I m not sure how much I ve got to change things to suit Jenkins so I d rather get it done sooner so it s done and out of the way And I promise that I haven t forgotten docblox support either Our roadmap has all the details About The Author Stuart has been writing PHP applications since 2003 and has been contributing to open source software since 1994 He was an early writer for php architect a co author of the Official Zend Certification Study Guide for PHP 4 and a regular speaker at conferences and user groups since 2004 When he s not designing software Stuart loves to explore the world through a

    Original URL path: http://blog.stuartherbert.com/php/2012/01/31/phix-0-15-released/ (2016-05-02)
    Open archived version from archive


  • Stuart on PHP - » phix
    and finally create and push the gh pages branch cd my pear repository git init pirum build git remote add origin git github com yourusername pear repository git git add git commit git branch gh pages git checkout gh pages git push u origin master git push origin gh pages Now you should receive a notification from GitHub can be sent via email too depending on your notification settings telling you that your page build was successful 2 It might take as long as up to 10 minutes before your pages will appear on http yourusername github com pear repository the first time you push your changes Following pushes should update the pages almost instantly Now on to see if it works as it should if pear channel discover http yourusername github com pear repository does not return any errors everything went fine You might want to check http yourusername github com pear repository using a browser to see if it has been uploaded first you will get a 404 if it is not Creating A PEAR Package Using Phix If you are using Phix to help maintain your project you have an environment which already is configured for generating PEAR packages But first you have to configure Phix so that it will generate the proper package xml file First we edit the project channel value in build properties project channel yourusername github com pear repository Then we go on to the package xml file most of the everyday stuff like adding files etc will be handled by Phix but the descriptions version history and package requirements need to be edited manually See the PEAR package xml documentation for more information Don t forget to bump version info in build properties and change log information in package xml when you are creating a new package version When you have got the package xml and build properties configured properly use the command phing pear package to create a PEAR package which will be placed in dist packagename X Y Z tgz Adding The Package To Your PEAR Channel To add a PEAR package you just use pirum add my pear repository my pear package X Y Z tgz cd my pear repository git commit a m Added my pear package X Y Z git push Then visit yourusername github com pear repository with your browser to see a list of all the uploaded packages Conclusion In the beginning there was only pear php net the only resource for PEAR packages in the world Then other package channels arrived and publishing your own PEAR package channel became really easy with Pirum Now you don t even need your own web server to host it you can host it on GitHub along with the source code for your PEAR package Now if we only can get some kind of PEAR channel aggregator or similar thing to avoid having to use channel discover for every new tool we want to install Footnotes The channel name must match the regular expression a zA Z0 9 a zA Z0 9 a zA Z0 9 You might want to turn off email notifications for successful page builds because the emails can easily pile up if you make many pushes Be the first to leave a comment Steps For Building A Test VM Posted by Stuart Herbert on September 18th 2011 in phix Toolbox Using virtual machines for testing software is great I can try out anything I want and there s never any risk of trashing my main dev machine which avoids hours of lost coding time I ve been using virtual machines since the 1990 s and frankly I couldn t develop without them I ve also got a lot of experience running a private cloud of VMs for one of the UK s fastest growing tech companies but that s a topic for another day or maybe a conversation over a nice whisky at one of the upcoming conferences Right now I m using them to test phix out on multiple Linux distros before release It s a sad fact of life that all of the major distros think they can create a better PHP than the folks upstream at PHP net intended and that unfortunately means that a default install of PHP on Ubuntu can t always run the same PHP code as a default install of PHP on Fedora I found this out the hard way with an early release of phix now every release gets tested in a small but growing library of test VMs before I push it up to my public website But the best thing of all You can backup a VM normally by creating a snapshot and then rollback to your snapshot in future resetting your test environment to a known state before you test again Perfect for this weekend s task which has been documenting and double checking the steps needed to install phix on Linux dev desktops I thought it would be useful to jog my own memory when the Linux distros release their next versions to write up the steps that I do when I create a new test VM Install Linux distro from latest available ISO image Run the software upgrade tools to make sure the system is fully patched Disable SELinux if it is enabled Make sure gcc and the Linux kernel headers are installed on the system Install VMWare tools for VMWare Workstation Fusion or VirtualBox Addons for VirtualBox OSE Use Firefox to install Google Chrome Install some useful dev tools curl and git At this point I shut down the virtual machine and take a snapshot before PHP is installed That s because I need to make sure that phix s upcoming installer script does the right thing when there is no PHP If you re building your own test VMs you ll probably want to get Apache PHP and MySQL installed and your app s vhosts serving static pages before

    Original URL path: http://blog.stuartherbert.com/php/category/phix/page/2/ (2016-05-02)
    Open archived version from archive

  • Stuart on PHP - » phix
    safely hard code the final installation location into your scripts it will vary from OS to OS and will also be different again if your component is installed into a vendor directory You ll need to locate these files using a different technique How Do I Locate The Data Files From My PHP Code Take a look at the top of the LibraryComponentFolder class from the ComponentManagerPhpLibrary component code lang php class LibraryComponentFolder extends ComponentFolder const DATA DIR DATA DIR ComponentManagerPhpLibrary php library code DATA DIR is a token that at runtime the PEAR installer expands to be the fully qualified path to the top of the computer s data dir Underneath that you need to remember to add your component s name to the path otherwise you ll be scratching your head and wondering why you can t find the data files The full instructions that tell the PEAR installer to expand this token are added to your component s package xml file when we build the PEAR compatible package I ll look at the final package xml file in detail towards the end of this series of blog posts How Do I Unit Test PHP Code That Relies On Data FIles There is one important downside to this technique any unit tests that rely on loading data from your data directory are going to fail because DATA DIR is only expanded when the PEAR installer installs your component At the time of writing I don t have an easy solution for this but leave it with me and I ll find a solution for this before the end of this series of blog posts Be the first to leave a comment PHP Components Shipping A Command Line Program Posted by Stuart Herbert on April 6th 2011 in Examples phix Toolbox In my Beyond Frameworks talk I explained how a component based architecture can help answer some of the important i e expensive questions you might face when creating long lived apps that rely on a PHP framework In this series of blog posts I m going to look at how to go about creating and working with components I m now going under the bonnet of our components and looking at the different file roles that the PEAR installer expects to find when we distribute our component as a PEAR compatible package One of the useful file roles allows us to install new command line programs such as PHPUnit or Phix onto a computer for everyone to use What Is A Command Line Program A command line program the script file role supported by the PEAR installer is a PHP script that your users run from inside Terminal or Command on Windows It allows you to put powerful tools in the hands of your users You can also run them as scheduled jobs via cron Where Do Command Line Scripts Go Inside The Component s Structure If we take a look at the phix component you ll find the command line program itself in the src bin folder src bin is meant to be a folder that holds the commands that you want installed into the computer system In theory you could put sub folders under here but this is not supported If you look at phix s actual code you ll see that the phix command line program loads code that exists in the src php folder of the component and is installed into usr share php when the PEAR installer installs the component Your classes should go in src php just like with any other component Where Do Command Line Programs Get Installed When you use the PEAR installer to install your component pear install phix phix all of the files in your component s src bin folder gets installed into usr bin on your computer The command line script src bin phix therefore ends up installed onto your computer as usr bin phix The reason why the PEAR installer installs your PHP code under usr bin is because this folder is normally part of a user s search path in Terminal That allows users to run your command line program simply by phix without having to specify the full path to your command line program I haven t seen it personally but there s always the possibility that some Linux distros and Mac OS X will install command line programs into a different folder You can see where the PEAR installer will put these files on your computer by running sudo pear config show grep bin dir PEAR executables directory bin dir usr bin How Do I Make My Command Line Program Executable You re probably used to running PHP scripts from the command line like this php my script php but for command line programs you don t want your users having to remember to run everything through the PHP interpreter each time UNIX and UNIX like operating systems such as Linux have a long tradition of writing command line programs using scripting languages If you put a shebang the characters hash pling at the top of your script you can tell your operating system how to execute your script usr bin env php php PHP code goes here The line usr bin env php tells your operating system to use the PHP CLI interpreter wherever it is in your Terminal s path to run this script Using usr bin env in this way normally makes your script portable across different Linux distros Be the first to leave a comment PHP Components Shipping Reusable PHP Code Posted by Stuart Herbert on April 5th 2011 in Examples phix Toolbox In my Beyond Frameworks talk I explained how a component based architecture can help answer some of the important i e expensive questions you might face when creating long lived apps that rely on a PHP framework In this series of blog posts I m going to look at how to go about creating and working with components I m now going under the bonnet of our components and looking at the different file roles that the PEAR installer expects to find when we distribute our component as a PEAR compatible package To get started I m going to start with the obvious file role the PHP code that a component is all about What Is PHP Code PHP code the php file role supported by the PEAR installer is your component s PHP code This is the code that you want everyone to download and install and then include into their own PHP apps Where Does PHP Code Go Inside The Component s Structure If we take a look at the CommandLineLib component you ll find all of the PHP code for this component under the src php folder src php is meant to be the top of a tree structure that any PSR0 compliant autoloader could load from The first level of folders under src php is by convention the name of the vendor of the code For CommandLineLib the vendor is Phix Project The second level of folder onwards can be whatever you need them to be By convention for our components at work we are using the second level of folders to be the name of the component in this case CommandLineLib This works really well as you start to build up a larger number of components in your PEAR channel And eventually you get down to the actual class definitions themselves The PHP class Phix ProjectCommandLineLibCommandLineParser therefore ends up in the file src php Phix Project CommandLineLib CommandLineParser php Where Does PHP Code Get Installed When you use the PEAR installer to install your component pear install phix CommandLineLib all of the files in your component s src php folder gets installed into usr share php on your computer The PHP class Phix ProjectCommandLineLibCommandLineParser therefore ends up installed onto your computer as usr share php Phix Project CommandLineLib CommandLineParser php The reason why the PEAR installer installs your PHP code under usr share php is because this folder is normally part of PHP s include path That allows developers to include your code simply by doing code lang php include Phix Project CommandLineLib CommandLineParser php code or better still by using a PSR0 compliant autoloader and then simply attempting to create a new instance of the class code lang php load the PSR0 compliant autoloader require once psr0 autoloader php create a new command line parser parser new Phix ProjectCommandLineLibCommandLineParser code Some Linux distros and Mac OS X will use usr lib php instead of usr share php You can see where the PEAR installer will put these files on your computer by running sudo pear config show grep php dir PEAR directory php dir usr lib php Be the first to leave a comment PHP Components ComponentManager 1 1 0 Released Posted by Stuart Herbert on April 4th 2011 in phix Toolbox In my Beyond Frameworks talk I explained how a component based architecture can help answer some of the important i e expensive questions you might face when creating long lived apps that rely on a PHP framework In this series of blog posts I m going to look at how to go about creating and working with components I ve just put out ComponentManager version 1 1 0 with the following hopefully useful changes Improvements To The php library Skeleton Once you ve setup your metadata phing build vendor will build with no errors I ve added an empty src php dummy php file so that a valid empty PEAR compatible package can be build and installed You ll want to remove this file when you start putting your own code into the component New build property project channel Set this to the name of your PEAR channel Automatically picked up by package xml now New build property pear local Set this to the folder where your local copy of your PEAR channel resides See my blog post for details about why you might want a local copy of your PEAR channel New build xml target publish local You can now do phing publish local to use pirum add your component to your local copy of your PEAR channel Bug Fixes For The php library Skeleton Now tested on both Ubuntu and Fedora 14 especially for phpcodemonkey Now excludes DS Store folders from the final component for those using these tools on OS X Now excludes svn folders from the final component Now excludes empty files from the final component How To Upgrade To upgrade your installation please do the following pear clear cache pear upgrade pear pear pear upgrade Gradwell ComponentManager Once the latest version of ComponentManager has been installed you can upgrade the skeletons of your existing components by doing cd where I put it my component phix php library upgrade You will then want to edit build properties to set the new properties added in this release Any problems let me know Be the first to leave a comment PHP Components Explaining File Roles Posted by Stuart Herbert on April 4th 2011 in Examples phix Toolbox In my Beyond Frameworks talk I explained how a component based architecture can help answer some of the important i e expensive questions you might face when creating long lived apps that rely on a PHP framework In this series of blog posts I m going to look at how to go about creating and working with components In previous articles I ve introduced you to the component skeleton that phix creates for you when you run the phix php library init command Our skeleton is designed to be extremely clean so that it is very easy to automatically generate your PEAR compatible component and its package xml file so that you don t have to maintain it yourself a process which would only end in tears At the heart of our skeleton are the design constraints imposed by the PEAR installer and that means the way it handles files differently depending on the file s role What Are File Roles A file s role is simply a way of telling the PEAR installer where you want the file installed The PEAR installer supports the following file roles data any data files that your component needs to read at run time doc documentation about your component php your PHP code script any command line scripts your component includes test your hopefully PHPUnit based tests www PHP code to be served by Apache plus a few more that are of no interest to authors of PHP components Where Do I Put Files For Each Role To make it extremely easy for the phing pear package command to auto generate your package xml file there s a folder in our component skeleton for each type of file Here s a handy summary showing you where to put your files inside your component based on their role data goes in the src data folder doc goes in the src doc folder php goes in the src php folder script goes in the src bin folder test goes in the src tests unit tests folder www goes in the src www folder In the next few articles I m going to look at each of these file roles in turn and show you in detail how the PEAR installer treats them and how to work with them in your own components starting with the php role Be the first to leave a comment PHP Components 3 Tips For Publishing Your Own PEAR Channel Posted by Stuart Herbert on March 31st 2011 in Examples phix Toolbox In my Beyond Frameworks talk I explained how a component based architecture can help answer some of the important i e expensive questions you might face when creating long lived apps that rely on a PHP framework In this series of blog posts I m going to look at how to go about creating and working with components In my last article I looked at how to publish your own PEAR channel and why today that s the best option for you and your projects It takes about 10 minutes to publish your first PEAR channel thanks to Fabien s work on creating Pirum But what is it like to actually work with your own PEAR channel on a long term basis What are the things you could do to make things as easy as possible Tip 1 Local Copy Of Your PEAR Channel Sometimes you develop a component for the sake of it but most of the time you end up writing your components and the app that needs them side by side This is what happened with phix et al and behind the scenes here it is also what is happening with the components for my example app called sental When that happens no matter how focused and skilled your unit testing is you ll want to release preview versions of your component try them in your app and then go back to your component and tweak things all before you re ready to share the next release of your component via your PEAR channel This is what the alpha and beta stability flags in package xml were originally designed for but it s more pragmatic to have a local private copy of your PEAR channel on your dev box and leave those stability flags well alone Here are the steps you need to follow to setup your own private copy of your PEAR channel on a Linux box Setup Apache on your dev box with a virtual host to publish your PEAR channel just like you have done on your public webserver Use pirum to create your PEAR channel s files on your dev box or even better see Tip 3 below Edit etc hosts to have the fully qualified domain name for your PEAR channel point to IP address 127 0 0 1 With this done every time you use the PEAR installer on your dev box to install something from your PEAR channel the PEAR installer will actually download your component from your private copy of your PEAR channel You can keep putting new copies of your component onto this private copy of your PEAR channel until you re satisfied with it and it doesn t matter that you re not actually bumping the version number of your component each time you do so because only you are affected And when you re ready to send this new version out into the world you just need to tag the release in source control and then upload your private copy of your PEAR channel to your public webserver Btw if you do a lot development disconnected from the internet like I do having a local copy of your PEAR channel is pretty much a must Tip 2 Tag Your Releases Once you ve decided that your component is ready to share with everyone on your PEAR channel that s the time to tag your release in source control It s dead easy to do and it gives you and anyone else who takes over maintenance of your code a record of what was in each release Here s how to do it in git stuart Devel sental repustateApi git tag a m Release 0 1 0 0 1 0 stuart Devel sental repustateApi git push tags origin master If you re publishing on GitHub you can then go to your component on there and forever more see your code for that release Here s the repustateApi component at version 0 1 0 on GitHub as a real example of tagged code An even better example is Sebastian Bergmann s PHPUnit project where at the time of writing there are 193 tags to see As an aside we really should be digitally signing these tags but that is a topic in its own right for

    Original URL path: http://blog.stuartherbert.com/php/category/phix/page/3/ (2016-05-02)
    Open archived version from archive

  • Stuart on PHP - » phix
    numbers when handling dependencies If you dig deep into package xml you ll find not only a version tag but also a stability tag Here s the tags from PEAR s HTTP Request2 s package xml at the time of writing version release 2 0 0beta2 release api 2 0 0 api version stability release beta release api beta api stability How To Depend On A Beta PEAR Component The fix we need to make to package xml is very simple simply depend on the beta version package name HTTP Request2 name channel pear php net channel min 2 0 0beta1 min max 2 999 9999 max package With this change made the PEAR installer does the right thing and installs HTTP Request2 just like I want it to It remains to be seen what will happen when HTTP Request 2 0 0 and beyond are released Will the PEAR installer download it or will I have to come back and edit the dependency in package xml I ll post news on that when the time comes With the right dependency information in package xml I can now get back to cranking out the code for the repustateApi component Be the first to leave a comment PHP Components How To Run Your Component s Unit Tests Posted by Stuart Herbert on March 25th 2011 in Examples phix Toolbox In my Beyond Frameworks talk I explained how a component based architecture can help answer some of the important i e expensive questions you might face when creating long lived apps that rely on a PHP framework In this series of blog posts I m going to look at how to go about creating and working with components Earlier today I created some very basic unit tests for my repustateApi component Unit tests are an essential part of developing your component but how do you run them Running Your Component s Code From The Command Line Many old skool developers choose to work largely from the command line You can happily run PHPUnit by hand from the command line yourself each time but if you re taking advantage of the extra data that PHPUnit can report back on that soon gets to be a lot of typing This is where the build xml file in our skeleton comes in handy To run your unit tests from the command line all you need to do is run the command phing test stuart Devel sental repustateApi phing test Buildfile home stuart Devel sental repustateApi build xml property Loading home stuart Devel sental repustateApi build properties lint phplint home stuart Devel sental repustateApi src php Gradwell Repustate Api Client php No syntax errors detected run unittests delete Deleting directory home stuart Devel sental repustateApi review code coverage mkdir Created dir home stuart Devel sental repustateApi review code c overage exec Executing command phpunit bootstrap home stuart Devel sental repustateApi src tests unit tests bootstrap php coverage html home stuart Devel sental repustateApi review code coverage coverage clover home stuart Devel sental repustateApi review logs phpunit xml home stuart Devel sental repustateApi src tests unit tests 2 1 exec PHPUnit 3 5 3 by Sebastian Bergmann exec exec EE exec exec Time 0 seconds Memory 4 00Mb exec exec There were 2 errors exec exec 1 GradwellRepustateApiClientTest testCanRetrieveSentimentScor eForTextByJson exec Exception oh dear exec exec home stuart Devel sental repustateApi src php Gradwell Repustate Api Client php 209 exec home stuart Devel sental repustateApi src php Gradwell Repustate Api Client php 151 exec home stuart Devel sental repustateApi src php Gradwell Repustate Api Client php 90 exec home stuart Devel sental repustateApi src tests unit tests php G radwell RepustateApi ClientTest php 70 exec exec 2 GradwellRepustateApiClientTest testCanRetrieveSentimentScor eForUrlByJson exec Exception oh dear exec exec home stuart Devel sental repustateApi src php Gradwell Repustate Api Client php 209 exec home stuart Devel sental repustateApi src php Gradwell Repustate Api Client php 151 exec home stuart Devel sental repustateApi src php Gradwell Repustate Api Client php 116 exec home stuart Devel sental repustateApi src tests unit tests php G radwell RepustateApi ClientTest php 83 exec exec FAILURES exec Tests 3 Assertions 1 Errors 2 exec exec Writing code coverage data to XML file this may take a moment exec exec Generating code coverage report this may take a moment Execution of target run unittests failed for the following reason home st uart Devel sental repustateApi build xml 108 40 Task exited with code 2 BUILD FAILED home stuart Devel sental repustateApi build xml 108 40 Task exited with cod e 2 Total time 0 5951 seconds That went bang in a spectacular way At this stage where we have tests but don t yet have a working Repustate API client that s exactly what should happen As I work through the code and satisfy the tests we should quickly get to the point where we have more tests and that they all pass Here s an example of another component our CommandLineLib which has many tests that all succeed just so that you can see what a successful test run should look like Buildfile home stuart Devel GWC CommandLineLib build xml property Loading home stuart Devel GWC CommandLineLib build properties lint phplint home stuart Devel GWC CommandLineLib src php Phix Project Comman dLineLib CommandLineParser php No syntax errors detected phplint home stuart Devel GWC CommandLineLib src php Phix Project Comman dLineLib ParsedSwitches php No syntax errors detected phplint home stuart Devel GWC CommandLineLib src php Phix Project Comman dLineLib DefinedArg php No syntax errors detected phplint home stuart Devel GWC CommandLineLib src php Phix Project Comman dLineLib DefinedSwitch php No syntax errors detected phplint home stuart Devel GWC CommandLineLib src php Phix Project Comman dLineLib DefinedSwitches php No syntax errors detected phplint home stuart Devel GWC CommandLineLib src php Phix Project Comman dLineLib ParsedSwitch php No syntax errors detected run unittests delete Deleting directory home stuart Devel GWC CommandLineLib review c ode coverage mkdir Created dir home stuart Devel GWC CommandLineLib review code co verage exec Executing command phpunit bootstrap home stuart Devel GWC Com mandLineLib src tests unit tests bootstrap php coverage html home stuart D evel GWC CommandLineLib review code coverage coverage clover home stuart D evel GWC CommandLineLib review logs phpunit xml home stuart Devel GWC Comman dLineLib src tests unit tests 2 1 exec PHPUnit 3 5 3 by Sebastian Bergmann exec exec 60 78 exec exec exec Time 1 second Memory 5 75Mb exec exec OK 78 tests 407 assertions exec exec Writing code coverage data to XML file this may take a moment exec exec Generating code coverage report this may take a moment echo echo The code coverage report is in home stuart Devel GWC CommandLine Lib review code coverage test BUILD FINISHED Total time 3 7912 seconds Command Line Test Run Explained The component s build xml file contains targets sequences of instructions that you can invoke by using phing When you run the command phing test here s what happens phing loads the build xml file in the current working directory So make sure you re in your component s top level folder when you run phing build xml sucks in the build properties file where we set the component s name and version number These properties are in a separate file so that it s safe to replace build xml with new versions as we improve the component s skeleton files in the future via the phix php library upgrade command phing runs the test target in build xml which tells it to actually run the lint and run unittests targets The lint target does a syntax check on all of your PHP files As your component grows and the time it takes to run your unit tests grows too a quick syntax check can save a developer wasting a surprising amount of time If the syntax check is successful the run unittests target runs next The run unittests target invokes PHPUnit telling it to use the skeleton s bootstrap file and to write out the results in XML format to feed into other tools later on It also tells PHPUnit to write out code coverage data as HTML We ll look at that in a later blog post Running Your Unit Tests From Netbeans If the command line isn t for you don t worry the component skeleton is also designed to make it very easy to run your unit tests from inside Netbeans I m assuming that it will be just as easy to do this from other IDEs that support PHPUnit but I haven t tested any myself First of all you need to setup your project in Netbeans to tell it where your tests are Open the project s properties dialog box and then set the Test Folder to be your unit tests folder Next open the PHPUnit settings in the project s properties dialog box and tick the Use Bootstrap box and then tell Netbeans to use the bootstrap file inside the unit tests folder so that the PHPUnit settings look like this Now we re all set to run the tests from inside Netbeans In the project browser simply right click on the Client php file and select Test from the popup menu Netbeans will run the tests for you and tell you exactly where they broke I hope you find these tools useful and time saving I m going to beaver away over the weekend getting several components completed and will be back on Monday to go through more of the things you need to know if you re going to successfully go Beyond Frameworks and shift to a component based architecture Have a great weekend Be the first to leave a comment PHP Components Where To Put Your Component s Unit Tests Posted by Stuart Herbert on March 25th 2011 in Examples phix Toolbox In my Beyond Frameworks talk I explained how a component based architecture can help answer some of the important i e expensive questions you might face when creating long lived apps that rely on a PHP framework In this series of blog posts I m going to look at how to go about creating and working with components I ve started work on creating the components for my simple app The first component is repustateApi which will be a PHP client for Repustate com s semantic analysis API With the component s metadata all done and the decision made to start with unit tests let s get the unit tests written and running The First Unit Tests Repustate s API is extremely simple to use making it the ideal choice for my first semantic analysis client It s very low risk to knock up a client and see if their API does the job if the API isn t suitable under heavy testing and I m forced to try someone else s semantic analysis API I haven t lost much time in the attempt As a result my initial unit tests can be extremely simple code lang php namespace GradwellRepustateApi class ClientTest extends PHPUnit Framework TestCase public function setUp this apiKey public function testCanCreateClient create the client with a valid key client new Client this apiKey did it work this assertTrue client instanceof Client public function testCanRetrieveSentimentScoreForTextByJson setup client new Client this apiKey text this is a happy piece of text do the test score client callScoreForText text json evaluate result here this assertTrue score false public function testCanRetrieveSentimentScoreForUrlByJson setup client new Client this apiKey url http www stuartherbert com do the test score client callScoreForUrl url json evaluate result here this assertTrue score false code and the skeleton class needed to execute those tests is just as simple code lang php namespace GradwellRepustateApi class Client protected apiKey null public function construct apiKey this setApiKey apiKey public function setApiKey apiKey this validateApiKey apiKey this apiKey apiKey public function validateApiKey apiKey TODO public function callScoreForText text format json placeholder return false public function callScoreForUrl url format json placeholder return false code Remember at this stage all I need to do is create unit tests that can be executed and will fail to allow me to model the API that this component will provide to the outside world By the time I m finished both the unit tests and the GradwellRepustateApiClient class will look quite different Where The Unit Tests And PHP Code Goes In our skeleton tests go into the src tests unit tests folder and the PHP code that the component will install into usr share php does into the src php folder Because we re using a PSR0 compliant autoloader for all components it s extremely easy to translate the name of a class into its full filename on disk GradwellRepustateApiClient goes into the file src php Gradwell RepustateApi Client php GradwellRepustateApiClientTest goes into the file src tests unit tests Gradwell RepustateApi ClientTest php This approach means that if needed we can scale to hundreds of components inside a single app and still only need the one autoloader The Component s Folder Structure So Far If I take the component structure and dump it out using the tree command here s a list of which files have gone where build properties build xml dist repustateApi 0 1 0 tgz LICENSE txt package xml README md src bin data php Gradwell RepustateApi Client php tests functional tests integration tests unit tests bin bootstrap php php Gradwell RepustateApi ClientTest php www www vendor php gwc autoloader php In the next blog post later this evening I ll show you have to run the tests in your component both from the command line and from inside Netbeans Be the first to leave a comment PHP Components Adding Unit Tests For Your Component Posted by Stuart Herbert on March 25th 2011 in Examples phix Toolbox In my Beyond Frameworks talk I explained how a component based architecture can help answer some of the important i e expensive questions you might face when creating long lived apps that rely on a PHP framework In this series of blog posts I m going to look at how to go about creating and working with components In my last article I finished editing the metadata for my component and then used the component s package xml file to download its dependencies and automatically install them into the vendor folder a local sandbox that we can recreate and destroy at any time We can now get stuck into what we all love doing the most writing code and that means starting with our unit tests Why does it Why You Should Unit Test Your Component There are many good reasons for ensuring your component has good unit tests Components are written to be used by many other developers Good tests ensure that your components will behave well in the hands of others which will save them time and enhance their trust in your future releases Good tests can serve as the best reference documentation for your code They can show others how your code was intended to be used in a way that they should be able to easily understand If you find yourself changing your tests in future releases it s a good way of making you pause and just have a think about whether you are actually breaking backwards compatibility without realising it As bugs are reported and fixed you can add additional tests for each bug to make sure that the bug doesn t sneak back into any future releases this is regression testing You can plug your unit tests into a Continuous Integration environment such as Jenkins to make sure no one in your team breaks your component with their next code check in These are all reasons that you have probably come across before and I m sure you ll come across them again before too long from many other bloggers You can watch Sebastian Bergmann creator of PHPUnit talk about this at phpuk2011 if you need further convincing Do watch the video especially if you re a World of Warcraft fan His talk at phpuk2011 was a big hit But there is another reason why components in particular need tests which you might not have seen before and it s all to do with how a component is different to hacking on a webapp TDD Unit Tests Come First Components are well suited to test driven design or test driven development if you prefer because they are standalone little chunks of code There s no website for you to point your browser at to test the components by hand The code inside your component only gets executed when someone writes some code of their own to call your code If you don t write the unit tests that means the first time your code runs will be when another developer downloads the code and tries it for himself What do you think is likely to happen Your code is likely to fail Is he going to fix your code or is he going to move on and look somewhere else for another solution Seeing as you need to write the tests anyway why not embrace test driven design and write the tests first Writing the tests first means that you re already starting to define the API that other developers are going to use It get you designing right from the very beginning with the end in mind how your code will be reused In this afternoon s blog post I ll show you where to put your tests and how to run them both from the command line and from within Netbeans Be the first to leave a comment PHP Components Setting Up Your Component s Package xml File Posted by Stuart Herbert on March 24th 2011 in Examples phix Toolbox In my Beyond Frameworks talk I explained how a component based architecture can help

    Original URL path: http://blog.stuartherbert.com/php/category/phix/page/4/ (2016-05-02)
    Open archived version from archive

  • Stuart on PHP - » phix
    another component or your app for now You can always break it out into a component at a later date This is exactly what I did with phix It started off as a single PEAR compatible package and as it evolved I extracted out more and more code into separate PEAR compatible packages when I felt it was worth doing so These are all questions about how to organise the code and it s this organisation this list of components and their dependency graph that then affects the design of the code inside each component It s good to start out with a plan but don t get hung up on it As you build the code and learn to feel what it s like to live with the list of components you ll probably want to make changes to make life easier There s nothing at all wrong with that So what could the component list for my example app look like Component Design For The Sentiment App If I apply these questions to the app I m building in these blog posts I end up with Components by type The orange components are going to contain useful code Either I m going to have to create them sental sentalXmlStore repustateApi lymbixApi rssFeeder or they already exist phix phix s dependencies The green components are meta packages to make it easy to manage creating and updating the code sentalApis sentalFeeders The blue component contains shared code sentalApiShared It s going to contain the interfaces that all the APIs will have to implement and will also hold any base classes or utilities that the APIs are likely to find useful I ve decomposed my requirements from this morning into a list of named components to tackle Whether it s the right list or not is too early to tell there s always more than one design that will work but this is what I m going with for now For the rest of this week s blog posts I ll focus on creating the repustateApi component Code at last And that should just about fingers crossed give me enough time at the weekend to fill in some of the other components before we pick things up again on Monday Be the first to leave a comment PHP Components Planning An App That Uses Components Posted by Stuart Herbert on March 23rd 2011 in Examples phix Toolbox In my Beyond Frameworks talk I explained how a component based architecture can help answer some of the important i e expensive questions you might face when creating long lived apps that rely on a PHP framework In this series of blog posts I m going to look at how to go about creating and working with components Components don t exist entirely in isolation They re built to solve a specific problem and ultimately to get used inside some sort of application or two To help explain one way to approach designing and building components blog post by blog post I m going to create a real app and its components showing you the workings involved and highlighting any decisions that were made along the way All the code will appear on GitHub so that you can tinker with it yourself too If you want to jump right in and figure it all out in your own way by taking existing code apart phix and the now separated out ComponentManager are both built as components in their own right Clone the git repos look at the phing targets in the build xml files and have a play Poke me on Twitter if you have questions If when you run into issues please file them on GitHub and I ll get them fixed for you Hopefully you re staying with me for the worked example app though I m going to start by defining what the final app needs to do App Requirements I need an app that will consume a bunch of blog posts off the net and summarise for me how many are positive articles and how many are negative articles I m going to use the data in future strategic planning sessions at work to add another perspective where it will be useful The app can be easily changed in future to analyse other data I m thinking of feeding it Flickr feeds too at some point to give my photography some much needed feedback Here s how I d summarise the technical requirements for this app The command line portion of the app will do the analysis running off a cron job The command line portion will analyse a list of RSS feeds loaded from a ini file The command line portion will use a web based API to score each blog article The value of zero will be neutral positive numbers mean the article is positive in tone and negative numbers mean that the article is negative in tone The command line portion will cache the results as XML files on disk just to keep the example simple The website part of the app will present the analysis consuming the summary data created by the cron job The app will be built as components to make it easy to share code between both parts of the app That should give us enough variety to be able to get into some non trivial examples With a very basic set of requirements documented before I go near any code my next step is to figure out a rough structure I need to decompose my requirements into an architecture That will be in the next blog post which will along this evening Be the first to leave a comment phix 0 11 and ComponentManager 1 0 Released Posted by Stuart Herbert on March 22nd 2011 in phix Toolbox In my Beyond Frameworks talk I explained how a component based architecture can help answer some of the important i e expensive questions you

    Original URL path: http://blog.stuartherbert.com/php/category/phix/page/5/ (2016-05-02)
    Open archived version from archive

  • Stuart on PHP - » 2014 » January » 07
    you ve installed the necessary dependencies first Any problems please let me know Storyplayer is the open source test automation tool built by DataSift Use it to bring your user stories to life using plain old PHP noDSL Create test environments deploy code test with real browsers shell commands and any PHP code and clean up afterwards all from your tests Write your tests once and run them against your dev test staging and production environments Storyplayer ships with 20 modules including support for Vagrant Amazon EC2 and ZeroMQ and can easily be extended with your own plugins About The Author Stuart has been writing PHP applications since 2003 and has been contributing to open source software since 1994 He was an early writer for php architect a co author of the Official Zend Certification Study Guide for PHP 4 and a regular speaker at conferences and user groups since 2004 When he s not designing software Stuart loves to explore the world through a camera lens spend time with his beloved guitars and continue his study to T ai Chi Chu an Taijiquan Be the first to leave a comment Latest Photos Categories phpnw 1 Beginner 2 Intermediate 3 Advanced Brighton PHP Conferences Opinion phix PHP In Business PSR Servers and Hosting Storyplayer Talks Toolbox Training Uncategorized Archives February 2016 January 2016 November 2015 October 2015 August 2015 March 2015 January 2014 May 2013 April 2013 March 2013 December 2012 November 2012 October 2012 September 2012 August 2012 July 2012 June 2012 May 2012 February 2012 January 2012 October 2011 September 2011 August 2011 July 2011 April 2011 March 2011 February 2011 October 2010 August 2010 July 2010 February 2010 January 2010 October 2009 September 2009 August 2009 May 2009 April 2009 March 2009 February 2009 January 2009 December

    Original URL path: http://blog.stuartherbert.com/php/2014/01/07/ (2016-05-02)
    Open archived version from archive

  • Stuart on PHP - » Storyplayer Slides From PHP London Talk
    Twitter If you can t see the embedded slides in this blog post they re available over on SlideShare Right now I m focused on completing the online documentation which is very much a work in progress and preparing v1 1 0 with further improvements About The Author Stuart has been writing PHP applications since 2003 and has been contributing to open source software since 1994 He was an early writer for php architect a co author of the Official Zend Certification Study Guide for PHP 4 and a regular speaker at conferences and user groups since 2004 When he s not designing software Stuart loves to explore the world through a camera lens spend time with his beloved guitars and continue his study to T ai Chi Chu an Taijiquan Comments are closed Latest Photos Categories phpnw 1 Beginner 2 Intermediate 3 Advanced Brighton PHP Conferences Opinion phix PHP In Business PSR Servers and Hosting Storyplayer Talks Toolbox Training Uncategorized Archives February 2016 January 2016 November 2015 October 2015 August 2015 March 2015 January 2014 May 2013 April 2013 March 2013 December 2012 November 2012 October 2012 September 2012 August 2012 July 2012 June 2012 May 2012 February 2012 January 2012 October 2011 September 2011 August 2011 July 2011 April 2011 March 2011 February 2011 October 2010 August 2010 July 2010 February 2010 January 2010 October 2009 September 2009 August 2009 May 2009 April 2009 March 2009 February 2009 January 2009 December 2008 November 2008 October 2008 September 2008 August 2008 June 2008 May 2008 April 2008 March 2008 January 2008 December 2007 November 2007 October 2007 July 2007 April 2007 March 2007 February 2007 January 2007 This Month May 2013 M T W T F S S Apr Jan 1 2 3 4 5 6 7 8 9

    Original URL path: http://blog.stuartherbert.com/php/2013/05/31/storyplayer-slides-from-php-london-talk/ (2016-05-02)
    Open archived version from archive

  • Stuart on PHP - » Slides from Brighton PHP: More Than Websites: PHP And The Firehose
    4 and a regular speaker at conferences and user groups since 2004 When he s not designing software Stuart loves to explore the world through a camera lens spend time with his beloved guitars and continue his study to T ai Chi Chu an Taijiquan Comments are closed Latest Photos Categories phpnw 1 Beginner 2 Intermediate 3 Advanced Brighton PHP Conferences Opinion phix PHP In Business PSR Servers and Hosting Storyplayer Talks Toolbox Training Uncategorized Archives February 2016 January 2016 November 2015 October 2015 August 2015 March 2015 January 2014 May 2013 April 2013 March 2013 December 2012 November 2012 October 2012 September 2012 August 2012 July 2012 June 2012 May 2012 February 2012 January 2012 October 2011 September 2011 August 2011 July 2011 April 2011 March 2011 February 2011 October 2010 August 2010 July 2010 February 2010 January 2010 October 2009 September 2009 August 2009 May 2009 April 2009 March 2009 February 2009 January 2009 December 2008 November 2008 October 2008 September 2008 August 2008 June 2008 May 2008 April 2008 March 2008 January 2008 December 2007 November 2007 October 2007 July 2007 April 2007 March 2007 February 2007 January 2007 This Month April 2013 M T W T

    Original URL path: http://blog.stuartherbert.com/php/2013/04/16/slides-from-brighton-php-more-than-websites-php-and-the-firehose/ (2016-05-02)
    Open archived version from archive



  •