-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProductCatalogTest.php
41 lines (34 loc) · 1.31 KB
/
ProductCatalogTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace App\Tests\Unit\Catalog;
use App\Catalog\ProductCatalog;
use App\Entity\Product;
use App\Repository\ProductRepository;
use PHPUnit\Framework\TestCase;
class ProductCatalogTest extends TestCase
{
public function testCatalogFetchesProductsFromRepository(): void
{
$productRepository = $this->createMock(ProductRepository::class);
$productRepository->expects($this->once())
->method("findAll");
$catalog = new ProductCatalog($productRepository);
$catalog->getMostExpensiveProducts();
}
public function testGetMostExpensiveProductsReallyReturnsTheMostExpensive(): void
{
$productRepository = $this->createStub(ProductRepository::class);
$productRepository->method("findAll")
->willReturn([
new Product("Balloon (individual)", "BAL-0001", 0.05),
new Product("Balloon (pack of 3)", "BAL-0003", 0.12),
new Product("Balloon (pack of 12)", "BAL-0012", 0.45),
new Product("Balloon (pack of 50)", "BAL-0050", 1.75),
new Product("Balloon (pack of 250)", "BAL-0250", 2.50),
new Product("Balloon (pack of 5000)", "BAL-5000", 15.00),
]);
$catalog = new ProductCatalog($productRepository);
$products = $catalog->getMostExpensiveProducts();
$skus = array_map(fn (Product $product) => $product->sku, $products);
$this->assertSame(["BAL-5000", "BAL-0250", "BAL-0050"], $skus);
}
}