File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
samplecode/phpunit-example Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ class HttpCommunication
4
+ {
5
+ public function communicate (): int
6
+ {
7
+ $ status_code = 200 ; // ダミーの値
8
+ echo "HTTP通信をしています... \n" ;
9
+ return $ status_code ;
10
+ }
11
+ }
12
+
13
+ function foo (HttpCommunication $ communication ): void
14
+ {
15
+ echo "foo start \n" ;
16
+
17
+ $ status_code = $ communication ->communicate ();
18
+
19
+ echo "foo end \n" ;
20
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ use PHPUnit \Framework \TestCase ;
3
+
4
+ require_once __DIR__ . "/../src/mockExample.php " ;
5
+
6
+ class MockExampleTest extends TestCase
7
+ {
8
+ public function test_モックを使うテストの例 (): void
9
+ {
10
+ $ mocked_communication = $ this ->createMock (HttpCommunication::class);
11
+ $ mocked_communication ->expects ($ this ->once ())
12
+ ->method ("communicate " )
13
+ ->with ()
14
+ ->willReturn (200 );
15
+
16
+ foo ($ mocked_communication );
17
+ }
18
+ }
You can’t perform that action at this time.
0 commit comments