質問編集履歴

13

2024/04/18 09:53

投稿

iridescence
iridescence

スコア1

test CHANGED
File without changes
test CHANGED
@@ -15,10 +15,7 @@
15
15
  ```
16
16
  SQLSTATE[HY000] [1044] Access denied for user 'sail'@'%' to database 'testing' (Connection: mysql, SQL: select table_name as `name`, (data_length + index_length) as `size`, table_comment as `comment`, engine as `engine`, table_collation as `collation` from information_schema.tables where table_schema = 'testing' and table_type in ('BASE TABLE', 'SYSTEM VERSIONED') order by table_name)
17
17
  ```
18
- sailにアクセス権限を与えたら以下のエラー文に変わりました。
19
- ```
20
- SQLSTATE[HY000] [2002] Connection refused (Connection: mysql, SQL: select table_name as `name`, (data_length + index_length) as `size`, table_comment as `comment`, engine as `engine`, table_collation as `collation` from information_schema.tables where table_schema = 'testing' and table_type in ('BASE TABLE', 'SYSTEM VERSIONED') order by table_name)
21
- ```
18
+
22
19
 
23
20
  ### 該当のソースコード
24
21
 

12

エラー文変更

2024/04/18 09:31

投稿

iridescence
iridescence

スコア1

test CHANGED
File without changes
test CHANGED
@@ -11,24 +11,13 @@
11
11
  sail test tests/Feature/Tweet/DeleteTest.php
12
12
  ```
13
13
  ### エラーメッセージ
14
- ```error
15
- SQLSTATE[42S01]: Base table or view already exists: 1050 Table
16
- ```
17
- dockerボリューム削除からのコンテナ作成し起動、phpunit.xml,docker-compose.ymlの修正を行ったところ以下のエラーに変わりました。↓
18
- ```error
19
- PHPUnit 11.1.1 by Sebastian Bergmann and contributors.
20
14
 
21
- Could not load "/var/www/html/phpunit.xml":
22
-
23
- Opening and ending tag mismatch: env line 26 and php
24
-
25
- Opening and ending tag mismatch: php line 20 and phpunit
26
-
27
- Premature end of data in tag phpunit line 2
28
- ```
29
- phpunit.xmlにて閉じタグの前に/が抜けていました。以下のエラー文に変わりました。
30
15
  ```
31
16
  SQLSTATE[HY000] [1044] Access denied for user 'sail'@'%' to database 'testing' (Connection: mysql, SQL: select table_name as `name`, (data_length + index_length) as `size`, table_comment as `comment`, engine as `engine`, table_collation as `collation` from information_schema.tables where table_schema = 'testing' and table_type in ('BASE TABLE', 'SYSTEM VERSIONED') order by table_name)
17
+ ```
18
+ sailにアクセス権限を与えたら以下のエラー文に変わりました。
19
+ ```
20
+ SQLSTATE[HY000] [2002] Connection refused (Connection: mysql, SQL: select table_name as `name`, (data_length + index_length) as `size`, table_comment as `comment`, engine as `engine`, table_collation as `collation` from information_schema.tables where table_schema = 'testing' and table_type in ('BASE TABLE', 'SYSTEM VERSIONED') order by table_name)
32
21
  ```
33
22
 
34
23
  ### 該当のソースコード
@@ -153,13 +142,7 @@
153
142
  ```
154
143
  sail artisan migrate:fresh
155
144
  ```
156
-
157
- ```
158
- SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'tweet_images' already exists (Connection: mysql, SQL: create table `tweet_images` (`tweet_Id` bigint unsigned not null, `image_Id` bigint unsigned not null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')
159
- ```
160
- ・.env.testingファイルを削除したところ下記エラーに変わった
161
- ```.env.testing
162
- SQLSTATE[HY000] [1044] Access denied for user 'sail'@'%' to database 'testing' (Connection: mysql, SQL: select table_name as `name`, (data_length + index_length) as `size`, table_comment as `comment`, engine as `engine`, table_collation as `collation` from information_schema.tables where table_schema = 'testing' and table_type in ('BASE TABLE', 'SYSTEM VERSIONED') order by table_name)
163
- ```
145
+ ・.env.testingは不要とのことだったので削除しました
164
146
 
165
147
 
148
+

11

<env name="DB_HOST" value="mysql.test"/> /が抜けてた

2024/04/18 08:30

投稿

iridescence
iridescence

スコア1

test CHANGED
File without changes
test CHANGED
@@ -127,7 +127,7 @@
127
127
  <env name="BCRYPT_ROUNDS" value="4"/>
128
128
  <env name="CACHE_STORE" value="array"/>
129
129
  <env name="DB_DATABASE" value="testing"/>
130
- <env name="DB_HOST" value="mysql.test">
130
+ <env name="DB_HOST" value="mysql.test"/>
131
131
  <env name="MAIL_MAILER" value="array"/>
132
132
  <env name="PULSE_ENABLED" value="false"/>
133
133
  <env name="QUEUE_CONNECTION" value="sync"/>

10

ファイル名間違えた

2024/04/18 08:27

投稿

iridescence
iridescence

スコア1

test CHANGED
File without changes
test CHANGED
@@ -33,7 +33,7 @@
33
33
 
34
34
  ### 該当のソースコード
35
35
 
36
- ```Delete.php
36
+ ```DeleteTest.php
37
37
  <?php
38
38
 
39
39
  namespace Tests\Feature\Tweet;

9

コマンドの追記

2024/04/18 08:20

投稿

iridescence
iridescence

スコア1

test CHANGED
File without changes
test CHANGED
@@ -6,7 +6,10 @@
6
6
 
7
7
  ### 発生している問題・分からないこと
8
8
  メッセージ削除機能のFeatureテストでエラーが発生しています。
9
-
9
+ 打ったコマンド
10
+ ```
11
+ sail test tests/Feature/Tweet/DeleteTest.php
12
+ ```
10
13
  ### エラーメッセージ
11
14
  ```error
12
15
  SQLSTATE[42S01]: Base table or view already exists: 1050 Table

8

エラー文変更

2024/04/18 08:13

投稿

iridescence
iridescence

スコア1

test CHANGED
File without changes
test CHANGED
@@ -22,6 +22,10 @@
22
22
  Opening and ending tag mismatch: php line 20 and phpunit
23
23
 
24
24
  Premature end of data in tag phpunit line 2
25
+ ```
26
+ phpunit.xmlにて閉じタグの前に/が抜けていました。以下のエラー文に変わりました。
27
+ ```
28
+ SQLSTATE[HY000] [1044] Access denied for user 'sail'@'%' to database 'testing' (Connection: mysql, SQL: select table_name as `name`, (data_length + index_length) as `size`, table_comment as `comment`, engine as `engine`, table_collation as `collation` from information_schema.tables where table_schema = 'testing' and table_type in ('BASE TABLE', 'SYSTEM VERSIONED') order by table_name)
25
29
  ```
26
30
 
27
31
  ### 該当のソースコード
@@ -152,15 +156,7 @@
152
156
  ```
153
157
  ・.env.testingファイルを削除したところ下記エラーに変わった
154
158
  ```.env.testing
155
- PHPUnit 11.1.1 by Sebastian Bergmann and contributors.
156
-
157
- Could not load "/var/www/html/phpunit.xml":
158
-
159
- Opening and ending tag mismatch: env line 26 and php
160
-
161
- Opening and ending tag mismatch: php line 20 and phpunit
162
-
163
- Premature end of data in tag phpunit line 2
159
+ SQLSTATE[HY000] [1044] Access denied for user 'sail'@'%' to database 'testing' (Connection: mysql, SQL: select table_name as `name`, (data_length + index_length) as `size`, table_comment as `comment`, engine as `engine`, table_collation as `collation` from information_schema.tables where table_schema = 'testing' and table_type in ('BASE TABLE', 'SYSTEM VERSIONED') order by table_name)
164
160
  ```
165
161
 
166
162
 

7

エラー文変更

2024/04/18 07:43

投稿

iridescence
iridescence

スコア1

test CHANGED
File without changes
test CHANGED
@@ -150,6 +150,17 @@
150
150
  ```
151
151
  SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'tweet_images' already exists (Connection: mysql, SQL: create table `tweet_images` (`tweet_Id` bigint unsigned not null, `image_Id` bigint unsigned not null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')
152
152
  ```
153
+ ・.env.testingファイルを削除したところ下記エラーに変わった
154
+ ```.env.testing
155
+ PHPUnit 11.1.1 by Sebastian Bergmann and contributors.
156
+
157
+ Could not load "/var/www/html/phpunit.xml":
158
+
159
+ Opening and ending tag mismatch: env line 26 and php
160
+
161
+ Opening and ending tag mismatch: php line 20 and phpunit
162
+
153
- データベースへのアクセスはできたが、データベースの初期化ができていないのかもしれない
163
+ Premature end of data in tag phpunit line 2
164
+ ```
154
165
 
155
166
 

6

エラー文追記

2024/04/18 07:32

投稿

iridescence
iridescence

スコア1

test CHANGED
File without changes
test CHANGED
@@ -142,7 +142,14 @@
142
142
  ・テストDB用のキーを作成する
143
143
  ・docker-compose.ymlにテスト用の環境変数を追記
144
144
  ・phpunit.xmlでDB_HOSTの項目をmysql.testに変更
145
+ ・↓回答者の方から共有していただいた記事を参考にコマンドを実行
146
+ ```
147
+ sail artisan migrate:fresh
148
+ ```
145
149
 
150
+ ```
151
+ SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'tweet_images' already exists (Connection: mysql, SQL: create table `tweet_images` (`tweet_Id` bigint unsigned not null, `image_Id` bigint unsigned not null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')
152
+ ```
146
153
  データベースへのアクセスはできたが、データベースの初期化ができていないのかもしれない
147
154
 
148
155
 

5

エラーメッセージの変更

2024/04/18 07:20

投稿

iridescence
iridescence

スコア1

test CHANGED
File without changes
test CHANGED
@@ -10,6 +10,18 @@
10
10
  ### エラーメッセージ
11
11
  ```error
12
12
  SQLSTATE[42S01]: Base table or view already exists: 1050 Table
13
+ ```
14
+ dockerボリューム削除からのコンテナ作成し起動、phpunit.xml,docker-compose.ymlの修正を行ったところ以下のエラーに変わりました。↓
15
+ ```error
16
+ PHPUnit 11.1.1 by Sebastian Bergmann and contributors.
17
+
18
+ Could not load "/var/www/html/phpunit.xml":
19
+
20
+ Opening and ending tag mismatch: env line 26 and php
21
+
22
+ Opening and ending tag mismatch: php line 20 and phpunit
23
+
24
+ Premature end of data in tag phpunit line 2
13
25
  ```
14
26
 
15
27
  ### 該当のソースコード

4

docker-compose.ymlとphpunitを追加

2024/04/18 07:13

投稿

iridescence
iridescence

スコア1

test CHANGED
File without changes
test CHANGED
@@ -57,6 +57,66 @@
57
57
 
58
58
  //以下省略
59
59
  ```
60
+ ↓docker-compose.yml(-が反映しないためドットで対応)
61
+
62
+ ```docker.compose.yml
63
+ #追記した部分
64
+ mysql.test:
65
+ image: 'mysql/mysql-server:8.0'
66
+ environment:
67
+ MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
68
+ MYSQL_ROOT_HOST: '%'
69
+ MYSQL_DATABASE: '${DB_DATABASE}'
70
+ MYSQL_USER: '${DB_USERNAME}'
71
+ MYSQL_PASSWORD: '${DB_PASSWORD}'
72
+ MYSQL_ALLOW_EMPTY_PASSWORD: 1
73
+ networks:
74
+ - sail
75
+ healthcheck:
76
+ test:
77
+ - CMD
78
+ - mysqladmin
79
+ - ping
80
+ - '-p${DB_PASSWORD}'
81
+ retries: 3
82
+ timeout: 5s
83
+ ```
84
+
85
+ ```phpunit.xml
86
+ <?xml version="1.0" encoding="UTF-8"?>
87
+ <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
88
+ xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
89
+ bootstrap="vendor/autoload.php"
90
+ colors="true"
91
+ >
92
+ <testsuites>
93
+ <testsuite name="Unit">
94
+ <directory>tests/Unit</directory>
95
+ </testsuite>
96
+ <testsuite name="Feature">
97
+ <directory>tests/Feature</directory>
98
+ </testsuite>
99
+ </testsuites>
100
+ <source>
101
+ <include>
102
+ <directory>app</directory>
103
+ </include>
104
+ </source>
105
+ <php>
106
+ <env name="APP_ENV" value="testing"/>
107
+ <env name="APP_MAINTENANCE_DRIVER" value="file"/>
108
+ <env name="BCRYPT_ROUNDS" value="4"/>
109
+ <env name="CACHE_STORE" value="array"/>
110
+ <env name="DB_DATABASE" value="testing"/>
111
+ <env name="DB_HOST" value="mysql.test">
112
+ <env name="MAIL_MAILER" value="array"/>
113
+ <env name="PULSE_ENABLED" value="false"/>
114
+ <env name="QUEUE_CONNECTION" value="sync"/>
115
+ <env name="SESSION_DRIVER" value="array"/>
116
+ <env name="TELESCOPE_ENABLED" value="false"/>
117
+ </php>
118
+ </phpunit>
119
+ ```
60
120
 
61
121
  ### 試したこと・調べたこと
62
122
  - [x] teratailやGoogle等で検索した
@@ -65,9 +125,11 @@
65
125
  - [ ] その他
66
126
 
67
127
  ##### 上記の詳細・結果
68
- .envをコピーして .env.testingを作成する。
128
+ .envをコピーして .env.testingを作成する。
69
- .env.testingにて、DB_DATABASE=testingに変更
129
+ .env.testingにて、DB_DATABASE=testingに変更
70
- テストDB用のキーを作成する
130
+ テストDB用のキーを作成する
131
+ ・docker-compose.ymlにテスト用の環境変数を追記
132
+ ・phpunit.xmlでDB_HOSTの項目をmysql.testに変更
71
133
 
72
134
  データベースへのアクセスはできたが、データベースの初期化ができていないのかもしれない
73
135
 

3

ファイル名間違えた

2024/04/18 05:45

投稿

iridescence
iridescence

スコア1

test CHANGED
File without changes
test CHANGED
@@ -66,7 +66,7 @@
66
66
 
67
67
  ##### 上記の詳細・結果
68
68
  .envをコピーして .env.testingを作成する。
69
- .envにて、DB_DATABASE=testingに変更
69
+ .env.testingにて、DB_DATABASE=testingに変更
70
70
  テストDB用のキーを作成する
71
71
 
72
72
  データベースへのアクセスはできたが、データベースの初期化ができていないのかもしれない

2

ファイル名間違えていたので変更した。

2024/04/18 05:31

投稿

iridescence
iridescence

スコア1

test CHANGED
File without changes
test CHANGED
@@ -45,27 +45,8 @@
45
45
  }
46
46
  ```
47
47
 
48
- ```.env
48
+ ```.env.testing
49
- APP_NAME=Laravel
50
- APP_ENV=local
51
- APP_KEY=base64:IAqlWv5TsWd+eY3nlg9CXLwulSs0ggi7XIJlo46FJQU=
52
- APP_DEBUG=true
53
- APP_TIMEZONE=Asia/Tokyo
54
- APP_URL=http://localhost
49
+ //省略
55
-
56
- APP_LOCALE=ja
57
- APP_FALLBACK_LOCALE=ja
58
- APP_FAKER_LOCALE=ja_JP
59
-
60
- APP_MAINTENANCE_DRIVER=file
61
- APP_MAINTENANCE_STORE=database
62
-
63
- BCRYPT_ROUNDS=12
64
-
65
- LOG_CHANNEL=stack
66
- LOG_STACK=single
67
- LOG_DEPRECATIONS_CHANNEL=null
68
- LOG_LEVEL=debug
69
50
 
70
51
  DB_CONNECTION=mysql
71
52
  DB_HOST=mysql
@@ -74,48 +55,7 @@
74
55
  DB_USERNAME=sail
75
56
  DB_PASSWORD=password
76
57
 
77
- SESSION_DRIVER=file
78
- SESSION_LIFETIME=120
79
- SESSION_ENCRYPT=false
80
- SESSION_PATH=/
58
+ //以下省略
81
- SESSION_DOMAIN=null
82
-
83
- BROADCAST_CONNECTION=log
84
- FILESYSTEM_DISK=local
85
- QUEUE_CONNECTION=database
86
-
87
- CACHE_STORE=database
88
- CACHE_PREFIX=
89
-
90
- MEMCACHED_HOST=127.0.0.1
91
-
92
- REDIS_CLIENT=phpredis
93
- REDIS_HOST=redis
94
- REDIS_PASSWORD=null
95
- REDIS_PORT=6379
96
-
97
- MAIL_MAILER=smtp
98
- MAIL_HOST=mailpit
99
- MAIL_PORT=1025
100
- MAIL_USERNAME=null
101
- MAIL_PASSWORD=null
102
- MAIL_ENCRYPTION=null
103
- MAIL_FROM_ADDRESS="hello@example.com"
104
- MAIL_FROM_NAME="hello"
105
-
106
- AWS_ACCESS_KEY_ID=
107
- AWS_SECRET_ACCESS_KEY=
108
- AWS_DEFAULT_REGION=us-east-1
109
- AWS_BUCKET=
110
- AWS_USE_PATH_STYLE_ENDPOINT=false
111
-
112
- VITE_APP_NAME="${APP_NAME}"
113
-
114
- SCOUT_DRIVER=meilisearch
115
- MEILISEARCH_HOST=http://meilisearch:7700
116
-
117
- MEILISEARCH_NO_ANALYTICS=false
118
-
119
59
  ```
120
60
 
121
61
  ### 試したこと・調べたこと
@@ -131,6 +71,4 @@
131
71
 
132
72
  データベースへのアクセスはできたが、データベースの初期化ができていないのかもしれない
133
73
 
134
- ### 補足
135
74
 
136
- データベースへのアクセスはできたが、データベースの初期化ができていないのかもしれない

1

タイトルを変更しました

2024/04/18 05:20

投稿

iridescence
iridescence

スコア1

test CHANGED
@@ -1 +1 @@
1
- phpunitでエラーが起こる
1
+ phpunitでタベースの初期化できていないかもしれない
test CHANGED
@@ -5,7 +5,7 @@
5
5
  PHPUnit バージョン12
6
6
 
7
7
  ### 発生している問題・分からないこと
8
- メッセージ投稿機能のFeatureテストでエラーが発生しています。
8
+ メッセージ削除機能のFeatureテストでエラーが発生しています。
9
9
 
10
10
  ### エラーメッセージ
11
11
  ```error