Learn Test Driven Development with Laravel!
Reset Uninstall docker desktop Start-> Settings-> App (usually disappears) When I try to turn it off normally with explorer, a blue screen appears and it restarts, and I can't turn it off forever (I've never seen a blue screen in this era ...). It seems that there is no choice but to snap it off in powershell administrator mode
learning-laravel-Based on a directory called tdd
PS C:\WINDOWS\system32> cd D:\OneDrive\dev
PS D:\OneDrive\dev> rm -Force learning-laravel-tdd
https://hub.docker.com/editions/community/docker-ce-desktop-windows/ The installation itself goes smoothly
OneDrive\dev>
$ mkdir learning-laravel-tdd
$ cd learning-laravel-tdd
$ git clone https://github.com/nunulk/learning-laravel-tdd-docker docker
$ mkdir app
learning-laravel-tdd
├── app
└── docker
Do it after starting Docker
$ cd docker
$ cp .env.example .env
$ docker-compose up -d
In my case, I found that 3306 was on (because I usually use it in python)
learning-laravel-tdd\docker\.env
COMPOSE_PROJECT_NAME=learning-laravel-tdd
APP_PATH=../app
TZ=Asia/Tokyo
WEB_PORT=80
- DB_PORT=3306
+ DB_PORT=3308
DB_DATABASE=learning_laravel_tdd
DB_USERNAME=root
DB_PASSWORD=root
DB_TESTING_DATABASE=learning_laravel_tdd_testing
DB_TESTING_PORT=3307
DB_TESTING_USERNAME=root
DB_TESTING_PASSWORD=root
Then, when you start with Docker's control panel, everything will be turned on
Execute the following command to check if all containers are running
learning-laravel-tdd\docker>
$ docker-compose ps
Name Command State Ports
-------------------------------------------------------------------------------------------------------------
learning-laravel-tdd_app_1 docker-php-entrypoint php-fpm Up 9000/tcp
learning-laravel-tdd_db-testing_1 docker-entrypoint.sh mysqld Up 0.0.0.0:3307->3306/tcp, 33060/tcp
learning-laravel-tdd_db_1 docker-entrypoint.sh mysqld Up 0.0.0.0:3308->3306/tcp, 33060/tcp
learning-laravel-tdd_web_1 nginx -g daemon off; Up 0.0.0.0:80->80/tcp
learning-laravel-tdd\docker>
$ docker exec -it learning-laravel-tdd_app_1 ash
# composer create-project --prefer-dist "laravel/laravel=7.*" .
learning-laravel-tdd\app\.env
#Omission
LOG_CHANNEL=stack
- DB_CONNECTION=mysql
- DB_HOST=127.0.0.1
- DB_PORT=3306
- DB_DATABASE=laravel
- DB_USERNAME=root
- DB_PASSWORD=
+ DB_CONNECTION=mysql
+ DB_HOST=db
+ DB_PORT=3306
+ DB_DATABASE=learning_laravel_tdd
+ DB_USERNAME=root
+ DB_PASSWORD=root
+ DB_TESTING_HOST=db-testing
+ DB_TESTING_PORT=3306
+ DB_TESTING_DATABASE=learning_laravel_tdd_testing
+ DB_TESTING_USERNAME=root
+ DB_TESTING_PASSWORD=root
BROADCAST_DRIVER=log
#Omission
learning-laravel-tdd\app\config\database.php
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
- 'port' => env('DB_PORT', '3306'),
+ 'port' => env('DB_PORT', '3308'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
+ 'mysql_testing' => [
+ 'driver' => 'mysql',
+ 'host' => env('DB_TESTING_HOST', '127.0.0.1'),
+ 'port' => env('DB_TESTING_PORT', '3307'),
+ 'database' => env('DB_TESTING_DATABASE', 'forge'),
+ 'username' => env('DB_TESTING_USERNAME', 'forge'),
+ 'password' => env('DB_TESTING_PASSWORD', ''),
+ 'unix_socket' => env('DB_SOCKET', ''),
+ 'charset' => 'utf8mb4',
+ 'collation' => 'utf8mb4_unicode_ci',
+ 'prefix' => '',
+ 'prefix_indexes' => true,
+ 'strict' => true,
+ 'engine' => null,
+ 'options' => extension_loaded('pdo_mysql') ? array_filter([
+ PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
+ ]) : [],
+ ],
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DATABASE_URL'),
learning-laravel-tdd\app\phpunit.xml
<server name="CACHE_DRIVER" value="array"/>
- <!-- <server name="DB_CONNECTION" value="sqlite"/> -->
- <!-- <server name="DB_DATABASE" value=":memory:"/> -->
+ <server name="DB_CONNECTION" value="mysql_testing"/>
+ <server name="DB_DATABASE" value="learning_laravel_tdd_testing"/>
<server name="MAIL_MAILER" value="array"/>
By default, Laravel will generate the Model class directly under the app directory when you generate it with the artisan command, but in this teaching material, we will create a Models directory and place it there. Move User.php, which is automatically created by the installation, to the Models directory in advance.
First, execute the following command to create a directory (either the container side or the host side is fine).
learning-laravel-tdd\app
# mkdir app/Models
Then move app/User.php under app/Models and change the namespace.
learning-laravel-tdd\app\Models\User.php
namespace App\Models;
Also change the namespace of the part that refers to the User class.
The following two files are to be changed.
learning-laravel-tdd\app\config\auth.php
'providers' => [
'users' => [
'driver' => 'eloquent',
- 'model' => App\User::class,
+ 'model' => App\Models\User::class,
],
learning-laravel-tdd\app\database\factories\UserFactory.php
- use App\User;
+ use App\Models\User;
config is ignored
Make learning-laravel-tdd \ docker \ db \ my.cnf
read-only
It seems to be a problem only for Windows
mysqld: [Warning] World-writable config file'/etc/mysql/my.cnf' is ignored. [Docker + Windows] What to do if the docker image of mysql does not start due to a mount error of my.cnf
Finally, run the following command inside the container to see if the application works.
/app # php artisan migrate
Recommended Posts