Permalink
Browse files

[單元測試] ShippingService 使用 Closure::call()

  • Loading branch information...
1 parent 17f65ca commit 89bdc1540df918a362a4acf3dedbc523fd174add Sam.IO.Hsiao committed Nov 20, 2016
Showing with 25 additions and 0 deletions.
  1. +25 −0 tests/ShippingServiceTest.php
@@ -0,0 +1,25 @@
+<?php
+
+use App\Services\ShippingService;
+
+class ShippingServiceTest extends TestCase
+{
+ /** @test */
+ public function 當重量為1kg時費用為110元()
+ {
+ /** arrange */
+ $target = App::make(ShippingService::class);
+
+ $__calculateFee = function (int $weight) {
+ return $this->calculateFee($weight);
+ };
+
+ /** act */
+ $weight = 1;
+ $actual = $__calculateFee->call($target, $weight);
+
+ /** assert */
+ $expected = 110;
+ $this->assertEquals($expected, $actual);
+ }
+}

0 comments on commit 89bdc15

Please sign in to comment.