Skip to content

Commit eb47566

Browse files
committed
added php unit testing
1 parent 03a1d9c commit eb47566

File tree

6 files changed

+266
-1
lines changed

6 files changed

+266
-1
lines changed

bootstrap/autoload.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
define('LARAVEL_START', microtime(true));
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Register The Composer Auto Loader
8+
|--------------------------------------------------------------------------
9+
|
10+
| Composer provides a convenient, automatically generated class loader
11+
| for our application. We just need to utilize it! We'll require it
12+
| into the script here so that we do not have to worry about the
13+
| loading of any our classes "manually". Feels great to relax.
14+
|
15+
*/
16+
17+
require __DIR__.'/../vendor/autoload.php';
18+
19+
/*
20+
|--------------------------------------------------------------------------
21+
| Include The Compiled Class File
22+
|--------------------------------------------------------------------------
23+
|
24+
| To dramatically increase your application's performance, you may use a
25+
| compiled class file which contains all of the classes commonly used
26+
| by a request. The Artisan "optimize" is used to create this file.
27+
|
28+
*/
29+
30+
if (file_exists($compiled = __DIR__.'/compiled.php'))
31+
{
32+
require $compiled;
33+
}
34+
35+
/*
36+
|--------------------------------------------------------------------------
37+
| Setup Patchwork UTF-8 Handling
38+
|--------------------------------------------------------------------------
39+
|
40+
| The Patchwork library provides solid handling of UTF-8 strings as well
41+
| as provides replacements for all mb_* and iconv type functions that
42+
| are not available by default in PHP. We'll setup this stuff here.
43+
|
44+
*/
45+
46+
Patchwork\Utf8\Bootup::initMbstring();
47+
48+
/*
49+
|--------------------------------------------------------------------------
50+
| Register The Laravel Auto Loader
51+
|--------------------------------------------------------------------------
52+
|
53+
| We register an auto-loader "behind" the Composer loader that can load
54+
| model classes on the fly, even if the autoload files have not been
55+
| regenerated for the application. We'll add it to the stack here.
56+
|
57+
*/
58+
59+
Illuminate\Support\ClassLoader::register();
60+
61+
/*
62+
|--------------------------------------------------------------------------
63+
| Register The Workbench Loaders
64+
|--------------------------------------------------------------------------
65+
|
66+
| The Laravel workbench provides a convenient place to develop packages
67+
| when working locally. However we will need to load in the Composer
68+
| auto-load files for the packages so that these can be used here.
69+
|
70+
*/
71+
72+
if (is_dir($workbench = __DIR__.'/../../workbench'))
73+
{
74+
Illuminate\Workbench\Starter::start($workbench);
75+
}

bootstrap/paths.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
return array(
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Application Path
8+
|--------------------------------------------------------------------------
9+
|
10+
| Here we just defined the path to the application directory. Most likely
11+
| you will never need to change this value as the default setup should
12+
| work perfectly fine for the vast majority of all our applications.
13+
|
14+
*/
15+
16+
'app' => __DIR__.'/../vendor/laravel/laravel/app',
17+
18+
/*
19+
|--------------------------------------------------------------------------
20+
| Public Path
21+
|--------------------------------------------------------------------------
22+
|
23+
| The public path contains the assets for your web application, such as
24+
| your JavaScript and CSS files, and also contains the primary entry
25+
| point for web requests into these applications from the outside.
26+
|
27+
*/
28+
29+
'public' => __DIR__.'/../vendor/laravel/laravel/public',
30+
31+
/*
32+
|--------------------------------------------------------------------------
33+
| Base Path
34+
|--------------------------------------------------------------------------
35+
|
36+
| The base path is the root of the Laravel installation. Most likely you
37+
| will not need to change this value. But, if for some wild reason it
38+
| is necessary you will do so here, just proceed with some caution.
39+
|
40+
*/
41+
42+
'base' => __DIR__.'/..',
43+
44+
/*
45+
|--------------------------------------------------------------------------
46+
| Storage Path
47+
|--------------------------------------------------------------------------
48+
|
49+
| The storage path is used by Laravel to store cached Blade views, logs
50+
| and other pieces of information. You may modify the path here when
51+
| you want to change the location of this directory for your apps.
52+
|
53+
*/
54+
55+
'storage' => __DIR__.'/../vendor/laravel/laravel/app/storage',
56+
57+
);

bootstrap/start.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
/*
4+
|--------------------------------------------------------------------------
5+
| Create The Application
6+
|--------------------------------------------------------------------------
7+
|
8+
| The first thing we will do is create a new Laravel application instance
9+
| which serves as the "glue" for all the components of Laravel, and is
10+
| the IoC container for the system binding all of the various parts.
11+
|
12+
*/
13+
14+
$app = new Illuminate\Foundation\Application;
15+
16+
/*
17+
|--------------------------------------------------------------------------
18+
| Detect The Application Environment
19+
|--------------------------------------------------------------------------
20+
|
21+
| Laravel takes a dead simple approach to your application environments
22+
| so you can just specify a machine name for the host that matches a
23+
| given environment, then we will automatically detect it for you.
24+
|
25+
*/
26+
27+
$env = $app->detectEnvironment(array(
28+
29+
'local' => array('your-machine-name'),
30+
31+
));
32+
33+
/*
34+
|--------------------------------------------------------------------------
35+
| Bind Paths
36+
|--------------------------------------------------------------------------
37+
|
38+
| Here we are binding the paths configured in paths.php to the app. You
39+
| should not be changing these here. If you need to change these you
40+
| may do so within the paths.php file and they will be bound here.
41+
|
42+
*/
43+
44+
$app->bindInstallPaths(require __DIR__.'/paths.php');
45+
46+
/*
47+
|--------------------------------------------------------------------------
48+
| Load The Application
49+
|--------------------------------------------------------------------------
50+
|
51+
| Here we will load this Illuminate application. We will keep this in a
52+
| separate location so we can isolate the creation of an application
53+
| from the actual running of the application with a given request.
54+
|
55+
*/
56+
57+
$framework = $app['path.base'].'/vendor/laravel/framework/src';
58+
59+
require $framework.'/Illuminate/Foundation/start.php';
60+
61+
/*
62+
|--------------------------------------------------------------------------
63+
| Return The Application
64+
|--------------------------------------------------------------------------
65+
|
66+
| This script returns the application instance. The instance is given to
67+
| the calling script so we can separate the building of the instances
68+
| from the actual running of the application and sending responses.
69+
|
70+
*/
71+
72+
return $app;

composer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@
1212
"require": {
1313
"php": ">=5.3.0",
1414
"illuminate/support": ">=4.0.0",
15+
"illuminate/database": ">=4.0.0",
1516
"illuminate/view": ">=4.0.0",
1617
"illuminate/filesystem": ">=4.0.0"
1718
},
19+
"require-dev": {
20+
"laravel/laravel": ">=4.0.0",
21+
"mockery/mockery": "0.7.2",
22+
"phpunit/phpunit": "3.7.*"
23+
},
1824
"autoload": {
1925
"classmap": [
2026
"src/migrations"

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit backupGlobals="false"
33
backupStaticAttributes="false"
4-
bootstrap="vendor/autoload.php"
4+
bootstrap="bootstrap/autoload.php"
55
colors="true"
66
convertErrorsToExceptions="true"
77
convertNoticesToExceptions="true"

tests/Datatables.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
use Mockery as m;
4+
use Bllim\Datatables\Datatables as Datatables;
5+
6+
/**
7+
* Demo Table
8+
*/
9+
class Demo extends Illuminate\Database\Eloquent\Model {}
10+
11+
class DatatablesTest extends Illuminate\Foundation\Testing\TestCase {
12+
13+
public function createApplication()
14+
{
15+
$unitTesting = true;
16+
17+
$testEnvironment = 'testing';
18+
19+
return require __DIR__.'/../bootstrap/start.php';
20+
}
21+
22+
public function setUp()
23+
{
24+
parent::setUp();
25+
26+
Config::set('database.default', 'sqlite');
27+
Config::set('database.sqlite.database', ':memory:');
28+
29+
Schema::dropIfExists('demos');
30+
Schema::create('demos', function($table){
31+
$table->increments('id');
32+
$table->string('name');
33+
});
34+
Demo::insert(array('name'=>'demo datatables'));
35+
}
36+
37+
public function tearDown()
38+
{
39+
Schema::dropIfExists('demos');
40+
}
41+
42+
public function test_demo_count()
43+
{
44+
$this->assertEquals(1, Demo::count());
45+
}
46+
47+
public function test_datatables_make_function()
48+
{
49+
$demo = DB::table('demos')->select('id','name');
50+
$output = Datatables::of($demo)->make();
51+
$this->assertTrue( $output instanceof Illuminate\Http\JsonResponse ? true : false );
52+
}
53+
54+
55+
}

0 commit comments

Comments
 (0)