Long time I was trying to explore if there is good unit test framework in PHP and recently got opportunity to work on for one of my projects. Its Simple Test PHP Unit Test Framework.
It has support for SSL, forms, frames, proxies and basic authentication. What makes Simple Test Framework immediately useful to the PHP developer is the internal web browser. This allows tests that navigate web sites, fill in forms and test pages. Being able to write these test in PHP means that it is easy to write integrated tests. An example might be confirming that a user was written to a database after a signing up through the web site.
There are basically two types of Test Case:
1. Unit Test Cases
a. The UnitTestCase class will typically generate test events when run and these events are sent to an observing reporter using methods inherited from UnitTestCase.
b. Autorun.php file does the expected work of pulling in the definitions of UnitTestCase. It collects all test classes in the current file and runs them automagically. It does this by setting up an exit handler.
Code Snippet:
Some of the Base Functions and their description:
- assertTrue($x) Fail unless $x evaluates true
- assertFalse($x) Fail unless $x evaluates false
2. Web Test Case
a. The WebTestCase includes facilities for navigation, content and cookie checks and form handling. Usage of these test cases is similar to the UnitTestCase.
b. Inorder to run test cases as part of a group, in this scenarion we use group testing. The test cases should really be placed in files without the runner code.
c. The setUp() method is run just before each and every test method.
d. The tearDown() is run just after each and every test method.
e. The name of the test case function is always prefixed by the word test. eg. if the test case is checklogin then you will require to
define the function as testchecklogin.
Code Snippet:
# For checking the response code of a URL
File: lastcraft_test.php
File: runlastcraft_test.php
# For checking the login functionallity
Some of the Base Functions and their description:
- getUrl() => The current location
- setMaximumRedirects($max) => Stop after this many redirects
- assertResponse($codes) => Pass if HTTP response matches this list
- assertField($name, $value) => Pass if an input tag with this name has this value
- setField($name, $value) => Sets the input tag with this name with this value
- clickSubmit($label) => Click the first button with this label
- assertText($name) => Pass if matches visible and "alt" text
- assertTitle($title) => Pass if title is an exact match
One can explore more on Simple Test PHP Unit Testing Framework Its pretty clean mechnism to follow your TDD
Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts
Saturday, May 7, 2011
Sunday, April 3, 2011
Using Google Earth API and KML for your business
Although its almost 6 yrs since when Google launched its Google Map API, and I built my first app around it for entrip.com, it has been evolving lot and lots of possibilities have been created.
A new application is result of new business requirement or introduction of new technology which can be used for solving old business problems.
Next step of Google Map api is now Google earth API, as processing power and bandwidth is going cheaper its becoming more feasible and attactive to build apps around google earth. A browser plugin makes google earth api more killing and pervasive.
The Google Earth Plug-in and its JavaScript API let you embed Google Earth, a true 3D digital globe, into your web pages. Using the API you can draw markers and lines, drape images over the terrain, add 3D models, or load KML files, allowing you to build sophisticated 3D map applications. The Google Earth API is a free service, available for any web site that is free to consumers.
Google Earth provides the following functionalities that adds to the advantage of using it:
The main new and interesting thing google introduces is KML ( Key Hole Markup Language ).
KML is a file format used to display geographic data in an Earth browser, such as Google Earth, Google Maps, and Google Maps for mobile. You can create KML files to pinpoint locations, add image overlays, and expose rich data in new ways. KML is used for the following reasons:
Using Above technologies just created a simple app which is just combination of
Goggle Earth API + KML Data + PHP + MYSQL + AJAX
Steps done taken are
1) Develope KML to locate particular co-ordinate and mark it using graphical shapes such are ring, polygon
2) Initialise the Google earth API
3) In-order to send the request to the PHP script Ajax has been implemented.
Some useful links
Using PHP and Mysql to generate KML
test your KML online tool
A new application is result of new business requirement or introduction of new technology which can be used for solving old business problems.
Next step of Google Map api is now Google earth API, as processing power and bandwidth is going cheaper its becoming more feasible and attactive to build apps around google earth. A browser plugin makes google earth api more killing and pervasive.
The Google Earth Plug-in and its JavaScript API let you embed Google Earth, a true 3D digital globe, into your web pages. Using the API you can draw markers and lines, drape images over the terrain, add 3D models, or load KML files, allowing you to build sophisticated 3D map applications. The Google Earth API is a free service, available for any web site that is free to consumers.
Google Earth provides the following functionalities that adds to the advantage of using it:
a. Google Street View
b. Google Aerial View
c. Google 3D buildings
and many more...
The main new and interesting thing google introduces is KML ( Key Hole Markup Language ).
KML is a file format used to display geographic data in an Earth browser, such as Google Earth, Google Maps, and Google Maps for mobile. You can create KML files to pinpoint locations, add image overlays, and expose rich data in new ways. KML is used for the following reasons:
a. Casual users
Description: Placemark homes, plan and document journeys.
b. Scientists
Description: See detailed mappings of natural resources and trends.
c. Non-Profits
Description: Highlight problems and advocate change
d. Students and Educators
Description: Explore historic and current places, people and events.
Using Above technologies just created a simple app which is just combination of
Goggle Earth API + KML Data + PHP + MYSQL + AJAX
Steps done taken are
1) Develope KML to locate particular co-ordinate and mark it using graphical shapes such are ring, polygon
2) Initialise the Google earth API
google.earth.createInstance('map3d', initCB, failureCB);
3) In-order to send the request to the PHP script Ajax has been implemented.
function addcityajax()
{
var data = "load=citydropdown";
$.ajax({
url: "get_kml_data.php",
type: 'GET',
data: data,
success: function(data){
//code to process kml data response
}
});
}
Some useful links
Using PHP and Mysql to generate KML
test your KML online tool
Saturday, May 16, 2009
Prologue
Hello firends..
There is prologue for every story, so why dont I.. As this is story of me and Open Source . Working with Open source for last 8-9 years of my IT career it was a overwhelming experience. I still remember days JDK1.1 was introduced and iting experience when EJB got introduced.. days when I memorized ACID properties saying A for Atomicity and C for concurrency..days when I started definining my own MVC architecture based on command design pattern . The warm welcome that we offered when struts got introduced.
Over the nine years thangs had been changed and lots of new things got introduced... lots of experiments been done, open source did not remain confined to Linux or J2EE. PHP came in big way.. apache evolved astonishingly. Journey to the Apache2.0 was mind blowing.. mod_rewrite, mod_proxy, mod_ext_filter, php modules, mod_cache its coming great. An then it was Ruby started very humbly but got into limelight with Rails framework. The days when I worked on ajax using XMLHTTP object and using document.getElementById to access DOM element to the days when we have jQuery and out of the box support for ajax using Rails Tags, isnt it interesting..
I am going to use this blog to share all my experience with these technologies and how they moulded me as they got evolved. How I helped my clients, friends and colleagues in my this journey to bring up applications/solutions for them.
I hope you will also cherish this with me.
Nilesh
There is prologue for every story, so why dont I.. As this is story of me and Open Source . Working with Open source for last 8-9 years of my IT career it was a overwhelming experience. I still remember days JDK1.1 was introduced and iting experience when EJB got introduced.. days when I memorized ACID properties saying A for Atomicity and C for concurrency..days when I started definining my own MVC architecture based on command design pattern . The warm welcome that we offered when struts got introduced.
Over the nine years thangs had been changed and lots of new things got introduced... lots of experiments been done, open source did not remain confined to Linux or J2EE. PHP came in big way.. apache evolved astonishingly. Journey to the Apache2.0 was mind blowing.. mod_rewrite, mod_proxy, mod_ext_filter, php modules, mod_cache its coming great. An then it was Ruby started very humbly but got into limelight with Rails framework. The days when I worked on ajax using XMLHTTP object and using document.getElementById to access DOM element to the days when we have jQuery and out of the box support for ajax using Rails Tags, isnt it interesting..
I am going to use this blog to share all my experience with these technologies and how they moulded me as they got evolved. How I helped my clients, friends and colleagues in my this journey to bring up applications/solutions for them.
I hope you will also cherish this with me.
Nilesh
Subscribe to:
Posts (Atom)
