Pak Jiddat

Read: In the name of thy Lord Who createth, Createth man from a clot. Read: And thy Lord is the Most Bounteous, Who teacheth by the pen, Teacheth man that which he knew not. Nay, but verily man is rebellious That he thinketh himself independent!. Lo! unto thy Lord is the return. (Sura Alalaq 96:8)

How to test Pak Php applications

Created On: 11 Apr, 2017: 12:28:45 - Tags : pak php framework | website testing


This article describes how to test Pak Php framework applications. The Pak Php framework provides support for unit testing and functional testing of applications. To test your Pak Php framework application you have to first put your application in test mode. You can do this by setting test_mode parameter in Configuration.php to true.

Unit Testing

To unit test your application, you need to enter the name of your test classes in test_classes parameter. You can have multiple test classes. Each test class should derive from the base application Test class. The Fully Qualified Class Name (FQCN) of the application Test class is \Framework\Testing\Testing. Next you have to write test functions in your test class. The name of each test function must start with Test and it should be defined as public. The test function takes one parameter as argument which is the test data. A test method has the following signature:
public function TestFunctionName($test_data)
To run your test function from the command line you have to enter following command:
php index.php
This will run all functions that start with Test in your test class. Alternately you can simply call the index.php script from the browser. Within your test function you can use AssertTrue and AssertEqual functions to test variable values.

Functional Testing

Functional testing a Pak Php application implies automatically calling the application functions. The output of the function is tested depending on the type of output. For example if a function returns a string, then the return value is considered to be html and is tested using W3C validator. If the function returns a json string and the string is valid json then the function is considered to be valid. The options to be tested are given in an array and assigned to the [testing]['test_options'] configuration parameter. If this parameter is omitted or it contains the string "all", then all options are tested. To start the functional testing you have to use the following command:
php index.php
Alternately you can simply run the index.php script from browser It is also possible to automatically generate test data for unit testing and functional testing. To automatically generate test data you have to set the configuration option save_test_data to true in Configuration.php. After that you can run your application normally from browser or command line. Each time the application is run, the application parameters are saved to database. Once the parameters are saved they can be used in unit tests and functional tests. To use the saved test data in unit tests you have to override the LoadTestData function of the base Testing class. This function needs to return the test data that will be given as parameters to the unit test functions. The test data is loaded from the database using FetchLogDataFromDatabase function of the Logging class. The test data is used automatically for functional tests. When a functional test is run, the framework automatically reads the test data from database and calls the application function with this test data. The function is called for each test data item.

Related Articles

  1. Managing Php scripts using the Pak Php Framework Admin Tool
  2. Developing WordPress plugins using Pak Php framework - Part 2
  3. Writing command line scripts using Pak Php framework
  4. Pak Php framework
  5. Developing WordPress plugins using Pak Php framework - Part 1
  6. Developing your own Php Utilities Framework