PHPUnit and Slim Frameworks

  1. Download PhpUnit with Composer
    • Update the composer.json file
    • "require-dev": {
              "phpunit/phpunit": "5.4.*"
    • Run php composer.phar update


2. Create file indexTest.php for testing file

require_once 'vendor/autoload.php';
require_once 'AutoLoader.php';
$appConfig = include('configTest.php');


3.  Create folder ‘test’ in root app dir, and create file for test, eg: EmailTest.php

use PHPUnit\Framework\TestCase;
use \models\User\EmailModel as Email; //Any namespace on your setup

 * @backupGlobals disabled
final class EmailTest extends TestCase
    public function testCanBeCreatedFromValidEmailAddress()


    public function testCannotBeCreatedFromInvalidEmailAddress()


    public function testCanBeUsedAsString()

Use annotation @backupGlobals to prevent Closure errors.


4. Then create file \models\User\EmailModel.php :

namespace models\User;

class EmailModel extends UserModel
private $email;

public function __construct($email)

$this->email = $email;

public static function fromString($email)
return new self($email);

public function __toString()
return $this->email;

private function ensureIsValidEmail($email)
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
throw new \InvalidArgumentException(
'"%s" is not a valid email address',


5. In terminal, run the below command:

./vendor/bin/phpunit --bootstrap indexTest.php test/EmailTest


PHPUnit 5.4.8 by Sebastian Bergmann and contributors.

... 3 / 3 (100%)

Time: 28 ms, Memory: 3.25MB

OK (3 tests, 3 assertions)

The sample of EmailTest.php and EmailModel.php is taken from PhpUnit site.

Ok Bye.


Apache2.4 Using Alias with mod_rewrite return error 404 not found

When i configure Alias in apache,
Alias /testing/ “/var/www/test_folder/”

Then in my ‘test_folder’, i’ve .htaccess file,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

Then when i run,
it will return error 404 Not found

The solution below at least is working with my environment:

Alias /testing/ “/var/www/testing/”

<Directory “/var/www/testing/”>

RewriteEngine On
RewriteBase /testing

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
AllowOverride None


So the trick here is by adding the,
RewriteBase /testing
AllowOverride None – set None to NOT use the htaccess file

That’s all, ok Bye 😉

Debug PHP Application with XDebug & KCacheGrind on Ubuntu 12.04

Install Xdebug, KCacheGrind on Ubuntu 12.04

Install PHP-Xdebug

sudo apt-get install php5-xdebug

Open php.ini, configure some line:
xdebug.profiler_enable = 1
xdebug.profiler_output_dir = /tmp


Restart your apache

Check your phpinfo, and should contain xdebug information.


Install KCacheGrind

sudo apt-get install kcachegrind


Append XDEBUG_PROFILE=1  ( in the GET/POST request to your script )
Example, run your app at browser:



Then open KCacheGrind, and open your file in /tmp folder:
Example: cachegrind.out.11445


Analysis of mobile development approaches


Which mobile development approach fits your needs? If you don’t know, read this overview about the possibilities. Also find out which approach Justin James thinks is mobile developers’ best bet for long-term success.

Mobile Web applications

Mobile Web applications are at the opposite end of the spectrum. With mobile Web applications, you can use your existing Web development knowledge, and learn the techniques to make it work well on mobile devices. Even better, you can reuse your existing Web applications if you have them already, and you can reach 100% of the smartphone market with a single codebase.

Cross-platform development tools

There are a number of cross-platform development tools designed to help you bridge the gap (Appcelerator is one example); these tools let you develop for their model, and then they create native applications for you. This can be a great approach, although you may need to learn an entirely new set of skills to work with the tool, depending on which one you pick. These tools can also do a great job at making your app look and feel right on each platform it supports, and they will provide access to the lowest-common-denominator of native functionality.

More details at: