Blog: Unit Testing

  • Unit Testing Laravel's Core in Windows

    Mar 8, 2012

    Testing Laravel's core is a critical part of making and submitting changes to the codebase. Without testing it's incredibly difficult to know if your changes break something. It's possible that your seemingly perfect modification could cause an error in something obscure that few people would ever use. It's important to test for an increased level of confidence.

    A few preparations must be made when unit testing Laravel's core in Windows. In the video I walk through updating PEAR, PHPUnit, enabling the fileinfo PHP extension, and pulling down the framework / core tests.

    1. Clone Laravel and the tests bundle.

    Clone the Laravel framework.

    git clone https://github.com/laravel/laravel.git
    

    Clone the laravel-tests bundle into the bundles folder.

    cd laravel/bundles
    
    git clone https://github.com/laravel/tests.git laravel-tests
    

    2. Upgrade PEAR.

    Change directories to your PHP installation folder.

    cd xampp177/php
    

    Upgrade PEAR.

    pear upgrade pear
    

    Upgrade PHPUnit.

    pear upgrade phpunit/PHPUnit
    

    3. Enable the fileinfo extension in php.ini.

    Laravel's File class uses the fileinfo extension. This is generally not enabled by default in Windows packages.

    In your php.ini file find the following line.

    ;extension=php_fileinfo.dll
    

    Uncomment the extension by removing the semi-colon.

    extension=php_fileinfo.dll
    

    Then restart your apache.

    4. Run the tests against Laravel's core.

    Change directories into the folder that you cloned Laravel into.

    cd laravel
    

    Then, run the tests against the core.

    php artisan test:core