Setting a PHP Project in Jenkins

Continuous Integration (CI) is the process by which a developer makes his/her contribution a part of the whole and ensures that it fits well in the whole, regularly. Using CI, its easy to cross-check all the updates/check-ins into the project automatically with pre-defined validations. Their are number of CI tools available that are either free or very cheap.Most popular CI tools available are Jenkins, Travis CI, Cruise Control, Teamcity etc.After some deliberations and discussion I short-listed Jenkins to use for CI in one of our PHP projects. Here are my experiences for the benefit of any one else trying to accomplish the same.

First time ever when I started evaluating Jenkins, following questions came to my mind:-

A) How to install Jenkins with basic configuration?

B) Plugins used to build a PHP project?

C) How to create a PHP project in Jenkins?

A. Commands used to install Jenkins in Linux:-

  1. yum install -y wget
  2. sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
  3. sudo rpm –import https://jenkins-ci.org/redhat/jenkins-ci.org.key
  4. sudo yum install jenkins
  5. sudo yum install java-1.7.0-openjdk
  6. firewall-cmd –zone=public –add-port=8080/tcp –permanent
  7. firewall-cmd –reload
  8. sudo /etc/init.d/jenkins restart
  9. systemctl restart jenkins.service
  10. Open http://localhost:8080 URL in browser and the below screen will open. It shows Jenkins is installed and running successfully.

B. Their are number of php plugins, the following are the basic ones those can be used:-

  • PHPUnit : – allows running automated tests on code (required).
  • PHP_CodeSniffer : analyse our code and detect errors in the coding standards.
  • PHPLOC : is used to analyse the size and structure of the code.
  • PHP_Depend : does static code analysis and provide metrics to evaluate the quality of code.
  • PHPMD : detects problem in the code. For analysis it use s the PHP_Depend analysis data.
  • PHPCPD : detects the duplicacy or copy/paste instances throughout the code base.
  • Clover PHP Plugin : used to provide code coverage reports from PHPUnit.
  • xUnit Plugin : This tools is used to publish the build execution results into Jenkins tool.

C. Set up PHP job into Jenkins:-

Before doing that, we have to check whether Ant installed on our server or not. If not, please install it.

Commands used to install Ant in Linux:
  1. sudo apt-get install ant
Now, what is ANT?

It helps in automating the software build process. It reads and processes a configuration file (contains tasks to be performed), also defines our project’s dependencies. Most used ANT configuration file name is build.xml. I also created the same and added to our project, so that Ant will work during Jenkins build creation process.

PHPUnit Configuration:

We can also configure the PHPUnit XML details into build.xml. So during the build process, the PHPUnit xml configuration also gets processed and the PHP unit test cases will be executed.

After all these set-ups, lets start creating/configuring our first PHP job in Jenkins.

Step 1: Click on “New Item” from the left menu. Enter the Item Name like “testPHPProject” and select “Freestyle project” option and hit the “OK” button.

Step 2: A new project with name “testPHPProject” created and its configuration page opens. Here we need to configure our PHP project.

In below screen, basic details are shown which has to be filled to configure the project. The details are as follows:-

1: In “Source Code Management” section, we have to provide how would Jenkins fetch the code base. For example, from GIT or the File System. Here, I have shown an example using a File System.

2: In “Build Triggers” section, we specify which method should be used for automatic build creation. If we have used GIT as “Source Code Management” tool, then we can choose an option to create build when anything changes in the repository. But in our example, we selected “Build periodically” and added vaue as “0 14 * * *”, which means everyday at 2 PM the build creation process will be started.

3: In “Build” section, a number of “build step” options are provided. Here since we are using Ant for build process, please choose “Invoke Ant” option and provide the absolute path of the Ant configuration file path in “Build File” textbox.

4: Jenkins also provides an option to add multiple “Post-build Actions”. Using this we can add multiple actions like Publish HTML, JAVADoc, Clover PHP coverage report and many others.

Here, I have chosen “Publish Clover PHP Coverage Report”. To publish it we have to provide the Clover XML Location.

Step 3: Click Save. The project will be configured.

Step 4: Click use Build Now option to create our first project build.

What’s in Store with Android O: Here ye, Android Developers!

Google team has announced the preview release of Android O, here are some changes for the developer with documentation and API differences.

  1. In new API changes, each page which is returned by the Content provider will be counted as a single Cursor object.
  2. Android O will allow you to customize the pairing request dialog when trying to pair with companion devices over Bluetooth, BLE, and Wi-Fi.
  3. There is a specific disk space for each app for caching data. You can get it using-getCacheQuotaBytes(File).
  4. Introduced OpenJDK Java language features in Android.

Here Comes the Android O : Everything About Upcoming Android OS. - Wildnet

Fonts using XML file

You can now use fonts as resources as it is a new feature introduced in Android O. There is no need to keep all fonts in assets. You can access these fonts with the help of newly introduced type, font.

Adaptive Icons

There is this new feature of adaptive launcher icon in Android O that supports visual effects and can display a variety of shapes across different device models. For example– you can configure launcher icon circular on one device and square on another device, it’s totally up to you.

Autosizing TextViews

Android O allows you to let the size of the text expand and contract automatically based on the boundaries of the TextView.

You can set up the TextView auto sizing via code or XML. The two types can be setup like:

  1. Granularity- By using this, you can set up the minimum and maximum range of the text size.
  2. Preset Size- By using this, you can auto size the TextView from the list of predefined sizes.

Generic findViewById

Say goodbye to casting views after findViewById().

Snoozing of Notifications

You can now snooze the notifications and can see later. Developers can also get all the snoozed notifications using- getSnoozedNotifications().

setToolTipText

Set the text on the tooltip that will be displayed in a small popup window. The tooltip will be displayed:

  1. On Long Click, unless is not handled otherwise.
  2. On hover, after a brief delay since the pointer has stopped moving

Android O may release on August 21 | Lifestyle News – India TV

Progress Dialog is no longer there, it’s deprecated now

Progress Dialog is now deprecated in Android O. It uses a progress indicator such as ProgressBar inline inside of an activity rather than using this modal dialog.

A dialog shows a progress indicator and an optional text message or view. Only a text message or a view can be used at the same time. The progress range is 0 to max and cancelable on the back press.

Notification.Builder() is now deprecated

Now we have to use Notification.Builder (context, channelId). ChannelId is a string value and mandatory for all posted notifications.

It’s time to remove BroadCast Receiver from the Manifest

In Android O, they have set the limit on the background executions. You should remove all implicit broadcast that is for intents. If you keep them in place then it will not crash your app but will be of no use when your app will run on Android O.

Autofill Framework

Autofill will save user’s time to fill the information in forms, like details such as credit card or personal account in their devices. The Autofill Framework manages the communication between the app and autofill service.

Developers can start using Android O by setting up the compileSdkVersion as ‘android-O’, targetSdkVersion as ‘O’ and buildToolsVersion as ‘26.0.0-rc1’.
You must set the support dependency as-

dependencies {
compile ‘com.android.support:appcompat-v7:26.0.0-alpha1’
}

Designing a kick-ass checkout experience

They confessed that they dreaded checkout as if some unknown calamity would fall upon them and they’d be forced to leave their cart. Sometimes they indeed had to abandon their cart because they didn’t get upfront information about shipping or tax charges. Other times, the steps were too hard to follow and they had a hard time placing the order.You think I am making this up? Below is an image which shows the results of a survey done with people in the US who gave reasons for abandoning their e-commerce cart-Among all the reasons, Extra costs (60%) and Create an account (37%) are the two topmost areas where users feel dejected.

Think of it this way- you go to a brick-and-mortar store, you put everything you need in your cart and stand in the long queue to wait for your turn. But just when you reach there, the person at the counter says that you need to pay 13% convenience tax as a first time customer. And, in case you want to waive it off, you need to register at the store. Isn’t that abominable?

Moving ahead, the third most cited reason for abandonment is- “too long/complicated process”. This is the area where, I feel, that designers can greatly help improve the user experience.

How?

By designing with the utmost care and keeping your end users in mind. You need to understand how people accomplish tasks and the role human psychology plays when people are browsing on the internet. It will help you design better interfaces.

For the checkout page, I have figured out five ways that can help you design a better experience.

How to design a user-centered online checkout experience | by Tanya Nativ | Prototypr

Design a checkout flow that customers can see

You know how trekkers gather the strength to climb to the top? They look at the summit and it gives them the adrenaline rush to conquer the mountain. A bit overboard of an example because the checkout process is nothing like mountain hiking. But you get the drift, don’t you?

In short- If you can see it, you can achieve it!

For example- once a user has added all the items in the bag and wants to go ahead and purchase, display the entire checkout flow up front. Show it with a progress bar so that the user knows what information s(he) has to fill at each stage. This also breaks down the process into chunks and the user is not burdened with everything on one page.

The above example of the checkout page of Myntra shows that there are three steps- BAG, ADDRESS, and PAYMENT. Each stage is highlighted so that as the users proceed in the flow, they know which stage they’ve reached and can review their order.

Display the right visual hierarchy

Visual hierarchy helps the users in two ways- it gives them the clarity on the items they are buying and it gives them control over their actions. When done right, visual hierarchy helps users understand what needs their attention.

For example- if they need to review their order or if they need to proceed to the payment page.

Visual hierarchy can also be used to attract the user’s attention to some promotional offer (eg- free shipping on orders over $X) or to motivate them to check out an interesting offer which can be clubbed with their existing one.

For example- in the screenshot below, the “bank offer” is highlighted so that users who are eligible (and interested) can look at it and decide whether they want to use it or not.

Keep the form fields minimal and clear

Designing forms that result in better conversations is an art. The number one principle that you need to keep in mind while designing forms is- don’t ask for unnecessary information.

For example, in the screen below, the payment form is precise and it helps users fill out the card details in the same sequence as they appear on the card. All payment options are listed in the left navigation menu and in case the user is unable to remember the card details, (s)he can use the other options.

The labels are correctly placed and they help the user enter the right information in the right input field. Apart from that, the security marks on the right-hand side (‘verified by VISA”) leave a positive impact on the user and they are assured of their money going in the right hands.

However, there is one more aspect which can be taken care of in this particular interaction. When I enter the card number (I entered an incorrect one), it didn’t show me any error.

Instead, it allowed me to move ahead in the journey. It was only after clicking on “make payment” that it showed me the error message on the top of the form. That too, incorrect. The error message is misleading and I can’t spot a “red” field anywhere.

A better approach is to handle errors on the go. It’s possible to validate the card number as soon as users enter it. So, why not make them aware of their mistake right when they make it?

How to Design an E-commerce Checkout Flow - 23 Tactics to Boost Sales

Make customer sign up optional

It happens to most of us. We look at something and we instantly want to buy it. But then we change our mind the moment the merchant portal asks us to sign up. Even in the survey conducted by Baymard Institute, “the site wanted me to create an account” is the reason given by 37% of people for cart abandonment. As customers, it’s natural to feel uncomfortable sharing our personal information (name, address, phone number) during the first interaction with a new store. Moreover, it’s tedious to create a new account on every site we browse.

A better option to fix this problem is to offer them guest checkout. By giving them the freedom to choose their way, you enhance their user experience. If they are already flattered by your service, they’ll make an account. If they are yet to discover that you’re awesome, you’ve given them a reason to love your page by giving them the “guest checkout” option.

Here’s an example from Nike’s website. When you “proceed to checkout”, it asks for your shipping details directly (no login required). However, it also gives you an option to sign-up in case you want faster sign up in the future.

Offer them all good things, including your help

Not all users sail smooth. Some hit a dead end, some get confused and some become frustrated. Even after taking care of everything (forms inputs, error messages, etc), it’s fair to assume that some users will still face problems.

In such situations, it’s crucial to provide users with assistance instead of sending them to help pages (that are not always helpful) or FAQ-pages that are hardly specific to their problems.

Nike’s website takes care of this aspect of user experience.

Knowing that someone is there to help you out brings more credibility and confidence in users and they can peacefully shop to their heart’s delight. It may not be a grand feature in the bigger scheme of things, but it’s the small things that matter the most.

The design of the checkout page is crucial in the consumer journey. If the design is good, it can help convert a customer into a returning user. However, if the design is bad, it not only causes loss of business but also gives people a chance to badmouth your website’s experience.

Therefore, it’s important to design a well-thought-out checkout page. There are many other methods that can guide you to create easy and creative checkout pages which delight users and make their shopping experience fun. But I believe that if the ways listed above are followed it can drastically increase the conversion rate through the checkout process.

ReactJS gains power with Flux

I recently started learning ReactJS. With a very good documentation available on GitHub I found it very easy to learn. I created a sample application in ReactJS & it was working fine!!With some experience in the same I would like to begin by mentioning two of its salient points :

  1. HTML and Javascript in a single file which makes it easy to maintain
  2. Component Driven Development in which DOM is divided into components to make it reusable and easily testable

Then I heard about React with Flux and I was intrigued to know why do we need Flux when React is fine on its own. I did not have much development experience in ReactJS which is why I didn’t realize the power of Flux. Eager to learn, I told myself let’s pull our socks a little, learn Flux and also help train others.

I created an application using ReactJS but initially didn’t use Flux in order to understand its additional benefits like:

  1. Maintainability
  2. Readability
  3. Unidirectional data flow

To see the same in practice, Let’s take a look at developing an application first without using Flux and then using Flux.

 

Let’s start by understanding basic definition/architecture of Flux –

Flux Architecture

There are four key points to Flux

  1. Action  – Actions are very simple because they only need to take request from View and pass it to the Dispatcher. It acts as mediator between View and Dispatcher.
  2. Dispatcher  – Dispatcher is responsible to pass information to Store. It does that via <this.dispatch> method in dispatcher.
  3. Store – Stores plays with data. It communicates with backend server as per request from View.
  4. View – Views are for displaying information. If views need some information then they get it from Store and if it needs to perform some action or update/add any information then it informs Action.Action calls Dispatcher which in turn fetches data from Store.

React and Flux

Let’s say we have to create a TODO application. It would be a single page application divided into following components

  • Header
    • Todo Count
  • Todo Form
  • Todo List
    • Todo Item

Expected behaviour

  • Todo Count will display the total count of Todo Items.
  • Todo Form will have input field.
  • On submitting the form, new Todo Item should be appended to Todo List and count should be increased in Todo Count.

Application without using Flux

Let’s create a TodoItem Class which will render individual todo item. It will receive information of todo item from its parent component

The below component is TodoList which is responsible for rendering all todo items. This component gets “data” from its parent class via props. “this.props.data” is a list of items which iterates and call TodoItem which we created above.

TodoCount component is responsible to display the count of items. It will get count from TodoHeader component.

TodoHeader component displays the header of an application and it calls the TodoCount component to display the count of total items.

Below is the TodoForm component. Let’s focus on the same because it creates the data in addition to rendering.

The handleSubmit method is called when Submit button is clicked and it calls TodoSubmit method which it got from the Application component.

When I was doing this I had questions –

  •      Why are we doing it this way?
  •      Why Application component submits the form and not TodoForm?

The reason is that Application Component is the parent/grandparent of all components. And data flows from parent to child and child can’t change the state of Parent. Also, there can’t be any communication flow between siblings.

Now if TodoForm will submit the form then how will this information be passed to TodoList or TodoHeader component?

That’s why we made Application component to be responsible for submitting the form.

The Application component is parent of all. It has methods on which we need some discussion.

loadDataFromServer – It will load data from server but in our example there isn’t any server so we have hard coded the data.

handleTodoSubmit – This method would be called by the TodoForm as explained in TodoForm component.

When this method would be called then it will change the state with new created Todo item which will trigger re-rendering of Application component and all child components will be updated with the new information.

As you can see that if sibling components want to communicate with each other then they need to pass data to their parent component.

Like in our example Todo Form wants to tell Todo List that new item has been added.

That’s why Application component is passing callback handleTodoSubmit. So on submit of Todo Form it is calling handleTodoSubmit method of Application component via callback. And handleTodoSubmit is updating the state of Application which causes the re-rendering of Application component by updating Todo Item and Todo Header.

In our example there is only 1 hierarchy but in real time scenarios there could be multi level hierarchy where the innermost child would want to update the other level of innermost child. Then you have to pass the callback method over all the hierarchies.

But that would make it less maintainable and it also impacts readability in negative ways which will result in losing the power of React.

Now Let’s try this same application using Flux

As we have seen there are 4 layers in Flux. Let’s write a code according to its structure.

Action

Actions are called by Views. If View wants to update data in Store then View tells about this changeto Action. Here we have created AppAction. In this, there is only 1 action i.e addItem.

This would be called when we want to add a new todo Item. This action further calls handleViewAction of dispatcher(AppDispatcher)

Dispatcher

In AppDispatcher, handleViewAction is defined which is called by AppAction. In handleViewAction action is passed which will tell what action is performed.

There is a this.dispatch inside handleViewAction which is a pre-defined method of Dispatcher. This method will internally call the Store.

Store

Let’s discuss methods of Store one by one.

dispatcherIndex – Execution starts from here because of the AppDispatcher.register. Whenever dispatch method of Dispatcher is called then it would pass the action information wherever AppDispatcher.register is defined.

In our example we have only one action “ADD_ITEM” but in most of the cases there would be multiple actions. So we have to first define the type of action and based on that we will perform actions and will call emit method.

Here, we are calling addTodoItem method from dispatcherIndex method and after that emitChange

addTodoItem – In this method we are not doing anything except pushing new todo item to the todoItems array.

emitChange – In emitChange, we are using this.emit(CHANGE_EVENT) method, this will let listeners of CHANGE_EVENT know that something is changed.

addListener – This method is used by Views to listen to the CHANGE_EVENT.

removeListener – This method is used by Views to remove listener.

getTodoItems – This method will return all the todos. This would be called by TodoList component.

getTodoCount – This method will return the count of all todos. This would be called by TodoCount component.

In TodoList component, we are fetching todo items from Store directly by calling AppStore.getTodoItems in getInitialState.

Now question is how will this component get to know when new todo item has been added?

The answer is in componentWillMount. In this method we are calling AppStore.addChangeListener which will listen to the event whichis defined in addChangeListener of Store. If there would be any change then it will call the _onChange which will reset the state.

Similar to TodoList, TodoCount will also get data from Store and there is a listener defined in componentWillMount.

Conclusion

On comparing both the codes you will find that creating application without using Flux is still easy ? But if you understand the flow of Flux then your choice would always be Flux because flow of Flux would be the same even when your application is getting complex. It provides us with additional benefits of maintainability, readability, unidirectional data flow.

To summerize, lets try again to understand the flow.

In TODO component, we are rendering 3 components <TodoHeader>, <TodoForm>, <TodoList>. There is no need to pass any callback, no need to define any state because <TODO> component is not doing anything except calling other components.

TodoHeader component is also not doing anything except rendering or calling other component.

In TodoCount component, we need to display the count of total items. We will get count from AppStore on rendering of TodoCount. But count may get update after rendering of TodoCount component. That’s why we have added listener in componentWillMount and removed in componentWillUnmount method. So if there would be any update in Store related to count than it would call _onChange method and will change the state of count accordingly.

TodoList component is displaying the list of Todo Items and for that it needs TodoItems. The behaviour is similar to TodoCount in terms of communicating with AppStore.

In TodoForm, we want to submit the form and want to tell other components that new item has been added. So on submit, instead of telling other components it is just passing information to AppAction which will dispatch it to store with the help of AppDispatcher. And AppStore will update/add the data.

In AppStore, there is emit method called in emitChange which will allow listeners to know that information has been updated/added.

As you can see, components are not dependent on each other. If they need any information they will get it from Store and if they want to update anything then they will create an Action and it would be Dispatched to Store.

Clearly, the data flow is unidirectional so it would be easy to understand and maintain.

error: Content is protected !!