Tài liệu Agile software development with PHPUnit doc

74 421 0
Tài liệu Agile software development with PHPUnit doc

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

JUNE 2003 VOLUME II - ISSUE The Magazine For PHP Professionals PHP Unit Testing Agile software development with PHPUnit Industrial strength MVC Building a reusable development framework with Open Source tools Getting a grip on LDAP A coder's introduction to working with directory services Implementing search with Lucene Integrating a Java search engine API into your PHP site Use OOP to manage your forms www.phparch.com Implementing object-oriented form libraries that promote uniformity and reusability The WURFL project Extreme cross-platform WAP development with PHP Plus: Tips & Tricks, Product Reviews and much more Introducing the php|architect Grant Program This is the LAST month to submit your project for approval The deadline is June 18th! Hurry and submit your proposal As PHP’s importance grows on the IT scene—something that is happening every day—it’s clear that its true capabilities go well beyond what it’s being used for today The PHP platform itself has a lot of potential as a general-purpose language, and not just a scripting tool; just its basic extensions, even discounting repositories like PEAR and PECL, provide a highquality array of functionality that most of its commercial competitors can’t afford without expensive external components At php|a, we’ve always felt that our mission is not limited to try our best to provide the PHP community with a publication of the highest possible quality We think that our role is also that of reinvesting in the community that we serve in a way that leads to tangible results To that end, this month we’re launching the php|architect Grant Program, a new initiative that will see us award two $1,000 (US) grants to PHP-related projects at the end of June Participating to the program is easy We invite all the leaders of PHP projects to register with our website at http://www.phparch.com/grant and submit their applications for a grant Our goal is to provide a financial incentive to those projects that, in our opinion, have the opportunity to revolutionize PHP and its position in the IT world In order to be eligible for the Grant Program, a project must be strictly related to PHP, but not necessarily written in PHP For example, a new PHP extension written in C, or a new program in any language that lends itself to using PHP in new and interesting ways would also be acceptable The only other important restriction is that the project must be released under either the LGPL, the GPL or the PHP/Zend license Thus, commercial products are not eligible Submit Your Project Today! Visit http://www.phparch.com/grant for more information TABLE OF CONTENTS php|architect Departments INDEX EDITORIAL RANTS Features Building a reusable development framework with open source tools By Jason E Sweat Rant Mode: On - the PHP/MySQL 'Platform' NEW STUFF Industrial Strength MVC 24 Agile Software Development With PHPUnit By Michael Hüttermann 38 REVIEW SourceGuardian Pro By Peter James 59 Lucene Integrating a Java search engine API into your PHP site By Dave Palmer REVIEW PHPEdit By Peter James 70 30 TIPS & TRICKS By John W Holmes 42 Tailoring W@P sites with WURFL By Andrea Trasatti 49 Getting a grip on LDAP By Brian K Jones 73 exit(0); Worlds Apart By Marco Tabini 62 Object-oriented Form Management With PHP By Marco Tabini June 2003 · PHP Architect · www.phparch.com The designers of PHP offer you the full spectrum of PHP solutions Serve More With Less Zend Performance Suite Reliable Performance Management for PHP Visit www.zend.com for evaluation version and ROI calculator Technologies Ltd EDITE O D R IT IA O LRR IAA LNTS EDITORIAL Rant Mode: On - the PHP/MySQL 'Platform' Recently, it has come to my attention that there are some informational channels that have taken to calling ‘PHP/MySQL’ a ‘platform’, in the same vein as ASP.NET, J2EE and the like This, in my opinion, is nothing short of a travesty I will not name names (for the most part) regarding individual culprits, because it would only give them publicity However, there is a certain developer’s website which fails to list PHP without MySQL by its side It has ‘PHP & MySQL Tips and Tutorials’, ‘PHP & MySQL Apps and Reviews’, and a couple of other departments devoted to the PHP/MySQL ‘platform’, without a single hint that PHP can be used in other ways In addition, documentation for a certain large company’s commercial IDE also refers to this popular duo as a ‘platform’ Probably the most surprising offenders in the perpetuation of this stereotype are the PHP conference organizers MySQL plays such a prominent role in the talks and tutorials at PHP conferences that, if you go to one with no experience in PHP, you would leave thinking that PHP is primarily an interface to the MySQL database! This is unfortunate, to put it lightly Truthfully, it disgusts me Unfortunately, there are a number of conditions which currently exist in the world of PHP that could arguably be used to justify the actions of these groups For example, have you done a search for ‘PHP MySQL’ at Amazon lately? I did this recently and June 2003 · PHP Architect · www.phparch.com php|architect Volume II - Issue June, 2003 Publisher Marco Tabini Editor-in-Chief Brian K Jones brian@phparch.com Editorial Team Arbi Arzoumani Brian Jones Peter James Marco Tabini Graphics & Layout Arbi Arzoumani Administration Emanuela Corso Authors Andrea Trasatti, Brian K Jones, Dave Palmer, Jason E Sweat, Marco Tabini, Michael Hüttermann, Peter James php|architect (ISSN 1705-1142) is published twelve times a year by Marco Tabini & Associates, Inc., P.O Box 3342, Markham, ON L3R 6G6, Canada Although all possible care has been placed in assuring the accuracy of the contents of this magazine, including all associated source code, listings and figures, the publisher assumes no responsibilities with regards of use of the information contained herein or in all associated material Contact Information: General mailbox: Editorial: Subscriptions: Sales & advertising: Technical support: info@phparch.com editors@phparch.com subs@phparch.com sales@phparch.com support@phparch.com Copyright © 2002-2003 Marco Tabini & Associates, Inc — All Rights Reserved EDITORIAL counted 16 books devoted solely to the use of PHP with MySQL as a data source! Here is the very real truth: MySQL is NOT the only data source PHP is capable of working with There are scores of developers who need to know this Pass it on Quite honestly, I’m tired of downloading applications from Freshmeat and elsewhere which require MySQL, only to find that they also contain PHP code to implement some feature that should be offloaded to (or better, built into) the database! This extra code introduces bugs, makes it more difficult to maintain, and inevitably slows down the application, and in the process makes PHP look unnecessarily slow and bulky Note that this is not a rant targeted at people who are using MySQL because they have properly evaluated their needs and found it to be the best tool for the job Nor is it aimed at newbies using MySQL as an introduction to the world of data-driven development I’m simply trying to enlighten some poor souls who might think that MySQL is the only choice they have when it comes to using PHP for their development needs PHP has native support for Sybase, Oracle, DB2, Informix, MS SQL Server, and other databases (yes, there are other databases) Aside from databases, PHP has native support for alternative sources of data such as SNMP agents and LDAP directories In short, PHP is a very capable development platform without the help of MySQL In this month’s issue of php|architect, you can capture a glimpse of a couple of June 2003 · PHP Architect · www.phparch.com these different data sources in action As promised, I’ve written a coder’s overview of using PHP with LDAP It’s a very highlevel, gentle discussion, light on code and long on cold, hard facts you’ll need to know if a client’s environment ever forces you to code against an LDAP directory In addition, Jason Sweat returns this month with a look at using different ‘ready made’ open source tools and frameworks to lighten the load on enterprise application developers In the article, you’ll be able to get a feel for the kinds of things you can with some of the other databases out there (Jason’s article uses PostgreSQL, in particular) As always, php|architect will strive to bring you the information you’d expect from any publication of our kind This will include MySQL, of course However, we’ll also try to debunk any myths or misstatements regarding PHP that exist out in the wild, like the erroneous labeling of PHP and MySQL as some sort of unified ‘platform’ As always, your opinions on this and anything you find in the pages of php|architect are of great interest to all of us here – so make you voice heard in our inboxes or the forums at the php|architect website Enjoy! NEW STUFF What’s s New! NEW STUFF PHP and Java? F rom the rumor mill department—we've heard that something big is about to happen between Java and PHP, and that it will be announced at the JavaOne Conference on June 9th in San Francisco We not yet know what the announcement will be about—but rest assured that we have unleashed our hounds Keep an eye on our website on June 9th for more information! + MySQL Beta Certification Exam MySQL AB announced this month that the beta version of the MySQL Professional Certification exam is available With successful completion of the Professional Certification beta exam, you can earn a valid MySQL Professional Certification the most advanced MySQL credential to demonstrate strong proficiency in working with the MySQL database Through the MySQL certification program, MySQL software developers can earn one or more formal credentials that validate their knowledge, experience and skill with the MySQL database and related MySQL AB products This program now includes two certifications: MySQL Core Certification and MySQL Professional Certification The MySQL Core Certification provides MySQL users with a formal credential that demonstrates proficiency in SQL, data entry and maintenance, data extraction for reporting and more The MySQL Professional Certification is for the more experienced MySQL user who wants to certify his or her knowledge in MySQL database management, installation, security, disaster prevention and optimization For more information, visit MySQL.com June 2003 · PHP Architect · www.phparch.com = ? Pear Info Package Pear announced the release of a new info package This package generates a comprehensive information page for your current PEAR install The format for the page is similar to that for phpinfo() except using PEAR colors The output has complete PEAR Credits (based on the packages you have installed) and will show if there is a newer version than the one presently installed (and what it's state is) Each package has an anchor in the form pkg_PackageName - where PackageName is a casesensitive PEAR package name Visit PEAR.php.net to download the new package Mozilla Firebird Mozilla.org has announced the release of Firebird 0.6 Mozilla Firebird is a redesign of the Mozilla browser component, similar to Galeon, K-Meleon and Camino™, but written using the XUL user interface language and designed to be cross-platform This latest version includes:A New theme, Redesigned Preferences Window, Improved Privacy Options, Improved Bookmarks, Talkback Enabled, Automatic Image Resizing, Smooth Scrolling, MacOSx Support and much more For more information, or to download, visit Mozilla.org FEATURES FEATURES Industrial Strength MVC Building a Reusable Development Framework With Open Source Tools By Jason E Sweat In the May issue, “An Introduction to MVC Using PHP” showed you the general background and a simple demonstration script of the Model-View-Controller pattern This article aims to take you to the next step: applying these principals in a realistic application Introduction This article assumes that you have either read the aforementioned “An Introduction to MVC Using PHP” article, or that you are already somewhat familiar with the MVC pattern, OO programming in PHP, and have at least looked at the Phrame examples The previous article highlighted proper use of the MVC pattern, with business logic in the Model classes, presentation logic in the View classes, and application flow directed by the Controller classes (ActionController, Action, ActionForms and ActionForwards in Phrame) Where the previous article only stored data in the session, this article steps it up a notch towards the “real world” by making extensive use of a database The Application To give this article a little more “real world” flavor, I would like to start with a hypothetical set of requirements for the application The application is a management system for hyperlinks The people who commissioned the application have identified three key sets of requirements: users, administrators and infrastructure User: • The user will access this application as a web site • The list of links will be organized into groups June 2003 · PHP Architect · www.phparch.com • The main link list will contain all of the links in the application on a single page, so they can all be printed at once • Each page of the application will contain the current date • The user will be able to view a summary of all the link groups, and will be able to jump directly to that group on the main listing of links Administrator: • The Admin will be able to maintain the links using the web site • The site will be able to detect the Admin, and display a link to the editing pages as appropriate • The Admin will be able to add, modify or delete both link groups and links The Admin can change the sequence that both groups and links withing groups are presented in the application, ease of use is also important REQUIREMENTS PHP Version: 4.0.6 O/S: Any Database: PostgreSQL 7.3 Additional Software: Phrame, ADOdb, Smarty, Eclipse FEATURES • Security should be in place to prevent unauthorized users from becoming the application administrator, or from using the administrative functions without being authorized as the administrator Infrastructure • Security is a serious concern, in particular, and credentials used by PHP scripts to access the database should have the bare minimum rights required to perform the tasks required (in case the web site code is ever compromised) • The application needs to be “future proof”, specifically this web application might not be the only client and/or the only source/editor for links in this application • This application will transition to other resources for maintenance, so it is important that it is well structured for both flexibility and ease of maintenance • The application should be designed so HTML designers can alter the appearance of the application without changing any source code • The data should never become corrupted, i.e Links should never refer to a group that does not exist • To assist in debugging problems, the system should track the date and time at which groups and links are both created and modified Industrial Strength MVC A quick review of these requirements can tell us a few things The fact that the application is basically a web site means that PHP is certainly a leading candidate for implementation The requirement for transitioning to other resources to maintain the application, and the desire for a robust and flexible framework, push us in the direction of implementing an MVC-style application The fact that “each page” must have a date stamp, and possibly a link to the editing pages, tends to indicate we should establish some sort of a site rendering framework This is often implemented with headers and footers in templates Finally, with websiteindependent business logic, strict referential integrity, queries across multiple tables (at least if we model links and groups in separate tables) and date columns to be modified on each SQL request, it looks like we have moved somewhat beyond MySQL’s fast retrieval of simple queries sweet spot, and another RDBMS will be required Developing the Application To review the development of this application, I think it is appropriate to take a look at the overall infrastructure first, which dovetails into Models Next, reviewing how the Controller (Phrame) implements application flow in this application, and lastly how the views are implemented in this application Infrastructure The first decision is what language the web application will be constructed in Since this is a magazine devoted to PHP, I think that is an appropriate choice ;) The choice of PHP allows us to pull out our now familiar bag Nobody As the publishers of Ian's Loaded Snapshot we know OSCommerce! Hosts OSCommerce Better! 100's of OSCommerce powered sites rely on our years of experience with OSCommerce, direct We Guarantee It! PHP, mySQL and Curl Optimized for OSCommerce Free Shared Certificate & Integrated SSL Server 20+ Contributions Pre-Installed on MS1 Release Web Mail and Web Based File Manager Full FTP and phpMyAdmin Access Free Ongoing Hands-On Support Web Stats by Urchin Reports Free Installation and Configuration USE PROMO CODE: phpa Get an Extended Free Trial and Free Setup! June 2003 · PHP Architect · www.phparch.com 866-994-7377 or sales@chainreactionweb.com www.chainreactionweb.com www.chainreactionweb.com/reseller 10 ... reusable development framework with open source tools By Jason E Sweat Rant Mode: On - the PHP/MySQL ''Platform'' NEW STUFF Industrial Strength MVC 24 Agile Software Development With PHPUnit By... is distributed with Postgres, and you can read the Postgres documentation for instructions on how to install and use plpgsql (http://www.postgresql.org/docs/view.php?version=7.3&idoc=1&file=plpgsql.html)... on manipulation and presentation of the data without worrying about corrupting the data model with our SQL statements Security on the link table, as with the link_group table, grants no SELECT

Ngày đăng: 21/12/2013, 12:15

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan