Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
3d934003
Commit
3d934003
authored
Dec 18, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test refactoring.
parent
cf61967d
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
22 additions
and
31 deletions
+22
-31
HelloController.php
apps/basic/commands/HelloController.php
+1
-1
web.php
apps/basic/config/web.php
+2
-4
_bootstrap.php
apps/basic/tests/unit/_bootstrap.php
+2
-3
index-test-acceptance.php
apps/basic/web/index-test-acceptance.php
+2
-3
index.php
apps/basic/web/index.php
+1
-2
TestCase.php
extensions/yii/codeception/TestCase.php
+14
-18
No files found.
apps/basic/commands/HelloController.php
View file @
3d934003
...
@@ -25,6 +25,6 @@ class HelloController extends Controller
...
@@ -25,6 +25,6 @@ class HelloController extends Controller
*/
*/
public
function
actionIndex
(
$message
=
'hello world'
)
public
function
actionIndex
(
$message
=
'hello world'
)
{
{
echo
$message
.
"
\n
"
;
echo
$message
.
"
\n
"
;
}
}
}
}
apps/basic/config/web.php
View file @
3d934003
...
@@ -39,16 +39,14 @@ $config = [
...
@@ -39,16 +39,14 @@ $config = [
'params'
=>
$params
,
'params'
=>
$params
,
];
];
if
(
YII_ENV_DEV
)
if
(
YII_ENV_DEV
)
{
{
// configuration adjustments for 'dev' environment
// configuration adjustments for 'dev' environment
$config
[
'preload'
][]
=
'debug'
;
$config
[
'preload'
][]
=
'debug'
;
$config
[
'modules'
][
'debug'
]
=
'yii\debug\Module'
;
$config
[
'modules'
][
'debug'
]
=
'yii\debug\Module'
;
$config
[
'modules'
][
'gii'
]
=
'yii\gii\Module'
;
$config
[
'modules'
][
'gii'
]
=
'yii\gii\Module'
;
}
}
if
(
YII_ENV_TEST
)
if
(
YII_ENV_TEST
)
{
{
// configuration adjustments for 'test' environment.
// configuration adjustments for 'test' environment.
// configuration for codeception test environments can be found in codeception folder.
// configuration for codeception test environments can be found in codeception folder.
...
...
apps/basic/tests/unit/_bootstrap.php
View file @
3d934003
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
// add unit testing specific bootstrap code here
// add unit testing specific bootstrap code here
yii\codeception\TestCase
::
$app
lication
Config
=
yii\helpers\ArrayHelper
::
merge
(
yii\codeception\TestCase
::
$appConfig
=
yii\helpers\ArrayHelper
::
merge
(
require
(
__DIR__
.
'/../../config/web.php'
),
require
(
__DIR__
.
'/../../config/web.php'
),
require
(
__DIR__
.
'/../../config/codeception/unit.php'
)
require
(
__DIR__
.
'/../../config/codeception/unit.php'
)
);
);
\ No newline at end of file
apps/basic/web/index-test-acceptance.php
View file @
3d934003
<?php
<?php
// NOTE: Make sure this file is not access
a
ble when deployed to production
// NOTE: Make sure this file is not access
i
ble when deployed to production
defined
(
'YII_DEBUG'
)
or
define
(
'YII_DEBUG'
,
true
);
defined
(
'YII_DEBUG'
)
or
define
(
'YII_DEBUG'
,
true
);
defined
(
'YII_ENV'
)
or
define
(
'YII_ENV'
,
'test'
);
defined
(
'YII_ENV'
)
or
define
(
'YII_ENV'
,
'test'
);
...
@@ -13,5 +13,4 @@ $config = yii\helpers\ArrayHelper::merge(
...
@@ -13,5 +13,4 @@ $config = yii\helpers\ArrayHelper::merge(
require
(
__DIR__
.
'/../config/codeception/acceptance.php'
)
require
(
__DIR__
.
'/../config/codeception/acceptance.php'
)
);
);
$application
=
new
yii\web\Application
(
$config
);
(
new
yii\web\Application
(
$config
))
->
run
();
$application
->
run
();
apps/basic/web/index.php
View file @
3d934003
...
@@ -9,5 +9,4 @@ require(__DIR__ . '/../vendor/yiisoft/yii2/yii/Yii.php');
...
@@ -9,5 +9,4 @@ require(__DIR__ . '/../vendor/yiisoft/yii2/yii/Yii.php');
$config
=
require
(
__DIR__
.
'/../config/web.php'
);
$config
=
require
(
__DIR__
.
'/../config/web.php'
);
$application
=
new
yii\web\Application
(
$config
);
(
new
yii\web\Application
(
$config
))
->
run
();
$application
->
run
();
extensions/yii/codeception/TestCase.php
View file @
3d934003
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
namespace
yii\codeception
;
namespace
yii\codeception
;
use
Yii
;
use
Yii
;
use
yii\helpers\ArrayHelper
;
/**
/**
* TestCase is the base class for all codeception unit tests
* TestCase is the base class for all codeception unit tests
...
@@ -14,22 +13,18 @@ use yii\helpers\ArrayHelper;
...
@@ -14,22 +13,18 @@ use yii\helpers\ArrayHelper;
class
TestCase
extends
\PHPUnit_Framework_TestCase
class
TestCase
extends
\PHPUnit_Framework_TestCase
{
{
/**
/**
* @var array|string Your application base config that will be used for creating application each time before test.
* @var array the application configuration that will be used for creating an application instance for each test.
* This can be an array or alias, pointing to the config file. For example for console application it can be
* '@tests/unit/console_bootstrap.php' that can be similar to existing unit tests bootstrap file.
*/
*/
public
static
$app
licationConfig
=
'@app/config/web.php'
;
public
static
$app
Config
=
[]
;
/**
/**
* @var
array|string Your application config, will be merged with base config when creating application. Can be an alias too.
* @var
string the application class that [[mockApplication()]] should use
*/
*/
protected
$config
=
[];
public
static
$appClass
=
'yii\web\Application'
;
/**
/**
* Created application class
* @inheritdoc
* @var string
*/
*/
protected
$applicationClass
=
'yii\web\Application'
;
protected
function
tearDown
()
protected
function
tearDown
()
{
{
$this
->
destroyApplication
();
$this
->
destroyApplication
();
...
@@ -37,20 +32,21 @@ class TestCase extends \PHPUnit_Framework_TestCase
...
@@ -37,20 +32,21 @@ class TestCase extends \PHPUnit_Framework_TestCase
}
}
/**
/**
* Sets up `Yii::$app`.
* Mocks up the application instance.
* @param array $config the configuration that should be used to generate the application instance.
* If null, [[appConfig]] will be used.
* @return \yii\web\Application|\yii\console\Application the application instance
*/
*/
protected
function
mockApplication
()
protected
function
mockApplication
(
$config
=
null
)
{
{
$baseConfig
=
is_array
(
static
::
$applicationConfig
)
?
static
::
$applicationConfig
:
require
(
Yii
::
getAlias
(
static
::
$applicationConfig
));
return
new
static
::
$appClass
(
$config
===
null
?
static
::
$appConfig
:
$config
);
$config
=
is_array
(
$this
->
config
)
?
$this
->
config
:
require
(
Yii
::
getAlias
(
$this
->
config
));
new
$this
->
applicationClass
(
ArrayHelper
::
merge
(
$baseConfig
,
$config
));
}
}
/**
/**
* Destroys
an application created via
[[mockApplication]].
* Destroys
the application instance created by
[[mockApplication]].
*/
*/
protected
function
destroyApplication
()
protected
function
destroyApplication
()
{
{
\
Yii
::
$app
=
null
;
Yii
::
$app
=
null
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment