Skip to content

Commit 0d13373

Browse files
committed
Init
0 parents  commit 0d13373

File tree

125 files changed

+3240
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+3240
-0
lines changed

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# yii console command
2+
/yii
3+
4+
# phpstorm project files
5+
.idea
6+
7+
# netbeans project files
8+
nbproject
9+
10+
# zend studio for eclipse project files
11+
.buildpath
12+
.project
13+
.settings
14+
15+
# windows thumbnail cache
16+
Thumbs.db
17+
18+
# composer vendor dir
19+
/vendor
20+
21+
# composer itself is not needed
22+
composer.phar
23+
24+
# Mac DS_Store Files
25+
.DS_Store
26+
27+
# phpunit itself is not needed
28+
phpunit.phar
29+
# local phpunit config
30+
/phpunit.xml

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## Test REST API application on [Yii2](https://github.com/yiisoft/yii2)
2+
3+
###INSTALLATION###
4+
5+
**Install via Composer**
6+
7+
If you do not have [Composer](http://getcomposer.org/), you may install it by following the
8+
[instructions at getcomposer.org](https://getcomposer.org/doc/00-intro.md).
9+
10+
You can then install the application using the following command:
11+
`composer create-project --prefer-dist -s dev "githubjeka/rest-yii2" .`
12+
13+
###GETTING STARTED###
14+
15+
After you install the application, you have to conduct the following steps to initialize the installed application.
16+
You only need to do these once for all.
17+
18+
- Create a new database and adjust the components['db'] configuration in `environments/dev/common/config/main-local.php` accordingly.
19+
- Run command `php init` to initialize the application with a specific environment. Choose **dev**.
20+
- Apply migrations with console command ``php yii migrate``. This will create tables needed for the application to work.
21+
- Set document roots of your Web server:
22+
23+
for frontend /path/to/yii-application/rest/web/ and using the URL http://rest-localhost/
24+
for backend /path/to/yii-application/backend/web/ and using the URL http://backend-localhost/
25+
26+
To login into the application is `demo/demo`.
27+
28+
[More information ... ](https://github.com/githubjeka/angular-yii2)
29+
30+
**TBD..**

backend/assets/AppAsset.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* @link http://www.yiiframework.com/
4+
* @copyright Copyright (c) 2008 Yii Software LLC
5+
* @license http://www.yiiframework.com/license/
6+
*/
7+
8+
namespace backend\assets;
9+
10+
use yii\web\AssetBundle;
11+
12+
/**
13+
* @author Qiang Xue <[email protected]>
14+
* @since 2.0
15+
*/
16+
class AppAsset extends AssetBundle
17+
{
18+
public $basePath = '@webroot';
19+
public $baseUrl = '@web';
20+
public $css = ['css/site.css'];
21+
public $js = [];
22+
public $depends = [
23+
'yii\web\YiiAsset',
24+
'yii\bootstrap\BootstrapAsset',
25+
];
26+
}

backend/codeception.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
paths:
2+
tests: tests
3+
log: tests/_log
4+
data: tests/_data
5+
helpers: tests/_helpers
6+
settings:
7+
bootstrap: _bootstrap.php
8+
suite_class: \PHPUnit_Framework_TestSuite
9+
colors: true
10+
memory_limit: 1024M
11+
log: true
12+
modules:
13+
config:
14+
Db:
15+
dsn: ''
16+
user: ''
17+
password: ''
18+
dump: tests/_data/dump.sql

backend/config/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
main-local.php
2+
params-local.php

backend/config/main.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
$params = array_merge(
3+
require(__DIR__ . '/../../common/config/params.php'),
4+
require(__DIR__ . '/../../common/config/params-local.php'),
5+
require(__DIR__ . '/params.php'),
6+
require(__DIR__ . '/params-local.php')
7+
);
8+
9+
return [
10+
'id' => 'app-backend',
11+
'basePath' => dirname(__DIR__),
12+
'controllerNamespace' => 'backend\controllers',
13+
'bootstrap' => ['log'],
14+
'modules' => [],
15+
'components' => [
16+
'user' => [
17+
'identityClass' => 'common\models\User',
18+
'enableAutoLogin' => true,
19+
],
20+
'log' => [
21+
'traceLevel' => YII_DEBUG ? 3 : 0,
22+
'targets' => [
23+
[
24+
'class' => 'yii\log\FileTarget',
25+
'levels' => ['error', 'warning'],
26+
],
27+
],
28+
],
29+
'errorHandler' => [
30+
'errorAction' => 'site/error',
31+
],
32+
],
33+
'params' => $params,
34+
];

backend/config/params.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
return [
3+
'adminEmail' => '[email protected]',
4+
];
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
namespace backend\controllers;
3+
4+
use yii\web\Controller;
5+
6+
class SiteController extends Controller
7+
{
8+
public function actions()
9+
{
10+
return [
11+
'error' => [
12+
'class' => 'yii\web\ErrorAction',
13+
],
14+
];
15+
}
16+
}

backend/models/.gitkeep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*

backend/runtime/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

backend/tests/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# these files are auto generated by codeception build
2+
/unit/CodeGuy.php
3+
/functional/TestGuy.php
4+
/acceptance/WebGuy.php

backend/tests/_bootstrap.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
// the entry script URL (without host info) for functional and acceptance tests
4+
// PLEASE ADJUST IT TO THE ACTUAL ENTRY SCRIPT URL
5+
defined('TEST_ENTRY_URL') or define('TEST_ENTRY_URL', '/advanced/backend/web/index-test.php');
6+
7+
// the entry script file path for functional and acceptance tests
8+
defined('TEST_ENTRY_FILE') or define('TEST_ENTRY_FILE', dirname(__DIR__) . '/web/index-test.php');
9+
10+
defined('YII_DEBUG') or define('YII_DEBUG', true);
11+
12+
defined('YII_ENV') or define('YII_ENV', 'test');
13+
14+
require_once(__DIR__ . '/../../vendor/autoload.php');
15+
16+
require_once(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
17+
18+
require(__DIR__ . '/../../common/config/aliases.php');
19+
20+
// set correct script paths
21+
$_SERVER['SCRIPT_FILENAME'] = TEST_ENTRY_FILE;
22+
$_SERVER['SCRIPT_NAME'] = TEST_ENTRY_URL;
23+
$_SERVER['SERVER_NAME'] = 'localhost';

backend/tests/_config.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
/**
3+
* application configurations shared by all test types
4+
*/
5+
return [
6+
'components' => [
7+
'mail' => [
8+
'useFileTransport' => true,
9+
],
10+
'urlManager' => [
11+
'showScriptName' => true,
12+
],
13+
],
14+
];

backend/tests/_console.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* Yii console bootstrap file.
4+
*
5+
* @link http://www.yiiframework.com/
6+
* @copyright Copyright (c) 2008 Yii Software LLC
7+
* @license http://www.yiiframework.com/license/
8+
*/
9+
10+
// fcgi doesn't have STDIN and STDOUT defined by default
11+
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
12+
defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w'));
13+
14+
require_once(__DIR__ . '/../../vendor/autoload.php');
15+
require_once(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
16+
require_once(__DIR__ . '/../../common/config/aliases.php');
17+
18+
defined('YII_DEBUG') or define('YII_DEBUG', true);
19+
defined('YII_ENV') or define('YII_ENV', 'test');

backend/tests/_data/dump.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* Replace this file with actual dump of your database */

backend/tests/_helpers/CodeHelper.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
namespace Codeception\Module;
3+
4+
// here you can define custom functions for CodeGuy
5+
6+
class CodeHelper extends \Codeception\Module
7+
{
8+
}

backend/tests/_helpers/TestHelper.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
namespace Codeception\Module;
3+
4+
// here you can define custom functions for TestGuy
5+
6+
class TestHelper extends \Codeception\Module
7+
{
8+
}

backend/tests/_helpers/WebHelper.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
namespace Codeception\Module;
3+
4+
// here you can define custom functions for WebGuy
5+
6+
class WebHelper extends \Codeception\Module
7+
{
8+
}

backend/tests/_log/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

backend/tests/acceptance.suite.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Codeception Test Suite Configuration
2+
3+
# suite for acceptance tests.
4+
# perform tests in browser using the Selenium-like tools.
5+
# powered by Mink (http://mink.behat.org).
6+
# (tip: that's what your customer will see).
7+
# (tip: test your ajax and javascript by one of Mink drivers).
8+
9+
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
10+
11+
class_name: WebGuy
12+
modules:
13+
enabled:
14+
- WebHelper
15+
- PhpBrowser
16+
- common\tests\_helpers\FixtureHelper
17+
# you can use WebDriver instead of PhpBrowser to test javascript and ajax.
18+
# This will require you to install selenium. See http://codeception.com/docs/04-AcceptanceTests#Selenium
19+
# "restart" option is used by the WebDriver to start each time per test-file new session and cookies,
20+
# it is useful if you want to login in your app in each test.
21+
# - WebDriver
22+
config:
23+
PhpBrowser:
24+
url: 'http://localhost:8080'
25+
# WebDriver:
26+
# url: 'http://localhost'
27+
# browser: firefox
28+
# restart: true
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use common\tests\_pages\LoginPage;
4+
5+
$I = new WebGuy($scenario);
6+
$I->wantTo('ensure login page works');
7+
8+
$loginPage = LoginPage::openBy($I);
9+
10+
$I->amGoingTo('submit login form with no data');
11+
$loginPage->login('', '');
12+
$I->expectTo('see validations errors');
13+
$I->see('Username cannot be blank.', '.help-block');
14+
$I->see('Password cannot be blank.', '.help-block');
15+
16+
$I->amGoingTo('try to login with wrong credentials');
17+
$I->expectTo('see validations errors');
18+
$loginPage->login('admin', 'wrong');
19+
$I->expectTo('see validations errors');
20+
$I->see('Incorrect username or password.', '.help-block');
21+
22+
$I->amGoingTo('try to login with correct credentials');
23+
$loginPage->login('erau', 'password_0');
24+
$I->expectTo('see that user is logged');
25+
$I->seeLink('Logout (erau)');
26+
$I->dontSeeLink('Login');
27+
$I->dontSeeLink('Signup');
28+
/** Uncomment if using WebDriver
29+
* $I->click('Logout (erau)');
30+
* $I->dontSeeLink('Logout (erau)');
31+
* $I->seeLink('Login');
32+
*/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
new yii\web\Application(require(__DIR__ . '/_config.php'));

backend/tests/acceptance/_config.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
return yii\helpers\ArrayHelper::merge(
4+
require(__DIR__ . '/../../config/main.php'),
5+
require(__DIR__ . '/../../config/main-local.php'),
6+
require(__DIR__ . '/../../../common/config/main.php'),
7+
require(__DIR__ . '/../../../common/config/main-local.php'),
8+
require(__DIR__ . '/../_config.php'),
9+
[
10+
'components' => [
11+
'db' => [
12+
'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_acceptance',
13+
],
14+
],
15+
]
16+
);

backend/tests/acceptance/_console.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
return yii\helpers\ArrayHelper::merge(
4+
require(__DIR__ . '/../../../common/config/main.php'),
5+
require(__DIR__ . '/../../../common/config/main-local.php'),
6+
require(__DIR__ . '/../../../console/config/main.php'),
7+
require(__DIR__ . '/../../../console/config/main-local.php'),
8+
[
9+
'components' => [
10+
'db' => [
11+
'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_acceptance',
12+
],
13+
],
14+
]
15+
);

backend/tests/acceptance/yii

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env php
2+
<?php
3+
/**
4+
* Yii console bootstrap file.
5+
*
6+
* @link http://www.yiiframework.com/
7+
* @copyright Copyright (c) 2008 Yii Software LLC
8+
* @license http://www.yiiframework.com/license/
9+
*/
10+
11+
// fcgi doesn't have STDIN and STDOUT defined by default
12+
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
13+
defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w'));
14+
15+
require_once(__DIR__ . '/../_console.php');
16+
17+
$config = require(__DIR__ . '/_console.php');
18+
19+
$application = new yii\console\Application($config);
20+
$exitCode = $application->run();
21+
exit($exitCode);

0 commit comments

Comments
 (0)