Yii 2 YarCode Project Template
Yii 2 YarCode Project - is a skeleton Yii 2 application.
In contrast to the yii2-app-advanced this template out of the box has:
- Support for .env file
- API application
- Include yii2-tools-yarcode
- Set of docker containers
- Integration with Travis CI
- Pre-installed AdminLTE theme for the backend application
The minimum requirement by this project template that your Web server supports PHP 7+.
You can then install this project template using the following command:
composer create-project --prefer-dist yarcode/yii2-app-yarcode yarcode сd yarcode php init
Copy .env file
cp .env.example .env
.env and apply migrations. Make sure that you are properly configured to connect to the database.
php yii migrate
The template installation is now complete.
To automatically build and test the application in a template, use Travis CI. The configuration is located in the file
.travis.yml in the project's root directory.
In the configuration file added PHP Coding Standards Fixer.
This tool allows us to automatically check the project code for compliance with standards and rules.
The configuration is in the file
.php_cs in the project's root directory.
Execute the command to verify the code for compliance with the PSR-2 standard
vendor/bin/php-cs-fixer fix -v --dry-run
This template supports Docker technology
Build your containers
docker volume create --name=yiidock_postgres_data
Init and apply migration:
cp docker-compose.override-example.yml docker-compose.override.yml docker-compose run --rm workspace composer install docker-compose run --rm workspace php init docker-compose run --rm yii migrate
Start the containers:
docker-compose up -d
Now app must be working:
- frontend app: http://localhost:8001
- backend app: http://localhost:8002
- api app: http://localhost:8003
You can also start the services individually. Example, start only backend:
docker-compose up -d nginx-backend
Tests are in the test catalogs
They are developed with Codeception PHP Testing Framework. By default there are 2 test suites for each applications(
For more information about testing Yii2 applications, read here
To run tests in a container can be used
Follow these three simple steps:
- Create test volume:
docker volume create --name=test_postgres_data
- Apply migration for test database:
docker-compose -f docker-compose.test.yml run --rm yii_test migrate
- Run all the tests that are in the template:
docker-compose -f docker-compose.test.yml run --rm codeception run
It is possible to run only unit or only functional tests for the application, for example
docker-compose -f docker-compose.test.yml run --rm codeception run unit -c backend docker-compose -f docker-compose.test.yml run --rm codeception run functional -c api
Also you can run some specific test by specifying the path to it
docker-compose -f docker-compose.test.yml run --rm codeception run functional -c api v1/ApiCest
For debugging, it can be convenient to run tests with the flags
docker-compose -f docker-compose.test.yml run --rm codeception run functional -c api v1/ApiCest -f --debug
The root directory contains the following subdirectories and files: