Yii 2 Basic Project Template is a skeleton Yii 2 application best for rapidly creating small projects.
The template contains the basic features including user login/logout and a contact page. It includes all commonly used configurations that would allow you to focus on adding new features to your application.
commands/ contains console commands (controllers)
config/ contains application configurations
controllers/ contains Web controller classes
mail/ contains view files for e-mails
models/ contains model classes
runtime/ contains files generated during runtime
tests/ contains various tests for the basic application
vendor/ contains dependent 3rd-party packages
views/ contains view files for the Web application
web/ contains the entry script and Web resources
- Clone the Repo
- run
composer install - run
docker-machine startif your docker machine is asleepin' - run
eval $(docker-machine env) - run
docker-compose up -d - Check to make sure all containers are running
- run
chmod +x ./yii - run
chmod +x ./toolbox.sh - run
./toolbox.sh yii migrate - You should be able to make a POST request to
http://192.168.99.199/signup(note: your base url may be different) - Note: You may need to create the
./runtime/cachedirectory if you get a punk ass exception error when making the request - Once you have a user, you can make a POST request to
http://192.168.99.100/loginto login and retrieve a token - Then... idk...
- adminer available at
http://192.168.99.100:8080
Edit the file config/db.php with real data, for example:
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=yii2basic',
'username' => 'root',
'password' => '1234',
'charset' => 'utf8',
];NOTES:
- Yii won't create the database for you, this has to be done manually before you can access it.
- Check and edit the other files in the
config/directory to customize your application as required. - Refer to the README in the
testsdirectory for information specific to basic application tests.
Tests are located in tests directory. They are developed with Codeception PHP Testing Framework.
By default there are 3 test suites:
unitfunctionalacceptance
Tests can be executed by running
vendor/bin/codecept run
The command above will execute unit and functional tests. Unit tests are testing the system components, while functional tests are for testing user interaction. Acceptance tests are disabled by default as they require additional setup since they perform testing in real browser.
To execute acceptance tests do the following:
-
Make sure you have the latest packages installed with
composer install -
chmod +x tests/bin/yii(First time only if needed) -
Login as root and create the test database if it does not yet exist
- Option 1: CLI (TODO)
- Option 2: Adminer
- Navigate to Adminer
- Login with
rootandpassword - Click
SQL Command - Enter
CREATE DATABASE growie_api_test CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; - When that successfully runs, enter
GRANT ALL PRIVILEGES ON growie_api_test.* to 'growie_admin'@'%'
-
Make sure migrations are up to date with
./toolbox.sh yii-test migrateThe database configuration can be found atconfig/test_db.php. -
Codeception can be used with the toolbox:
./toolbox.sh codecept run./toolbox.sh codecept unit-tests./toolbox.sh coverage
# shorthand
./toolbox.sh coverage
#collect coverage for all tests
./toolbox.sh codecept run -- --coverage-html --coverage-xml
#collect coverage only for unit tests
./toolbox.sh codecept run unit -- --coverage-html --coverage-xml
#collect coverage for unit and functional tests
./toolbox.sh codecept run functional,unit -- --coverage-html --coverage-xml
You can see code coverage output under the tests/_output directory.