-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from YunYinORG/tests-pr 单元测试
添加单元测试,提交代码自动进行单元测试 完成 testConfig
- Loading branch information
Showing
11 changed files
with
269 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# http://about.travis-ci.org/docs/user/languages/php/ | ||
dist: trusty | ||
language: php | ||
|
||
# list any PHP version | ||
php: | ||
# using major version aliases | ||
# aliased to a recent 7.x version | ||
- 7.0 | ||
# aliased to a recent 5.6.x version | ||
- 5.6 | ||
# aliased to a recent 5.5.x version | ||
- 5.5 | ||
# aliased to a recent 5.4.x version | ||
- 5.4 | ||
# aliased to 5.3.29 | ||
- 5.3 | ||
|
||
|
||
# https://docs.travis-ci.com/user/environment-variables/ | ||
# optionally specify a list of environments | ||
env: | ||
- environ=dev | ||
- environ=product | ||
|
||
# optionally set up exclutions and allowed failures in the matrix | ||
# matrix: | ||
# # allow_failures: | ||
# # - php: 5.3 | ||
|
||
|
||
install: | ||
#init tests environment | ||
- ./tests/install-yaf.sh | ||
|
||
|
||
# execute any number of scripts before the test run, custom env's are available as variables | ||
before_script: | ||
#init YYF | ||
- echo 0 | ./init.cmd | ||
|
||
# omitting "script:" will default to phpunit | ||
# use the env variable to determine the phpunit.xml to use | ||
script: phpunit --coverage-text --configuration tests/phpunit.xml | ||
|
||
# configure notifications (email, IRC, campfire etc) | ||
notifications: | ||
email: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
namespace tests; | ||
|
||
class EnvTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testExt() | ||
{ | ||
$this->assertTrue(extension_loaded('yaf'),'yaf extension not loaded'); | ||
} | ||
|
||
/*conf is exist?*/ | ||
public function testConfFile() | ||
{ | ||
$conf=APP_PATH . '/conf/app.ini'; | ||
$this->assertFileExists($conf,$conf.' can not find'); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
extension=yaf.so | ||
[yaf] | ||
yaf.environ=dev | ||
yaf.use_spl_autoload = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
extension=yaf.so | ||
|
||
[yaf] | ||
yaf.environ=product | ||
yaf.cache_config=1 | ||
yaf.use_spl_autoload=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
define('APP_PATH', dirname(dirname(__FILE__))); | ||
define('TRACER_OFF', true); | ||
|
||
$app=new Yaf_Application(APP_PATH . '/conf/app.ini'); | ||
$app->bootstrap(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env bash | ||
|
||
TESTS_PATH=`dirname $(readlink -f $0)` | ||
if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." ]]; then | ||
YAF_VERSION=yaf-2.3.5 | ||
else | ||
YAF_VERSION=yaf-3.0.3 | ||
fi | ||
|
||
curl https://pecl.php.net/get/${YAF_VERSION}.tgz | tar zx -C ./ | ||
cd ${YAF_VERSION}; phpize; | ||
|
||
./configure && make && make install | ||
|
||
phpenv config-add $TESTS_PATH/ini/yaf.$environ.ini |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
namespace tests\library; | ||
|
||
use \Config as Config; | ||
use \Yaf_Application as Application; | ||
|
||
class ConfigTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
||
/*测试配置和配置文件是否一致*/ | ||
public function testConfigConsistency() | ||
{ | ||
$env=Application::app()->environ(); | ||
$config=parse_ini_file(APP_PATH.'/conf/app.ini', true); | ||
$current=$config[$env.':common']+$config['common']; | ||
|
||
foreach ($current as $key => $value) { | ||
$this->assertSame($current[$key], Config::get($key), $key); | ||
} | ||
} | ||
|
||
/*检测空值*/ | ||
public function testEmpty() | ||
{ | ||
$this->assertSame(Config::get(uniqid('_te_', true)), null); | ||
} | ||
|
||
/*测试默认值*/ | ||
public function testDefault() | ||
{ | ||
$key=uniqid('_td_', true); | ||
$default=array(false,null,1,true,array(1,2,4),'test'); | ||
foreach ($default as $k=>$d) { | ||
$this->assertSame(Config::get($k.$key, $d), $d); | ||
} | ||
} | ||
|
||
/*测试secret路径是否存在*/ | ||
public function testSecretPath() | ||
{ | ||
$secret_ini=Config::get('secret_config_path'); | ||
$this->assertFileExists($secret_ini, $secret_ini.' Config cannot find'); | ||
return $secret_ini; | ||
} | ||
|
||
/** | ||
* @depends testSecretPath | ||
*/ | ||
public function testSecret($path) | ||
{ | ||
$secret=parse_ini_file($path, true); | ||
foreach ($secret as $name => &$key) { | ||
foreach ($key as $k => $v) { | ||
$this->assertSame(Config::getSecret($name, $k), $v, "$name.$k"); | ||
} | ||
} | ||
} | ||
|
||
public function testSecretArray() | ||
{ | ||
$default_db=Config::getSecret('database', 'db._'); | ||
$this->assertNotEmpty($default_db); | ||
$this->assertArrayHasKey('dsn', $default_db); | ||
} | ||
|
||
/*检测sceret空值*/ | ||
public function testSecretEmpty() | ||
{ | ||
$key=uniqid('_tse_', true); | ||
$this->assertSame(Config::getSecret('database', $key), null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit bootstrap="./init.php" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
colors="true"> | ||
|
||
<testsuites> | ||
|
||
<testsuite name="Environment"> | ||
<file>EnvTest.php</file> | ||
</testsuite> | ||
|
||
<testsuite name="Library"> | ||
<directory>library</directory> | ||
</testsuite> | ||
|
||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">../library</directory> | ||
</whitelist> | ||
</filter> | ||
|
||
</phpunit> |