Thursday, September 12, 2013

How to configure PHPUnit and Aptana Studio 3?

Try to get PHPUnit integrated with Aptana Studio 3 for my unit testing, discover that it is not straight forward. Aptana Studio 3 is not ready for that kind of tight integration. I have to make use of "External Tools" on Aptana Studio to launch PHPUnit through DOS command.

Assumption
- PEAR has been installed
- Running on Window 7
- Download PHPUnit 3.7.25 from https://github.com/sebastianbergmann/phpunit/ ("phpunit.phar" will be downloaded)
- Follow the Zend 2 sample tutorial to prepare the unit testing script http://framework.zend.com/manual/2.0/en/user-guide/unit-testing.html

Steps to configure

1. Install phpunit on your machine by running the command as described below in "Command Prompt" window with phpunit.phar in the same directory.
  
pear config-set auto_discover 1
pear install pear.phpunit.de/PHPUnit
2. Once phpunit has been installed, phpunit.bat file will be created in [PEAR_INSTALL_PATH]. Launch the "Command Prompt" window and type in the command as described below to check the version of PHPUnit.
phpunit --version
PHPUnit 3.7.25 by Sebastian Bergmann.
Note: "phpunit" command is working provided you right click "Command Prompt" icon and select "Run as administrator" to launch the "Command Prompt" window.

3. In Aptana Studio 3.0, "External Tools" menu will not be available in the "Run" menu. Steps as described below are required to turn on the "External Tools" option.
- Right click the "Web Perspective" and select "Customize" menu, "Customize Perspective" screen will be displayed.


- Select "Command Groups Availability" tab and check the "External Tools" check box as shown in the screenshots below.

- Click on "Ok" button to dismiss the "Customize Perspective" screen. Click on "Run" menu, "External Tools" will be displayed.

4. Select "Run" ->  "External Tools" -> "External Tools Configuration", the configuration screen will be displayed.


5. Fill in the details as described below
Name: PHPUnit

Location: [PEAR_INSTALL_PATH]\phpunit.bat
Note: Normally phpunit.bat is located at the PEAR installation path if PEAR is used to install PHPUnit.

Working Directory: ${project_loc}/module/Application/test
Note: Based on the tutorial provided by Zend2, http://framework.zend.com/manual/2.0/en/user-guide/unit-testing.html, this should be the folder that consists of "phpunit.xml.dist" file.

6. Select unit testing class, for example, "IndexControllerText.php", click on "Run" -> "External Tools" -> "PHPUnit", the unit testing script will be executed and test result will be output to "Console" screen.

Friday, September 6, 2013

Issue encounter and simple note on Mantis exploration

System Environment
Mantis Version: 1.2.15
WAMP version 2.4

How to configure email notification on Mantis using Gmail SMTP Server?

Note: Assume Gmail account has been created

Steps to resolve
1. Open config_defaults_inc.php, edit the parameters as described below:
/**
  * Allow email notification.
  * Set to ON to enable email notifications, OFF to disable them. Note that
  * disabling email notifications has no effect on emails generated as part
  * of the user signup process. When set to OFF, the password reset feature
  * is disabled. Additionally, notifications of administrators updating
  * accounts are not sent to users.
  * @global int $g_enable_email_notification
*/
$g_enable_email_notification = ON;

/**
  * select the method to mail by:
  * PHPMAILER_METHOD_MAIL - mail()
  * PHPMAILER_METHOD_SENDMAIL - sendmail
  * PHPMAILER_METHOD_SMTP - SMTP
  * @global int $g_phpMailer_method
*/
$g_phpMailer_method = PHPMAILER_METHOD_SMTP;

/**
  * This option allows you to use a remote SMTP host.  Must use the phpMailer script
  * One or more hosts, separated by a semicolon, can be listed.
  * You can also specify a different port for each host by using this
  * format: [hostname:port] (e.g. "smtp1.example.com:25;smtp2.example.com").
  * Hosts will be tried in order.
  * @global string $g_smtp_host
*/
$g_smtp_host = 'smtp.gmail.com';

/**
  * These options allow you to use SMTP Authentication when you use a remote
  * SMTP host with phpMailer.  If smtp_username is not '' then the username
  * and password will be used when logging in to the SMTP server.
  * @global string $g_smtp_username
*/
$g_smtp_username = '[GMAIL_ACCT_ID]';

/**
  * SMTP Server Authentication password
  * @global string $g_smtp_password
*/
$g_smtp_password = '[GMAIL_ACCT_PASSWD]';

/**
  * This control the connection mode to SMTP server. Can be 'ssl' or 'tls'
  * @global string $g_smtp_connection_mode
*/
$g_smtp_connection_mode = 'ssl';

/**
  * The smtp port to use.  The typical SMTP ports are 25 and 587.  The port to use
  * will depend on the SMTP server configuration and hence others may be used.
  * @global int $g_smtp_port
*/
$g_smtp_port = 465;

How to send email using simple SMTP command through Gmail SMTP Server?

Note: 
- Assume Perl is installed on your machine to encode both user id and password in base64.
- Assume OpenSSL is available on your machine

Steps to resolve

1. Using openssl to direct connect to the Gmail SMTP server, a SSL handshaking will be executed.
openssl s_client -connect smtp.gmail.com:465 -crlf -ign_eof

2. Type in the command below to introduce yourself to the mail server.
ehlo [MY_DOMAIN] //Note: ehlo localhost

3. Before hand, please use Perl on another command prompt to encode both your [GMAIL_USER_ID] and [GMAIL_USER_PASSWORD] into base64. Below are the command helping you to generate encoded user id and password for authentication purpose.
perl -MMIME::Base64 -e "print encode_base64(qq(\000[GMAIL_USER_ID]\@gmail.com\000[GMAIL_USER_PASSWORD]))"
Once the command has been executed, you will get an encoded output, let's assume it as [BASE64_USERID_PASSWORD]

4. Back to your SMTP command prompt, type in the command as shown below to pass the authentication
AUTH PLAIN [BASE64_USERID_PASSWORD]
Response "2.7.0 Accepted" will be prompted

5. Type in the command below to set the sender gmail id
MAIL FROM: <[SENDER_GMAIL_ID]@gmail.com>

6. Type in the command below to set the recipient gmail id
RCPT TO: <[RECIPIENT_GMAIL_ID]@gmail.com>

7. Enter the command "DATA" to proceed with composing the email subject and body.
DATA

8. Enter the email body and subject based on the description and shown below
Subject: Hello Testing

Hello Testing!
.
Note: The '.' is represented the email composing has been completed and trigger sent command

How to resolve Mantis email problem when WAMP 2.4 is used?

Configure email notification on Mantis that run on WAMP 2.4 through Gmail SMTP server, always unable to send email. Have a further investigation, discovered that I need to turn on php_openssl in my WAMP PHP extensions. When turn on the php_openssl extension, encounter the error as shown in the log file.
[Mon Sep 09 14:57:33.670249 2013] [mpm_winnt:notice] [pid 1544:tid 352] AH00418: Parent: Created child process 2280
[Mon Sep 09 14:57:34.174249 2013] [ssl:warn] [pid 2280:tid 244] AH01882: Init: this version of mod_ssl was compiled against a newer library (OpenSSL 1.0.1e 11 Feb 2013, version currently loaded is OpenSSL 1.0.1d 5 Feb 2013) - may result in undefined or erroneous behavior
[Mon Sep 09 14:57:34.909049 2013] [ssl:warn] [pid 2280:tid 244] AH01882: Init: this version of mod_ssl was compiled against a newer library (OpenSSL 1.0.1e 11 Feb 2013, version currently loaded is OpenSSL 1.0.1d 5 Feb 2013) - may result in undefined or erroneous behavior
[Mon Sep 09 14:57:35.824849 2013] [ssl:warn] [pid 2280:tid 244] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache]
From the error log, seems like OpenSSL version is not correct and I found out the hyperlink as described below to explain steps to upgrade the OpenSSL version.

http://stackoverflow.com/questions/17354788/enabling-openssl-in-wamp

Once the OpenSSL version is upgraded to version OpenSSL 1.0.1e, I am able to turn on php_openssl in my WAMP PHP extensions and finally email notification is working in my Mantis installation.

How to turn on LDAP authentication on Mantis?

To turn on the LDAP authentication on Mantis that normally required by corporate users, below are some tips on how to achieve it.

Steps to resolve

1. Open config_defaults_inc.php, edit the parameters as described below:
/**
* login method
* MD5, LDAP, BASIC_AUTH or HTTP_AUTH.
* Note: you may not be able to easily switch encryption methods, so this
* should be carefully chosen at install time. However, MantisBT will attempt
* to "fall back" to older methods if possible.
* @global int $g_login_method
*/
$g_login_method = LDAP;

//Examples, ldap://ldap.example.com:389
$g_ldap_server = 'ldap://[LDAP_SERVER]:389';


//Examples, dc=employee,dc=it,dc=departmentname,dc=companyname
//Note: Please use the most exact DN instead of global DN. Otherwise,
//Mantis will keep throwing empty response and the application will always 
//show empty page
$g_ldap_root_dn = '[LDAP_DN_PARAMETER]';

//Use sAMAccountName for Active Directory
$g_ldap_uid_field = 'sAMAccountName';

/**
* The distinguished of the user account to use for binding to the LDAP server.
* For example, 'CN=ldap,OU=Administrators,DC=example,DC=com'.
*
* @global string $g_ldap_bind_dn
*/
$g_ldap_bind_dn = '[DOMAIN_NAME]\[USERNAME]';

/**
* The password for the service account to be used for connecting to the LDAP server.
*
* @global string $g_ldap_bind_passwd
*/
$g_ldap_bind_passwd = '[PASSWORD]';

/**
* Should we send to the LDAP email address or what MySql tells us
* @global int $g_use_ldap_email
*/
$g_use_ldap_email = ON;

/**
* The LDAP Protocol Version, if 0, then the protocol version is not set.  For Active Directory use version 3.
*
* @global int $g_ldap_protocol_version
*/
$g_ldap_protocol_version = 3;

How to turn on debug message in Mantis for LDAP troubleshooting?

To turn on the debug message for LDAP troubleshooting, below are the steps and configuration that are required

Steps to resolve
1. Open php.ini which is located at "[WAMP_INSTALL_PATH]\bin\apache\Apache2.4.4\bin".
2. Uncomment 'error_log = "[WAMP_INSTALL_PATH]/logs/php_error.log"'
3. Open config_defaults_inc.php in Mantis, change the value of g_log_level to LOG_LDAP
$g_log_level = LOG_LDAP;
Restart your WAMP server, LDAP log will be available at [WAMP_INSTALL_PATH]\logs\php_error.log.

How to reset your mysql user account password through command line?

Open your mysql browser, type in the command as displayed below

UPDATE mysql.user SET Password=PASSWORD('[MyNewPass]') WHERE User='root';
FLUSH PRIVILEGES;
Relogin again.

Wednesday, September 4, 2013

How to use cocospods in managing library dependencies in your iOS project?

In the process of exploring MMDrawerController library, discover cocoapods that are quite useful in managing library dependencies in my iOS project.

In general, CocoaPods is equivalent to MAVEN in J2EE project. Lets walk through all the necessary steps to get the concept on how it works.

Assumption
- Ruby MRI 2.0.0 or 1.8.7 (ships with Mac OS X)

Install CocoaPods
- Open Mac terminal
- Enter "sudo gem install cocoapods" and enter administrator password
- Type in command "pod setup" to install CocoaPods.
- Navigate to the project folder, enter "touch Podfile" command to create Podfile
- Enter command "open -e Podfile" to launch the text editor
- Edit the Podfile file with the configuration as shown below
platform :ios, '5.0' 
pod 'MMDrawerController', '~> 0.4.0'
- Navigate to the project folder that you wish to import the library through cocoa pods.
- Enter "pod install", MMDrawerController will be imported, a project file with ".xcworkspace" extension will be created.
- Open project file with the extension ".xcworkspace", a "Pods" project will be included. All the imported library will be included in the "Pods" project.

Tuesday, September 3, 2013

How to integrate VisualSVN, TortoiseSVN and Aptana to create a PHP development environment?

In setting up my PHP development environment, I have made use of the software listed below :-  
- Aptana Studio 3 (IDE)
- VisualSVN Server Manager version 2.6.4 (Source control application)
- TortoiseSVN 1.8.1 (SVN client)

Note: Assume both Aptana and VisualSVN, TortoiseSVN have been installed on the same or different machine.

Below are the details to get the environment up:-
1. Open VisualSVN Server Manager, right click "Repositories" and select "Create New Repository..." menu.


2. Enter "Repository Name", for example "efront", click on "Next" button.
3. Select "Single-project repository (with the top-level 'trunk', branches' and 'tags' folders)" radio button, click on "Next" button.
4. Select "All Subversion users have Read/Write access" radio button, click on "Create" button.
5. "Repository Name" and "Repository URL" will be displayed, click on "Finish" button.

Note: SVN administrator will be responsible to create the repository for the team lead/developer. [REPOSITORY_URL] will be provided by administrator to team leader/developer.

6. Assume you are team leader/developer now, you have a new project, you are going to check in your source code into the new repository. Create a new folder and check out the source code using the repository url ([REPOSITORY_URL]\trunk) using TortoiseSVN client.

7. Copy the source code into the checkout folder, right click on the "efront" folder, select TortoiseSVN -> Add. Click on "Ok" button.

8. Right click on the "efront" folder, select "SVN Commit" menu, a dialogue box will be popup. Enter some comment and click on "Ok" button. The source code will be committed to the SVN server.

Note: Team leader will provide the [REPOSITORY_URL]  to developer. Developer will launch Aptana Studio to check out the source code. Assume developer account creation has been completed by SVN administrator.

9. Developer launch Aptana Studio, click on File -> Import to import project from SVN.


10. Enter the repository url and authentication details. Click "Next" button.

Note: If you wish to checkout those source code in trunk for development, please enter URL as "[REPOSITORY_URL]\[PROJECT_NAME]\trunk". When the message "Do you wish to normalize URL by cutting its last segment off?" just select "No" because you are intended to checkout source code from trunk folder.


11. In "Select Resource" screen, just click "Finish" button.
12. In "Check Out As" screen, click on "Finish" button.
13. In "Select a wizard" screen, select "PHP Project" and click on "Next" button.
14. In "New PHP Project" screen, enter your "Project name" and the location of the source code. Click on "Finish" button.

Up till now, developer should be able to get their environment up in Aptana Studio for development.

15. When source code committing is required, right click on the "Project name" in Aptana Studio and select "Team" menu. All the SVN features will be displayed.


Why "Syntax error" message is prompted on Aptana Studio 3.0 when "trait" is using on the php class?

Discover that Aptana Studio 3.0 don't support new syntax from PHP version 5.4, it supports only up to  PHP version 5.3. This is really inconvenient to see a red "X" mark or "Syntax error" messages that appear everywhere in all the classes in my project. I just turn off the PHP Project Natures from the project to clean up those unnecessarily errors prompt.

Steps to turn off PHP as the "Project Natures"
1. Right click project name, select "Properties" menu
2. Select "Project Natures" and unckeck "PHP" checkbox, click on "Ok" button.
3. Close on reopen project dialogue box will be prompted, just follow the instruction.
4. Select "Project" -> "Clean..." menu to refresh the project, all the red "X" marks and "Syntax error" messages will be cleared.

Just a workaround for me who easily getting confused by the error prompt in the IDE. Still waiting for Aptana to support PHP version 5.4.