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
3f4ee3e4
Commit
3f4ee3e4
authored
Dec 28, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #1604: fixed URL and cookie problems.
Refactored tests.
parent
f554d46a
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
66 additions
and
91 deletions
+66
-91
functional.php
apps/basic/config/codeception/functional.php
+0
-17
unit.php
apps/basic/config/codeception/unit.php
+0
-15
README.md
apps/basic/tests/README.md
+19
-26
_bootstrap.php
apps/basic/tests/_bootstrap.php
+13
-0
acceptance.suite.yml
apps/basic/tests/acceptance.suite.yml
+2
-2
HomeCept.php
apps/basic/tests/acceptance/HomeCept.php
+1
-1
_bootstrap.php
apps/basic/tests/acceptance/_bootstrap.php
+1
-6
_config.php
apps/basic/tests/acceptance/_config.php
+6
-4
functional.suite.yml
apps/basic/tests/functional.suite.yml
+1
-2
HomeCept.php
apps/basic/tests/functional/HomeCept.php
+1
-1
_bootstrap.php
apps/basic/tests/functional/_bootstrap.php
+1
-2
_config.php
apps/basic/tests/functional/_config.php
+17
-0
index-test-functional.php
apps/basic/web/index-test-functional.php
+0
-11
index-test.php
apps/basic/web/index-test.php
+4
-4
No files found.
apps/basic/config/codeception/functional.php
deleted
100644 → 0
View file @
f554d46a
<?php
// configuration adjustments for codeception functional tests. Will be merged with web.php config.
return
[
'components'
=>
[
'db'
=>
[
'dsn'
=>
'mysql:host=localhost;dbname=yii2basic_functional'
,
],
'request'
=>
[
'enableCsrfValidation'
=>
false
,
],
'urlManager'
=>
[
'baseUrl'
=>
'/web/index.php'
,
],
],
];
apps/basic/config/codeception/unit.php
deleted
100644 → 0
View file @
f554d46a
<?php
// configuration adjustments for codeception unit tests. Will be merged with web.php config.
return
[
'components'
=>
[
'fixture'
=>
[
'class'
=>
'yii\test\DbFixtureManager'
,
'basePath'
=>
'@tests/unit/fixtures'
,
],
'db'
=>
[
'dsn'
=>
'mysql:host=localhost;dbname=yii2basic_unit'
,
],
],
];
apps/basic/tests/README.md
View file @
3f4ee3e4
This folder contains various tests for the basic application.
This folder contains various tests for the basic application.
These tests are developed with
[
Codeception PHP Testing Framework
](
http://codeception.com/
)
.
These tests are developed with
[
Codeception PHP Testing Framework
](
http://codeception.com/
)
.
To run the tests, follow these step
s:
After creating the basic application, follow these steps to prepare for the test
s:
1.
Download Codeception(
[
Quickstart step 1
](
http://codeception.com/quickstart
)
) and put the codeception.phar in the
1.
In the file
`_bootstrap.php`
, modify the definition of the constant
`TEST_ENTRY_URL`
so
application base directory (not in this
`tests`
directory!).
that it points to the correct entry script URL.
2.
Adjust the test configuration files based on your environment:
2.
Go to the application base directory and build the test suites:
-
Configure the URL for
[
acceptance tests
](
http://codeception.com/docs/04-AcceptanceTests
)
in
`acceptance.suite.yml`
.
The URL should point to the
`index-test-acceptance.php`
file that is located under the
`web`
directory of the application.
-
`functional.suite.yml`
for
[
functional testing
](
http://codeception.com/docs/05-FunctionalTests
)
and
`unit.suite.yml`
for
[
unit testing
](
http://codeception.com/docs/06-UnitTests
)
should already work out of the box
and should not need to be adjusted.
-
If you want to run acceptance tests, you need to download
[
selenium standalone
](
http://www.seleniumhq.org/download/
)
and start it with command
`java -jar {selenium-standalone-name}.jar`
.
After that you can use
`WebDriver`
codeception module that will connect to selenium and launch browser.
This also allows you to use
[
Xvfb
](
https://en.wikipedia.org/wiki/Xvfb
)
in your tests which allows you to run tests
without showing the running browser on the screen. There is codeception
[
blog post
](
http://codeception.com/05-24-2013/jenkins-ci-practice.html
)
that explains how it works.
3.
Go to the application base directory and build the test suites:
```
```
php codecept.phar build // rebuild test scripts, only need to be run once
vendor/bin/codecept build
```
4.
Run the tests:
```
php codecept.phar run // run all available tests
// you can also run a test suite alone:
php codecept.phar run acceptance
php codecept.phar run functional
php codecept.phar run unit
```
```
Now you can run the tests with the following commands:
```
# run all available tests
vendor/bin/codecept run
# run acceptance tests
vendor/bin/codecept run acceptance
# run functional tests
vendor/bin/codecept run functional
# run unit tests
vendor/bin/codecept run unit
```
Please refer to
[
Codeception tutorial
](
http://codeception.com/docs/01-Introduction
)
for
Please refer to
[
Codeception tutorial
](
http://codeception.com/docs/01-Introduction
)
for
more details about writing acceptance, functional and unit tests.
more details about writing a
nd running a
cceptance, functional and unit tests.
apps/basic/tests/_bootstrap.php
View file @
3f4ee3e4
<?php
<?php
// the entry script URL (without host info) for functional and acceptance tests
// PLEASE ADJUST IT TO THE ACTUAL ENTRY SCRIPT URL
defined
(
'TEST_ENTRY_URL'
)
or
define
(
'TEST_ENTRY_URL'
,
'/yii2-basic/web/index-test.php'
);
// the entry script file path for functional and acceptance tests
defined
(
'TEST_ENTRY_FILE'
)
or
define
(
'TEST_ENTRY_FILE'
,
dirname
(
__DIR__
)
.
'/web/index-test.php'
);
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'
);
require_once
(
__DIR__
.
'/../vendor/autoload.php'
);
require_once
(
__DIR__
.
'/../vendor/autoload.php'
);
require_once
(
__DIR__
.
'/../vendor/yiisoft/yii2/yii/Yii.php'
);
require_once
(
__DIR__
.
'/../vendor/yiisoft/yii2/yii/Yii.php'
);
// set correct script paths
$_SERVER
[
'SCRIPT_FILENAME'
]
=
TEST_ENTRY_FILE
;
$_SERVER
[
'SCRIPT_NAME'
]
=
TEST_ENTRY_URL
;
Yii
::
setAlias
(
'@tests'
,
__DIR__
);
Yii
::
setAlias
(
'@tests'
,
__DIR__
);
apps/basic/tests/acceptance.suite.yml
View file @
3f4ee3e4
...
@@ -18,7 +18,7 @@ modules:
...
@@ -18,7 +18,7 @@ modules:
# - WebDriver
# - WebDriver
config
:
config
:
PhpBrowser
:
PhpBrowser
:
url
:
'
http://localhost
/basic-app/web/index-test-acceptance.php
'
url
:
'
http://localhost'
# WebDriver:
# WebDriver:
# url: 'http://localhost
/basic-app/web/index-test-acceptance.php
'
# url: 'http://localhost'
# browser: firefox
# browser: firefox
apps/basic/tests/acceptance/HomeCept.php
View file @
3f4ee3e4
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
$I
=
new
WebGuy
(
$scenario
);
$I
=
new
WebGuy
(
$scenario
);
$I
->
wantTo
(
'ensure that home page works'
);
$I
->
wantTo
(
'ensure that home page works'
);
$I
->
amOnPage
(
''
);
$I
->
amOnPage
(
Yii
::
$app
->
homeUrl
);
$I
->
see
(
'My Company'
);
$I
->
see
(
'My Company'
);
$I
->
seeLink
(
'About'
);
$I
->
seeLink
(
'About'
);
$I
->
click
(
'About'
);
$I
->
click
(
'About'
);
...
...
apps/basic/tests/acceptance/_bootstrap.php
View file @
3f4ee3e4
<?php
<?php
$config
=
yii\helpers\ArrayHelper
::
merge
(
new
yii\web\Application
(
require
(
__DIR__
.
'/_config.php'
));
require
(
__DIR__
.
'/../../config/web.php'
),
require
(
__DIR__
.
'/../../config/codeception/acceptance.php'
)
);
$application
=
new
yii\web\Application
(
$config
);
apps/basic/
config/codeception/acceptance
.php
→
apps/basic/
tests/acceptance/_config
.php
View file @
3f4ee3e4
<?php
<?php
// configuration adjustments for codeception acceptance tests. Will be merged with web.php config.
use
yii\helpers\ArrayHelper
;
return
[
$config
=
require
(
__DIR__
.
'/../../config/web.php'
);
return
ArrayHelper
::
merge
(
$config
,
[
'components'
=>
[
'components'
=>
[
'db'
=>
[
'db'
=>
[
'dsn'
=>
'mysql:host=localhost;dbname=yii2basic_acceptance'
,
'dsn'
=>
'mysql:host=localhost;dbname=yii2
_
basic_acceptance'
,
],
],
],
],
];
]
)
;
apps/basic/tests/functional.suite.yml
View file @
3f4ee3e4
...
@@ -14,5 +14,4 @@ modules:
...
@@ -14,5 +14,4 @@ modules:
-
Yii2
-
Yii2
config
:
config
:
Yii2
:
Yii2
:
entryScript
:
'
web/index-test-functional.php'
configFile
:
'
tests/functional/_config.php'
url
:
'
http://localhost/'
apps/basic/tests/functional/HomeCept.php
View file @
3f4ee3e4
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
$I
=
new
TestGuy
(
$scenario
);
$I
=
new
TestGuy
(
$scenario
);
$I
->
wantTo
(
'ensure that home page works'
);
$I
->
wantTo
(
'ensure that home page works'
);
$I
->
amOnPage
(
''
);
$I
->
amOnPage
(
Yii
::
$app
->
homeUrl
);
$I
->
see
(
'My Company'
);
$I
->
see
(
'My Company'
);
$I
->
seeLink
(
'About'
);
$I
->
seeLink
(
'About'
);
$I
->
click
(
'About'
);
$I
->
click
(
'About'
);
...
...
apps/basic/tests/functional/_bootstrap.php
View file @
3f4ee3e4
<?php
<?php
// create an application instance to support URL creation before running any test
new
yii\web\Application
(
require
(
__DIR__
.
'/_config.php'
));
Yii
::
createObject
(
require
(
__DIR__
.
'/../../web/index-test-functional.php'
));
apps/basic/tests/functional/_config.php
0 → 100644
View file @
3f4ee3e4
<?php
use
yii\helpers\ArrayHelper
;
// set correct script paths
$_SERVER
[
'SCRIPT_FILENAME'
]
=
TEST_ENTRY_FILE
;
$_SERVER
[
'SCRIPT_NAME'
]
=
TEST_ENTRY_URL
;
$config
=
require
(
__DIR__
.
'/../../config/web.php'
);
return
ArrayHelper
::
merge
(
$config
,
[
'components'
=>
[
'db'
=>
[
'dsn'
=>
'mysql:host=localhost;dbname=yii2_basic_functional'
,
],
],
]);
apps/basic/web/index-test-functional.php
deleted
100644 → 0
View file @
f554d46a
<?php
// this file is used as the entry script for codeception functional testing
$config
=
yii\helpers\ArrayHelper
::
merge
(
require
(
__DIR__
.
'/../config/web.php'
),
require
(
__DIR__
.
'/../config/codeception/functional.php'
)
);
$config
[
'class'
]
=
'yii\web\Application'
;
return
$config
;
apps/basic/web/index-test
-acceptance
.php
→
apps/basic/web/index-test.php
View file @
3f4ee3e4
<?php
<?php
// NOTE: Make sure this file is not accessible when deployed to production
// NOTE: Make sure this file is not accessible when deployed to production
if
(
!
in_array
(
@
$_SERVER
[
'REMOTE_ADDR'
],
[
'127.0.0.1'
,
'::1'
]))
{
die
(
'You are not allowed to access this file.'
);
}
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'
);
...
@@ -8,9 +11,6 @@ defined('YII_ENV') or define('YII_ENV', 'test');
...
@@ -8,9 +11,6 @@ defined('YII_ENV') or define('YII_ENV', 'test');
require
(
__DIR__
.
'/../vendor/autoload.php'
);
require
(
__DIR__
.
'/../vendor/autoload.php'
);
require
(
__DIR__
.
'/../vendor/yiisoft/yii2/yii/Yii.php'
);
require
(
__DIR__
.
'/../vendor/yiisoft/yii2/yii/Yii.php'
);
$config
=
yii\helpers\ArrayHelper
::
merge
(
$config
=
require
(
__DIR__
.
'/../tests/acceptance/_config.php'
);
require
(
__DIR__
.
'/../config/web.php'
),
require
(
__DIR__
.
'/../config/codeception/acceptance.php'
)
);
(
new
yii\web\Application
(
$config
))
->
run
();
(
new
yii\web\Application
(
$config
))
->
run
();
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