Skip to content

Commit 59615ba

Browse files
committed
[feat] Mock example
1 parent aea5dad commit 59615ba

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
}

0 commit comments

Comments
 (0)