GithubHelp home page GithubHelp logo

yidas / codeigniter-phpunit Goto Github PK

View Code? Open in Web Editor NEW
16.0 1.0 9.0 10 KB

CodeIgniter 3 PHPUnit Test extension library

License: MIT License

PHP 100.00%
codeigniter phpunit unit-test test-driven-development

codeigniter-phpunit's Introduction

CodeIgniter PHPUnit Test


CodeIgniter 3 PHPUnit Test extension library

Latest Stable Version License

This RESTful API extension is collected into yidas/codeigniter-pack which is a complete solution for Codeigniter framework.

FEATURES

  • PHPUnit Test in Codeigniter 3 Framework

  • Easy to install into your Codeigniter project by Composer


OUTLINE

REQUIREMENTS

This library requires the following:

  • PHP 5.3.0+
  • CodeIgniter 3.0.0+

INSTALLATION

Run Composer in your Codeigniter project under the folder \application:

composer require yidas/codeigniter-phpunit

DIRECTORY STRUCTURE

codeigniter/
└── application/
    ├── tests/          Test cases
    ├── vendor/         Vendor included yidas/codeigniter-phpunit
    └── phpunit.xml     PHPUnit XML

CONFIGURATION

According to Directory Structure, create and configure phpunit.xml under application directory:

<?xml version="1.0" encoding="UTF-8" ?>
<phpunit bootstrap="vendor/yidas/codeigniter-phpunit/bootstrap.php">
  <testsuites>
    <testsuite name="TestSuite">
      <directory>tests</directory>
    </testsuite>
  </testsuites>
</phpunit>

For this phpunit.xml template, the test cases directory is application/test, make sure you would create every test cases under it.


USAGE

In the application directory of this library, run phpunit from vendor:

$ ./vendor/bin/phpunit

Or using absolute path commands like:

$ /var/www/html/codeigniter3/application/vendor/bin/phpunit -c /var/www/html/codeigniter3/application/phpunit.xml
$ phpunit -c /var/www/html/codeigniter3/application/phpunit.xml

Then the result would like:

PHPUnit 5.7.27 by Sebastian Bergmann and contributors.



Time: 40 ms, Memory: 2.75MB

No tests executed!

TEST CASE

With this extension libaray, you could write test cases with loading Codeigniter framework.

For example, write a test case application/tests/CodeigniterTest.php for testing Codeigniter config component:

<?php

use PHPUnit\Framework\TestCase;

final class CodeigniterTest extends TestCase
{
    function __construct() 
    {
        parent::__construct();
        // Load CI application
        $this->CI = & get_instance();
    }
    
    public function testConfigItem()
    {
        $indexPage = $this->CI->config->item('index_page');
        
        $this->assertSame('index.php', $indexPage);
    }
}

Then you would get the result OK (1 test, 1 assertion) by running PHPUnit test.

codeigniter-phpunit's People

Contributors

yidas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.