Add some test, need more test :) just for start

address #22
This commit is contained in:
fzerorubigd 2013-11-07 21:47:57 +03:30
parent b8119d4acd
commit 7e398d41d9
No known key found for this signature in database
GPG Key ID: D6EE858AF9D2999A
7 changed files with 171 additions and 3 deletions

4
.gitignore vendored
View File

@ -1,3 +1,7 @@
vendor vendor
*.swp *.swp
*.swo *.swo
composer.phar
composer.lock
*.iml
.idea

View File

@ -3,6 +3,8 @@
"description": "Handlebars processor for php", "description": "Handlebars processor for php",
"homepage": "https://github.com/XaminProject/handlebars.php", "homepage": "https://github.com/XaminProject/handlebars.php",
"type": "library", "type": "library",
"minimum-stability": "dev",
"prefer-stable": true,
"license": "MIT", "license": "MIT",
"authors": [ "authors": [
{ {
@ -14,8 +16,15 @@
"email": "everplays@gmail.com" "email": "everplays@gmail.com"
} }
], ],
"require": {}, "require": {
},
"require-dev": {
"phpunit/phpunit": "3.8.*"
},
"autoload": { "autoload": {
"psr-0": { "Handlebars": "src/" } "psr-0": {
"Handlebars": "src/"
}
} }
} }

15
phpunit.xml.dist Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="tests/bootstrap.php" colors="true">
<testsuites>
<testsuite name="Handlebars.php Test suite">
<directory>tests/Xamin/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</phpunit>

View File

@ -0,0 +1,116 @@
<?php
/**
* Class AutoloaderTest
*/
class HandlebarsTest extends \PHPUnit_Framework_TestCase
{
/**
* Test handlebars autoloader
*
* @return void
*/
public function testAutoLoad()
{
Handlebars\Autoloader::register(realpath(__DIR__ . '/../fixture/'));
$this->assertTrue(class_exists('Handlebars\\Test'));
$this->assertTrue(class_exists('Handlebars\\Example\\Test'));
}
/**
* Test basic tags
*
* @param string $src handlebars source
* @param array $data data
* @param string $result expected data
*
* @dataProvider simpleTagdataProvider
*
* @return void
*/
public function testBasicTags($src, $data, $result)
{
$loader = new \Handlebars\Loader\StringLoader();
$engine = new \Handlebars\Handlebars(array('loader' => $loader));
$this->assertEquals($result, $engine->render($src, $data));
}
/**
* Simple tag provider
*
* @return array
*/
public function simpleTagdataProvider()
{
return array(
array(
'{{! This is comment}}',
array(),
''
),
array(
'{{data}}',
array('data' => 'result'),
'result'
),
array(
'{{data.key}}',
array('data' => array('key' => 'result')),
'result'
),
);
}
/**
* Test helpers (internal helpers)
*
* @param string $src handlebars source
* @param array $data data
* @param string $result expected data
*
* @dataProvider internalHelpersdataProvider
*
* @return void
*/
public function testSimpleHelpers($src, $data, $result)
{
$loader = new \Handlebars\Loader\StringLoader();
$helpers = new \Handlebars\Helpers();
$engine = new \Handlebars\Handlebars(array('loader' => $loader, 'helpers' => $helpers));
$this->assertEquals($result, $engine->render($src, $data));
}
/**
* Simple helpers provider
*
* @return array
*/
public function internalHelpersdataProvider()
{
return array(
array(
'{{#if data}}Yes{{/if}}',
array('data' => true),
'Yes'
),
array(
'{{#if data}}Yes{{/if}}',
array('data' => false),
''
),
array(
'{{#with data}}{{key}}{{/with}}',
array('data' => array('key' => 'result')),
'result'
),
array(
'{{#each data}}{{this}}{{/each}}',
array('data' => array(1,2,3,4)),
'1234'
),
);
}
}

3
tests/bootstrap.php Normal file
View File

@ -0,0 +1,3 @@
<?php
$loader = include __DIR__ . "/../vendor/autoload.php";

View File

@ -0,0 +1,10 @@
<?php
namespace Handlebars\Example;
/**
* Class Handlebars_Example_Class
*/
class Test
{
}

View File

@ -0,0 +1,11 @@
<?php
namespace Handlebars;
/**
* Class Handlebars_Class
*/
class Test
{
}