Permalink
Browse files

[單元測試] ShippingService 使用 interface

1 parent 64bbe41 commit 9bfce794d885ece5547b475b547e232aeda6bac9 Sam.IO.Hsiao committed Nov 18, 2016
Showing with 33 additions and 0 deletions.
  1. +33 −0 tests/ShippingServiceTest.php
@@ -0,0 +1,33 @@
+<?php
+
+declare(strict_types = 1);
+
+use App\Services\BlackCat;
+use App\Services\LogisticsInterface;
+use App\Services\ShippingService;
+
+class ShippingServiceTest extends TestCase
+{
+ /** @test */
+ public function 黑貓單元測試()
+ {
+ /** arrange */
+ $mock = $this->createMock(BlackCat::class);
+ $mock->expects($this->once())
+ ->method('calculateFee')
+ ->withAnyParameters()
+ ->willReturn(110);
+
+ App::instance(LogisticsInterface::class, $mock);
+
+ /** act */
+ $weight = 1;
+ $actual = App::call(ShippingService::class . '@calculateFee', [
+ 'weight' => $weight,
+ ]);
+
+ /** assert */
+ $expected = 110;
+ $this->assertEquals($expected, $actual);
+ }
+}

0 comments on commit 9bfce79

Please sign in to comment.