-
Notifications
You must be signed in to change notification settings - Fork 73
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 #1 from monster-hunter/master
phpunit
- Loading branch information
Showing
17 changed files
with
579 additions
and
9 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,10 @@ | ||
imports: | ||
- php | ||
|
||
tools: | ||
external_code_coverage: | ||
timeout: 1800 # Timeout in seconds. | ||
# disable copy paste detector and similarity analyzer as they have no real value | ||
# and a huge bunch of false-positives | ||
php_sim: false | ||
php_cpd: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
preset: psr2 |
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,34 @@ | ||
language: php | ||
|
||
matrix: | ||
fast_finish: true | ||
|
||
php: | ||
- 5.6 | ||
#- 7.1 | ||
|
||
# cache vendor dirs | ||
cache: | ||
directories: | ||
- $HOME/.composer/cache | ||
- vendor | ||
|
||
services: | ||
- mysql | ||
|
||
install: | ||
- travis_retry composer self-update | ||
- composer config -g github-oauth.github.com dcb6b0049723eb6f56039b2d6389ac76eb29e352 | ||
- travis_retry composer install --prefer-dist --no-interaction | ||
- travis_retry mysql -e 'CREATE DATABASE test;' | ||
|
||
before_script: | ||
- travis_retry composer self-update | ||
- travis_retry composer install --no-interaction --prefer-source --dev | ||
|
||
script: | ||
- ./vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover | ||
|
||
after_script: | ||
- wget https://scrutinizer-ci.com/ocular.phar | ||
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover |
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
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,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="./tests/bootstrap.php" | ||
colors="true" | ||
verbose="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">./models</directory> | ||
<directory suffix=".php">./components</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
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,83 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: zjw | ||
* Date: 2017/8/7 | ||
* Time: 下午3:56 | ||
*/ | ||
|
||
namespace pheme\settings\tests; | ||
|
||
use Yii; | ||
|
||
class BaseSettingModelTest extends TestCase | ||
{ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->setting = Yii::$app->settings; | ||
$this->model->value = "i am testSet value"; | ||
$this->model->section = "testSetKey"; | ||
$this->model->type = 'string'; | ||
$this->model->modified = time(); | ||
$this->model->active = "1"; | ||
$this->model->key = 'testSetKey'; | ||
$this->model->save(); | ||
} | ||
|
||
public function testSave() | ||
{ | ||
$this->model->type = "double"; | ||
$this->assertFalse($this->model->save()); | ||
} | ||
|
||
public function testGetSettings() | ||
{ | ||
$res = $this->model->getSettings()['testSetKey']['testSetKey']; | ||
$this->assertTrue($res[0] == 'i am testSet value'); | ||
$this->assertTrue($res[1] == 'string'); | ||
} | ||
|
||
public function testSetSetting() | ||
{ | ||
$res = $this->model->setSetting("testSetKey", "testSetKey", "aa", "string"); | ||
$this->assertTrue($res); | ||
$res = $this->model->setSetting("testSetKey", "testSetKey1", "bb", "string"); | ||
$this->assertTrue($res); | ||
} | ||
|
||
public function testDeactivateSetting() | ||
{ | ||
$res = $this->model->deactivateSetting("testSetKey", "testSetKey"); | ||
$this->assertTrue($res); | ||
$res = $this->model->deactivateSetting("testSetKey", "testSetKey"); | ||
$this->assertFalse($res); | ||
} | ||
|
||
public function testActivateSetting() | ||
{ | ||
$res1 = $this->model->deactivateSetting("testSetKey", "testSetKey"); | ||
$res2 = $this->model->activateSetting("testSetKey", "testSetKey"); | ||
$this->assertTrue($res1 && $res2); | ||
$res3 = $this->model->activateSetting("testSetKey", "testSetKey"); | ||
$this->assertFalse($res3); | ||
} | ||
|
||
public function testDeleteSetting() | ||
{ | ||
$res = $this->model->deleteSetting("testSetKey", "testSetKey"); | ||
$this->assertTrue($res == 1); | ||
} | ||
|
||
public function testDeleteAllSettings() | ||
{ | ||
$res = $this->model->deleteAllSettings(); | ||
$this->assertTrue($res == 1); | ||
} | ||
|
||
public function testFindSetting() | ||
{ | ||
$res = $this->model->findSetting("testSetKey", "testSetKey"); | ||
$this->assertTrue($res->id > 0); | ||
} | ||
} |
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,100 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: zjw | ||
* Date: 2017/8/7 | ||
* Time: 下午6:00 | ||
*/ | ||
|
||
namespace pheme\settings\tests; | ||
|
||
use pheme\settings\components\Settings; | ||
use Yii; | ||
|
||
class ComponentSettingTest extends TestCase | ||
{ | ||
/** | ||
* @var \pheme\settings\components\Settings | ||
*/ | ||
public $setting; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->setting = Yii::$app->settings; | ||
$this->setting->init(); | ||
$this->model->value = "i am testSet value"; | ||
$this->model->section = "testSetKey"; | ||
$this->model->type = 'string'; | ||
$this->model->modified = time(); | ||
$this->model->active = "0"; | ||
$this->model->key = 'testSetKey'; | ||
$this->model->save(); | ||
} | ||
|
||
public function testSet() | ||
{ | ||
$res = $this->setting->set('testSetKey', "i am testSet value", 'testSetKey'); | ||
$this->assertTrue($res, '通过组件来修改testSetKey的section'); | ||
} | ||
|
||
public function testGet() | ||
{ | ||
$this->setting->activate("testSetKey", "testSetKey"); | ||
$res = $this->setting->get("testSetKey", "testSetKey"); | ||
$this->assertTrue($res == "i am testSet value"); | ||
$res1 = $this->setting->get("testSetKey.testSetKey"); | ||
$this->assertTrue($res1 == "i am testSet value"); | ||
} | ||
|
||
public function testHas() | ||
{ | ||
$this->setting->activate("testSetKey", "testSetKey"); | ||
$res = $this->setting->has("testSetKey", "testSetKey"); | ||
$this->assertTrue($res); | ||
} | ||
|
||
public function testDelete() | ||
{ | ||
$res = $this->setting->delete("testSetKey", "testSetKey"); | ||
$this->assertTrue($res == 1); | ||
} | ||
|
||
public function testDeleteAll() | ||
{ | ||
$res = $this->setting->deleteAll(); | ||
$this->assertTrue($res > 0); | ||
} | ||
|
||
public function testActivate() | ||
{ | ||
$res = $this->setting->activate("testSetKey", "testSetKey"); | ||
$this->assertTrue($res); | ||
} | ||
|
||
public function testDeActivate() | ||
{ | ||
$this->setting->activate("testSetKey", "testSetKey"); | ||
$res = $this->setting->deactivate("testSetKey", "testSetKey"); | ||
$this->assertTrue($res); | ||
} | ||
|
||
public function testGetRawConfig() | ||
{ | ||
$this->setting->activate("testSetKey", "testSetKey"); | ||
$this->setting->get('testSetKey', "testSetKey"); | ||
$res = $this->setting->getRawConfig(); | ||
$this->assertTrue($res['testSetKey']['testSetKey'][0] == $this->model->value); | ||
} | ||
|
||
public function testClearCache() | ||
{ | ||
$res = $this->setting->clearCache(); | ||
$this->assertTrue($res); | ||
} | ||
|
||
public function testGetModelClass() | ||
{ | ||
$this->assertTrue($this->setting->modelClass == (new Settings())->modelClass); | ||
} | ||
} |
Oops, something went wrong.