質問編集履歴
5
phpunit.batの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -25,9 +25,6 @@
|
|
25
25
|
C:\MyPhpUnit\phpunit_chap13\srcrestaurant_check.php
|
26
26
|
|
27
27
|
C:\MyPhpUnit\phpunit_chap13\test\RestaurantCheckTest.php
|
28
|
-
C:\MyPhpUnit\phpunit_chap13\vendor
|
29
|
-
C:\MyPhpUnit\phpunit_chap13\composer.json
|
30
|
-
C:\MyPhpUnit\phpunit_chap13\composer.lock
|
31
28
|
C:\MyPhpUnit\phpunit_chap13\phpunit.phar
|
32
29
|
C:\MyPhpUnit\phpunit_chap13\phpunit.cmd
|
33
30
|
|
@@ -75,6 +72,11 @@
|
|
75
72
|
}
|
76
73
|
```
|
77
74
|
|
75
|
+
```.bat
|
76
|
+
// phpunit.cmd
|
77
|
+
@php "%~dp0phpunit.phar" %*
|
78
|
+
```
|
79
|
+
|
78
80
|
```エラー
|
79
81
|
|
80
82
|
hiroko@HIROKO711 C:\MyPhpUnit\phpunit_chap13
|
4
修正する。
title
CHANGED
File without changes
|
body
CHANGED
@@ -53,10 +53,10 @@
|
|
53
53
|
```php
|
54
54
|
|
55
55
|
//RestaurantCheckTest.php
|
56
|
-
include '
|
56
|
+
include 'restaurant_check.php';
|
57
57
|
|
58
58
|
// 引数値の変更
|
59
|
-
class RestaurantCheckTest extends
|
59
|
+
class RestaurantCheckTest extends PHPUnit_Framework_TestCase{
|
60
60
|
|
61
61
|
public function testWithTaxAndTip() {
|
62
62
|
|
3
コード、質問の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,7 +4,6 @@
|
|
4
4
|
RestaurantCheckTest()関数は、restaurant_check()関数をテストする関数です。
|
5
5
|
約1ケ月ぐらいPHPUnitをネットで調べて初歩のテストができるようになったので、
|
6
6
|
参考書に戻ってやってみたのですが、
|
7
|
-
CalculateTest.phpはうまくいったので、見比べながらやってみたのですが
|
8
7
|
どうしても以下のエラーが解決できません。
|
9
8
|
|
10
9
|
XAMPP for Windows 7.4.7
|
@@ -23,25 +22,15 @@
|
|
23
22
|
|
24
23
|
|
25
24
|
ファイルは以下のようになっています。
|
26
|
-
C:\MyPhpUnit\
|
25
|
+
C:\MyPhpUnit\phpunit_chap13\srcrestaurant_check.php
|
27
|
-
C:\MyPhpUnit\OreillyPhpunit\chap13\src\Calculate.php
|
28
|
-
C:\MyPhpUnit\OreillyPhpunit\chap13\test\RestaurantCheckTest.php
|
29
|
-
C:\MyPhpUnit\OreillyPhpunit\chap13\test\CalculateTest.php
|
30
26
|
|
27
|
+
C:\MyPhpUnit\phpunit_chap13\test\RestaurantCheckTest.php
|
28
|
+
C:\MyPhpUnit\phpunit_chap13\vendor
|
29
|
+
C:\MyPhpUnit\phpunit_chap13\composer.json
|
30
|
+
C:\MyPhpUnit\phpunit_chap13\composer.lock
|
31
|
-
C:\MyPhpUnit\
|
31
|
+
C:\MyPhpUnit\phpunit_chap13\phpunit.phar
|
32
|
-
C:\MyPhpUnit\
|
32
|
+
C:\MyPhpUnit\phpunit_chap13\phpunit.cmd
|
33
33
|
|
34
|
-
ちなみに同じフォルダにあるCalculateTest.phpは以下のようにテスト結果が正常に表示されます。
|
35
|
-
hiroko@HIROKO711 C:\MyPhpUnit\OreillyPhpunit\chap13
|
36
|
-
& phpunit test/CalculateTest.php
|
37
|
-
PHPUnit 9.2.5 by Sebastian Bergmann and contributors.
|
38
|
-
|
39
|
-
.
|
40
|
-
|
41
|
-
|
42
|
-
Time: 00:00.003, Memory: 12.00 MB
|
43
|
-
|
44
|
-
OK (1 test, 2 assertions)
|
45
34
|
よろしくお願いいたします。
|
46
35
|
|
47
36
|
```php
|
@@ -77,7 +66,7 @@
|
|
77
66
|
|
78
67
|
$tip = 20 ;
|
79
68
|
|
80
|
-
$result =
|
69
|
+
$result = resturant_check($meal,$tax,$tip);
|
81
70
|
|
82
71
|
$this->assertEquals(130,$result);
|
83
72
|
|
@@ -85,73 +74,24 @@
|
|
85
74
|
|
86
75
|
}
|
87
76
|
```
|
88
|
-
```
|
89
|
-
//Calculate.php
|
90
|
-
<?php
|
91
|
-
// http://refirio.org/view/364
|
92
77
|
|
93
|
-
function multiplication($x, $y) {
|
94
|
-
|
95
|
-
return $x * $y;
|
96
|
-
|
97
|
-
}
|
98
|
-
|
99
|
-
function division($x, $y) {
|
100
|
-
|
101
|
-
return $x / $y;
|
102
|
-
|
103
|
-
}
|
104
|
-
```
|
105
|
-
|
106
|
-
```php
|
107
|
-
//CalculateTest.php
|
108
|
-
<?php
|
109
|
-
//http://refirio.org/view/364
|
110
|
-
|
111
|
-
require_once './src/calculate.php';
|
112
|
-
|
113
|
-
class CalculateTest extends PHPUnit\Framework\TestCase
|
114
|
-
{
|
115
|
-
public function testCalculate()
|
116
|
-
{
|
117
|
-
$this->assertEquals(8, multiplication(4, 2));
|
118
|
-
|
119
|
-
$this->assertEquals(2, division(4, 2));
|
120
|
-
}
|
121
|
-
}
|
122
|
-
```
|
123
|
-
|
124
78
|
```エラー
|
125
79
|
|
126
|
-
hiroko@HIROKO711 C:\MyPhpUnit\
|
80
|
+
hiroko@HIROKO711 C:\MyPhpUnit\phpunit_chap13
|
127
|
-
#
|
81
|
+
# phpunit test\RestaurantCheckTest.php
|
128
|
-
PHP Warning: include(./src/restaurant_check.php): failed to open stream:
|
129
|
-
h file or directory in C:\MyPhpUnit\OreillyPhpunit\chap13\test\RestaurantC
|
130
|
-
st.php on line 2
|
131
|
-
|
132
|
-
Warning: include(./src/restaurant_check.php): failed to open stream: No su
|
133
|
-
e or directory in C:\MyPhpUnit\OreillyPhpunit\chap13\test\RestaurantCheckT
|
134
|
-
p on line 2
|
135
|
-
PHP Warning: include(): Failed opening './src/restaurant_check.php' for i
|
136
|
-
on (include_path='C:\xampp\php\PEAR') in C:\MyPhpUnit\OreillyPhpunit\chap1
|
137
|
-
\RestaurantCheckTest.php on line 2
|
138
|
-
|
139
|
-
Warning: include(): Failed opening './src/restaurant_check.php' for inclus
|
140
|
-
nclude_path='C:\xampp\php\PEAR') in C:\MyPhpUnit\OreillyPhpunit\chap13\tes
|
141
|
-
aurantCheckTest.php on line 2
|
142
82
|
PHPUnit 9.2.5 by Sebastian Bergmann and contributors.
|
143
83
|
|
144
|
-
E
|
84
|
+
E
|
145
85
|
|
146
86
|
|
147
|
-
Time: 00:00.
|
87
|
+
Time: 00:00.001, Memory: 12.00 MB
|
148
88
|
|
149
89
|
There was 1 error:
|
150
90
|
|
151
91
|
1) RestaurantCheckTest::testWithTaxAndTip
|
152
|
-
Error: Call to undefined function
|
92
|
+
Error: Call to undefined function resturant_check()
|
153
93
|
|
154
|
-
C:\MyPhpUnit\
|
94
|
+
C:\MyPhpUnit\phpunit_chap13\test\RestaurantCheckTest.php:15
|
155
95
|
|
156
96
|
ERRORS!
|
157
97
|
Tests: 1, Assertions: 0, Errors: 1.
|
2
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
|
34
34
|
ちなみに同じフォルダにあるCalculateTest.phpは以下のようにテスト結果が正常に表示されます。
|
35
35
|
hiroko@HIROKO711 C:\MyPhpUnit\OreillyPhpunit\chap13
|
36
|
-
|
36
|
+
& phpunit test/CalculateTest.php
|
37
37
|
PHPUnit 9.2.5 by Sebastian Bergmann and contributors.
|
38
38
|
|
39
39
|
.
|
1
コードの修正と追加、エラーの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,11 +2,15 @@
|
|
2
2
|
restaurant_check()関数は、料理の値段、税率、チップ率を指定すると、レストランの
|
3
3
|
料理の総額を計算します。
|
4
4
|
RestaurantCheckTest()関数は、restaurant_check()関数をテストする関数です。
|
5
|
+
約1ケ月ぐらいPHPUnitをネットで調べて初歩のテストができるようになったので、
|
6
|
+
参考書に戻ってやってみたのですが、
|
7
|
+
CalculateTest.phpはうまくいったので、見比べながらやってみたのですが
|
8
|
+
どうしても以下のエラーが解決できません。
|
5
9
|
|
6
|
-
XAMPP for Windows 7.4.
|
10
|
+
XAMPP for Windows 7.4.7
|
7
11
|
|
8
12
|
> php -v
|
9
|
-
PHP 7.4.
|
13
|
+
PHP 7.4.7 (cli) (built: May 12 2020 11:38:54) ( ZTS Visual C++ 2017 x64 )
|
10
14
|
Copyright (c) The PHP Group
|
11
15
|
Zend Engine v3.4.0, Copyright (c) Zend Technologies
|
12
16
|
|
@@ -15,26 +19,29 @@
|
|
15
19
|
Apache Lounge VC15 Server built: Apr 22 2020 11:11:00
|
16
20
|
|
17
21
|
>phpunit -v
|
18
|
-
PHPUnit 9.2.
|
22
|
+
PHPUnit 9.2.5 by Sebastian Bergmann and contributors.
|
19
23
|
|
20
24
|
|
21
25
|
ファイルは以下のようになっています。
|
26
|
+
C:\MyPhpUnit\OreillyPhpunit\chap13\ restaurant_check.php
|
22
|
-
C:\
|
27
|
+
C:\MyPhpUnit\OreillyPhpunit\chap13\src\Calculate.php
|
28
|
+
C:\MyPhpUnit\OreillyPhpunit\chap13\test\RestaurantCheckTest.php
|
29
|
+
C:\MyPhpUnit\OreillyPhpunit\chap13\test\CalculateTest.php
|
23
30
|
|
24
|
-
C:\xampp\php\phpunit_test\restaurant_check.php
|
25
|
-
C:\
|
31
|
+
C:\MyPhpUnit\OreillyPhpunit\chap13\phpunit.phar
|
32
|
+
C:\MyPhpUnit\OreillyPhpunit\chap13\phpunit.cmd
|
26
33
|
|
27
|
-
ちなみに同じフォルダにある
|
34
|
+
ちなみに同じフォルダにあるCalculateTest.phpは以下のようにテスト結果が正常に表示されます。
|
28
|
-
hiroko@HIROKO711
|
35
|
+
hiroko@HIROKO711 C:\MyPhpUnit\OreillyPhpunit\chap13
|
29
|
-
|
36
|
+
# phpunit test/CalculateTest.php
|
30
|
-
PHPUnit 9.2.
|
37
|
+
PHPUnit 9.2.5 by Sebastian Bergmann and contributors.
|
31
38
|
|
32
39
|
.
|
33
40
|
|
34
41
|
|
35
42
|
Time: 00:00.003, Memory: 12.00 MB
|
36
43
|
|
37
|
-
OK (1 test,
|
44
|
+
OK (1 test, 2 assertions)
|
38
45
|
よろしくお願いいたします。
|
39
46
|
|
40
47
|
```php
|
@@ -57,8 +64,7 @@
|
|
57
64
|
```php
|
58
65
|
|
59
66
|
//RestaurantCheckTest.php
|
60
|
-
<?php
|
61
|
-
|
67
|
+
include './src/restaurant_check.php';
|
62
68
|
|
63
69
|
// 引数値の変更
|
64
70
|
class RestaurantCheckTest extends PHPUnit\Framework\TestCase{
|
@@ -78,53 +84,74 @@
|
|
78
84
|
}
|
79
85
|
|
80
86
|
}
|
87
|
+
```
|
88
|
+
```
|
89
|
+
//Calculate.php
|
81
|
-
?
|
90
|
+
<?php
|
91
|
+
// http://refirio.org/view/364
|
82
92
|
|
93
|
+
function multiplication($x, $y) {
|
94
|
+
|
95
|
+
return $x * $y;
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
function division($x, $y) {
|
100
|
+
|
101
|
+
return $x / $y;
|
102
|
+
|
103
|
+
}
|
83
104
|
```
|
105
|
+
|
84
106
|
```php
|
85
|
-
//
|
107
|
+
//CalculateTest.php
|
86
108
|
<?php
|
87
|
-
|
109
|
+
//http://refirio.org/view/364
|
88
|
-
|
89
|
-
public function testEqual() {
|
90
110
|
|
111
|
+
require_once './src/calculate.php';
|
112
|
+
|
113
|
+
class CalculateTest extends PHPUnit\Framework\TestCase
|
114
|
+
{
|
115
|
+
public function testCalculate()
|
116
|
+
{
|
117
|
+
$this->assertEquals(8, multiplication(4, 2));
|
118
|
+
|
91
|
-
|
119
|
+
$this->assertEquals(2, division(4, 2));
|
92
|
-
|
120
|
+
}
|
93
|
-
|
121
|
+
}
|
94
|
-
?>
|
95
122
|
```
|
96
123
|
|
97
124
|
```エラー
|
98
125
|
|
99
|
-
hiroko@HIROKO711
|
126
|
+
hiroko@HIROKO711 C:\MyPhpUnit\OreillyPhpunit\chap13
|
100
|
-
#
|
127
|
+
# phpunit test/RestaurantCheckTest.php
|
101
|
-
PHP Warning: include(
|
128
|
+
PHP Warning: include(./src/restaurant_check.php): failed to open stream:
|
102
|
-
|
129
|
+
h file or directory in C:\MyPhpUnit\OreillyPhpunit\chap13\test\RestaurantC
|
103
|
-
|
130
|
+
st.php on line 2
|
104
131
|
|
105
|
-
Warning: include(
|
132
|
+
Warning: include(./src/restaurant_check.php): failed to open stream: No su
|
106
|
-
|
133
|
+
e or directory in C:\MyPhpUnit\OreillyPhpunit\chap13\test\RestaurantCheckT
|
107
|
-
|
134
|
+
p on line 2
|
108
|
-
PHP Warning: include(): Failed opening '
|
135
|
+
PHP Warning: include(): Failed opening './src/restaurant_check.php' for i
|
109
|
-
|
136
|
+
on (include_path='C:\xampp\php\PEAR') in C:\MyPhpUnit\OreillyPhpunit\chap1
|
110
|
-
|
137
|
+
\RestaurantCheckTest.php on line 2
|
111
138
|
|
112
|
-
Warning: include(): Failed opening '
|
139
|
+
Warning: include(): Failed opening './src/restaurant_check.php' for inclus
|
113
|
-
|
140
|
+
nclude_path='C:\xampp\php\PEAR') in C:\MyPhpUnit\OreillyPhpunit\chap13\tes
|
114
|
-
|
141
|
+
aurantCheckTest.php on line 2
|
115
|
-
PHPUnit 9.2.
|
142
|
+
PHPUnit 9.2.5 by Sebastian Bergmann and contributors.
|
116
143
|
|
117
144
|
E 1 / 1
|
118
145
|
|
119
146
|
|
120
|
-
Time: 00:00.
|
147
|
+
Time: 00:00.003, Memory: 12.00 MB
|
121
148
|
|
122
149
|
There was 1 error:
|
123
150
|
|
124
151
|
1) RestaurantCheckTest::testWithTaxAndTip
|
125
152
|
Error: Call to undefined function restaurant_check()
|
126
153
|
|
127
|
-
C:\
|
154
|
+
C:\MyPhpUnit\OreillyPhpunit\chap13\test\RestaurantCheckTest.php:15
|
128
155
|
|
129
156
|
ERRORS!
|
130
157
|
Tests: 1, Assertions: 0, Errors: 1.
|