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 - » PHP Components: Planning An App That Uses Components
    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 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

    Original URL path: http://blog.stuartherbert.com/php/2011/03/23/planning-an-app-that-uses-components/ (2016-05-02)
    Open archived version from archive


  • Stuart on PHP - » PHP Components: Decomposing An App Into Components
    a meta package all it does is pull in all the other components that support creating and managing specific types of components Every time I find and fix a bug or add a new feature the bug fix or feature goes into one of the specific components such as ComponentManagerPhpLibrary but you don t need to keep track of them all All you have to do is pear upgrade phix ComponentManager and it takes care of upgrading all of the other components for you Where will your component be installed Components can be installed into two places on a computer system wide e g usr share php or inside an app e g vendor folder inside the app s code tree Does the component work in both places This is a question I personally wish the Doctrine developers had asked themselves At the time of writing Doctrine assumes that it will only be installed system wide making it a real pain in the backside if I want to run two or more separate apps that use Doctrine on the same server By forcing me to install Doctrine system wide they also force me to test and potentially fix all apps that use it in one go whenever I need to upgrade Doctrine The components built using ComponentManager can easily support installing into both system wide or inside an app to suit your choices and I ll show you exactly how that is done when we get there Can I get this functionality from an existing component from someone else Or put another way am I re inventing the wheel here Or living my not invented here dreams Today PHP components are at an embryonic state compared to our cousin languages There aren t all that many out there and support for the PSR0 autoloading standard is still to become widespread That said you should still take a look first before deciding to build your own component Folks like the Symfony 2 community seriously get components and are doing a great job in publishing high quality code that might just suit your needs Am I ever going to re use this code I ve saved the most important question for last Is it worth the trouble There isn t much practically in creating a component for the sake of it If you can t see yourself or anyone else ever re using the code put the code inside 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

    Original URL path: http://blog.stuartherbert.com/php/2011/03/23/decomposing-an-app-into-components/ (2016-05-02)
    Open archived version from archive

  • Stuart on PHP - » PHP Components: Creating A Skeleton Component
    skeleton improves pull requests are very welcome you can use the very handy phix php library upgrade command to get the improvements dropped right into your components Another bonus feature of adopting a standardised skeleton instead of rolling everything by hand In the next blog post we ll get build properties and package xml setup and get the vendor folder created What s the vendor folder I ll tell you next time 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 No Comments Christian Weiske says March 24th 2011 at 8 31 am You should really use a meta package to track and install your dependencies with a single command http pear php net manual en guide users dependencytracking php Stuart Herbert says March 24th 2011 at 9 36 am cw that would work if users did not need to manually channel discover Christian Weiske says March 24th 2011 at 8 31 am You should really use a meta package to track and install your dependencies with a single command http pear php net manual en guide users dependencytracking php Stuart Herbert says March 24th 2011 at 9 36 am cw that would work if users did not need to manually channel discover Manuel Pichler says March 24th 2011 at 6 38 pm sh pear config set auto discover 1 is your friend Stuart Herbert says March 24th 2011 at 8 49 pm Ah ha That will save a lot of effort And Sebastian will be able to simplify his install instructions for PHPUnit too Manuel Pichler says March 24th 2011 at 6 38 pm sh pear config set auto discover 1 is your friend Stuart Herbert says March 24th 2011 at 8 49 pm Ah ha That will save a lot of effort And Sebastian will be able to simplify his install instructions for PHPUnit too Manuel Pichler says March 24th 2011 at 6 40 pm sh by the way PHP Depend and PHPMD are already stable so you can omit the beta and alpha suffix Manuel Pichler says March 24th 2011 at 6 40 pm sh by the way PHP Depend and PHPMD are already stable so you can omit the beta and alpha suffix Brett Bieber says March 25th 2011 at 12 59 am Just FYI the PEAR2 Pyrus Developer tools have a skeleton generator built in php pyrus phar generate pear2 MyPackage Docs here http pear php net manual en pyrus commands generatepear2 php Pyrus also prompts for undiscovered pear channels if they aren t already discovered Stuart Herbert

    Original URL path: http://blog.stuartherbert.com/php/2011/03/24/creating-a-skeleton-component/ (2016-05-02)
    Open archived version from archive

  • Stuart on PHP - » PHP Components: Setting Up Your Component’s Metadata, Pt 1
    version of my component I m going to call this version of the component repustateApi 0 1 0 That means that I need to change the top four lines of build properties to look like this project name repustateApi project majorVersion 0 project minorVersion 1 project patchLevel 0 You can see the fullly edited build properties file on GitHub Why did I pick 0 1 0 as the version number What s In A Version Number When it comes to components we need to adopt a sane and engineering focused version numbering scheme otherwise we run into a lot of trouble when trying to trust our own and other people s components over time I went into this in some detail in my Beyond Frameworks talk and it basically boils down to this The scheme itself reads major minor patchLevel or if you prefer x y z All versions 1 y z must be 100 backwards compatible You can fix bugs and add new features but if you break backwards compatibility you need to create version 2 y z The people who use your components need to be confident that they can upgrade the component to get the latest fixes and features without any nasty surprises that force them to also go to the trouble of editing their own code Make the major version number your promise to other developers that they can upgrade safely Don t be afraid to create version 2 y z version 3 y z etc as rapidly as needed Google has done exactly this with Chrome and it hasn t exactly done them any harm If you re adding new features and not breaking backwards compatibility turn version 1 0 into version 1 1 1 2 and so on And if you re only putting out bug fixes just increase the last number and turn version 1 0 0 into version 1 0 1 1 0 2 and so on This numbering scheme is called Semantic Versioning Please do follow it That s all that we need to edit in build properties We still need to setup package xml which I ll cover in the next blog post 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

    Original URL path: http://blog.stuartherbert.com/php/2011/03/24/setting-up-your-components-metadata-pt1/ (2016-05-02)
    Open archived version from archive

  • Stuart on PHP - » PHP Components: Setting Up Your Component’s Package.xml File
    develop on shared servers or even if you end up maintaining a lot of components this is a real time saver If you run that command locally and look inside the vendor folder it creates you should see that our tools have downloaded and installed the Autoloader package that s listed in package xml s list of dependencies As we add more PEAR compatible packages to the package xml s dependency list we can rebuild the vendor folder and install all of the dependencies side by side I ve picked the repustateApi component because it will allow me to demonstrate that as we go along Please ignore the errors that you will see scroll up the screen when you run phing build vendor at this stage Unfortunately the PEAR installer doesn t seem to have a command to install just the dependencies i e pear install onlydeps listed It s also trying to install our component s PEAR compatible package which doesn t exist yet The Final package xml File You can see the final package xml file containing all of the edits listed in this blog post on Github As we work on the component and then release it we will need to come back and edit package xml a little more But we ve done what we need to for now and can get started on creating some code My apologies if it seems like a lot of work just to create an empty component and then sort out the component s metadata In all honesty after you ve done it a few times you can create a new component in a matter of minutes and this is work you only have to do the once In the next blog post we re going to start creating the initial tests for this component 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 No Comments Daniel O Connor says March 25th 2011 at 2 52 am A handy tool I love to use is PEAR PackageFileManager Cli pear install PEAR PackageFileManager Cli Then it s a simple pfm and follow the prompts PEAR Package File Manager Command Line Tool Please enter the location of your package Creating a new package file Enter the base install directory Enter the name of the package doconnor VALEX Channel or URI based package c c u c Enter the name of the channel pear php net Enter a 1 line summary Fish Enter a description 2 blank lines to finish Enter a description 2 blank lines

    Original URL path: http://blog.stuartherbert.com/php/2011/03/24/setting-up-your-components-package-xml-file/ (2016-05-02)
    Open archived version from archive

  • Stuart on PHP - » PHP Components: Adding Unit Tests For Your Component
    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 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

    Original URL path: http://blog.stuartherbert.com/php/2011/03/25/adding-unit-tests-for-your-component/ (2016-05-02)
    Open archived version from archive

  • Stuart on PHP - » PHP Components: Where To Put Your Component’s Unit Tests
    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 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 No Comments Raffael says March 25th 2011 at 9 36 pm This is a pretty awesome and useful blog series Cheers Raffael says March 25th 2011 at 9 36 pm This is

    Original URL path: http://blog.stuartherbert.com/php/2011/03/25/where-to-put-your-components-unit-tests/ (2016-05-02)
    Open archived version from archive

  • Stuart on PHP - » PHP Components: How To Run Your Component’s Unit Tests
    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 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 No Comments A semana no mundo PHP 01 04 2011 raphael dealmeida says April 1st 2011 at 5 23 pm How To Run Your Component s Unit Tests A semana no mundo PHP 01 04 2011 raphael dealmeida says April 1st 2011 at 5 23 pm How To Run Your Component s Unit Tests Patrícia says February 9th 2012 at 8 29 pm My tests didn t work How did the file bootstrap php appeared on the unit tests folder I think this may be the problem because I don t have it The log shows Buildfile opt lampp htdocs repustateApi build xml property Loading opt lampp htdocs repustateApi build properties property Loading opt lampp htdocs repustateApi dist lastBuilt lint phplint opt lampp htdocs repustateApi src php Gradwell RepustateApi Client php No syntax errors detected run unittests delete Deleting directory opt lampp htdocs repustateApi review code coverage mkdir Created dir opt lampp htdocs repustateApi review code coverage exec PHPUnit 3 6 10 by Sebastian Bergmann exec exec Usage phpunit switches UnitTest UnitTest php exec phpunit switches exec exec log junit Log test execution in JUnit XML format to file exec log tap Log test execution in TAP format to file exec log json Log test execution in JSON format exec exec coverage clover Generate code coverage report in Clover XML format exec coverage html Generate code coverage report in HTML format exec coverage php Serialize PHP CodeCoverage object to file exec coverage text Generate code coverage report in text format exec Default to writing to the standard output exec exec testdox html Write agile documentation in HTML format to file exec testdox text Write agile documentation in Text format to file exec exec filter Filter which tests to run exec group Only runs tests from the specified group s exec exclude group Exclude tests from the specified group s exec list groups List available test groups exec exec loader TestSuiteLoader implementation to use exec printer TestSuiteListener implementation to use exec repeat Runs the test s repeatedly exec exec tap Report test execution progress in TAP format exec testdox Report test execution progress in TestDox format exec exec colors Use colors in output exec stderr Write to STDERR instead of STDOUT exec stop on error Stop execution upon first error exec stop on failure Stop execution upon first error or failure exec stop on skipped Stop execution upon first skipped test exec stop on incomplete Stop execution upon first incomplete test exec strict Run tests in strict mode exec v verbose Output more verbose information exec debug Display debbuging information during test execution exec exec process isolation Run each test in a separate PHP process exec no globals backup Do not backup and restore GLOBALS for each test exec static backup Backup and restore static attributes for each test exec exec bootstrap A bootstrap PHP file that is run before the tests exec c configuration Read configuration from XML file exec no configuration Ignore default configuration file phpunit xml exec include path Prepend PHP s include path with given path s exec d key value Sets a php ini value exec exec h help Prints this usage information exec version Prints the version and exits exec exec debug Output debugging information Execution of target run unittests failed for the following reason opt lampp htdocs repustateApi build xml 210 40 Task exited with code 2 BUILD FAILED opt lampp htdocs repustateApi build xml 210 40 Task exited with code 2 Total time 0 1993 seconds Stuart Herbert says February

    Original URL path: http://blog.stuartherbert.com/php/2011/03/25/how-to-run-your-components-unit-tests/ (2016-05-02)
    Open archived version from archive



  •