Permalink
Browse files

[單元測試] ShippingService 使用 closure

  • Loading branch information...
1 parent fb691e1 commit 9a1347a16940686651b8333d3fad1a0a0a1ea9e7 Sam.IO.Hsiao committed Nov 18, 2016
Showing with 5 additions and 24 deletions.
  1. +5 −24 tests/ShippingServiceTest.php
@@ -2,8 +2,6 @@
declare(strict_types = 1);
-use App\Services\BlackCat;
-use App\Services\LogisticsInterface;
use App\Services\ShippingService;
class ShippingServiceTest extends TestCase
@@ -12,35 +10,18 @@ class ShippingServiceTest extends TestCase
public function 黑貓單元測試()
{
/** arrange */
- $mock = $this->createMock(BlackCat::class);
+ $mock = $this->createPartialMock(stdClass::class, ['__invoke']);
+
$mock->expects($this->once())
- ->method('calculateFee')
+ ->method('__invoke')
->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);
- }
-
- /** @test */
- public function 黑貓整合測試()
- {
- /** arrange */
- App::bind(LogisticsInterface::class, BlackCat::class);
-
/** act */
$weight = 1;
$actual = App::call(ShippingService::class . '@calculateFee', [
- 'weight' => $weight,
+ 'weight' => $weight,
+ 'logistics' => $mock,
]);
/** assert */

0 comments on commit 9a1347a

Please sign in to comment.