UsageLimitEligibilityCheckerTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018-06-27
  6. * Time: 17:22
  7. */
  8. namespace iBrand\Component\Discount\Test\Checkers;
  9. use iBrand\Component\Discount\Checkers\DatesEligibilityChecker;
  10. use iBrand\Component\Discount\Checkers\UsageLimitEligibilityChecker;
  11. use iBrand\Component\Discount\Test\BaseTest;
  12. use Carbon\Carbon;
  13. use iBrand\Component\Discount\Models\Discount;
  14. use Faker\Factory;
  15. class UsageLimitEligibilityCheckerTest extends BaseTest
  16. {
  17. public function testIsEligible()
  18. {
  19. $faker = Factory::create('zh_CN');
  20. $discountChecker = $this->app->make(UsageLimitEligibilityChecker::class);
  21. $discount = Discount::create([
  22. 'title' => $faker->word,
  23. 'label' => $faker->word,
  24. 'usage_limit' => $faker->numberBetween(80, 100),
  25. 'used' => 20,
  26. 'starts_at' => Carbon::now()->addDay(1),
  27. 'ends_at' => Carbon::now()->addDay(2),
  28. ]);
  29. $result = $discountChecker->isEligible($discount);
  30. $this->assertTrue($result);
  31. $discount = Discount::create([
  32. 'title' => $faker->word,
  33. 'label' => $faker->word,
  34. 'usage_limit' => $faker->numberBetween(80, 100),
  35. 'used' => 100,
  36. 'starts_at' => Carbon::now()->addDay(-1),
  37. 'ends_at' => Carbon::now()->addDay(2),
  38. ]);
  39. $result = $discountChecker->isEligible($discount);
  40. $this->assertFalse($result);
  41. //test usage limit null
  42. $discount = Discount::create([
  43. 'title' => $faker->word,
  44. 'label' => $faker->word,
  45. 'used' => 20,
  46. 'starts_at' => Carbon::now()->addDay(1),
  47. 'ends_at' => Carbon::now()->addDay(2),
  48. ]);
  49. $result = $discountChecker->isEligible($discount);
  50. $this->assertTrue($result);
  51. }
  52. }