-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
91 additions
and
2 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,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<phpunit bootstrap="./tests/bootstrap.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="yii2-phpsms Test Suite"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
</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
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,63 @@ | ||
<?php | ||
|
||
namespace kuangjy\RandomLib\Tests; | ||
|
||
use yii\di\Container; | ||
use yii\helpers\ArrayHelper; | ||
use Yii; | ||
|
||
/** | ||
* This is the base class for all yii framework unit tests. | ||
*/ | ||
abstract class TestCase extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* Clean up after test. | ||
* By default the application created with [[mockApplication]] will be destroyed. | ||
*/ | ||
protected function tearDown() | ||
{ | ||
parent::tearDown(); | ||
$this->destroyApplication(); | ||
} | ||
|
||
/** | ||
* Populates Yii::$app with a new application | ||
* The application will be destroyed on tearDown() automatically. | ||
* @param array $config The application configuration, if needed | ||
* @param string $appClass name of the application class to create | ||
*/ | ||
protected function mockApplication($config = [], $appClass = '\yii\console\Application') | ||
{ | ||
new $appClass(ArrayHelper::merge([ | ||
'id' => 'testapp', | ||
'basePath' => __DIR__, | ||
'vendorPath' => dirname(__DIR__) . '/vendor', | ||
], $config)); | ||
} | ||
|
||
protected function mockWebApplication($config = [], $appClass = '\yii\web\Application') | ||
{ | ||
new $appClass(ArrayHelper::merge([ | ||
'id' => 'testapp', | ||
'basePath' => __DIR__, | ||
'vendorPath' => dirname(__DIR__) . '/vendor', | ||
'components' => [ | ||
'request' => [ | ||
'cookieValidationKey' => 'wefJDF8sfdsfSDefwqdxj9oq', | ||
'scriptFile' => __DIR__ . '/index.php', | ||
'scriptUrl' => '/index.php', | ||
], | ||
], | ||
], $config)); | ||
} | ||
|
||
/** | ||
* Destroys application in Yii::$app by setting it to null. | ||
*/ | ||
protected function destroyApplication() | ||
{ | ||
Yii::$app = null; | ||
Yii::$container = new Container(); | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
// ensure we get report on all possible php errors | ||
error_reporting(-1); | ||
|
||
define('YII_ENABLE_ERROR_HANDLER', false); | ||
define('YII_DEBUG', true); | ||
$_SERVER['SCRIPT_NAME'] = '/' . __DIR__; | ||
$_SERVER['SCRIPT_FILENAME'] = __FILE__; | ||
|
||
require_once(__DIR__ . '/../vendor/autoload.php'); | ||
require_once(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); |