tarfin-labs /
parasut-laravel
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace TarfinLabs\Parasut\Tests; |
||||
| 4 | |||||
| 5 | use TarfinLabs\Parasut\Mocks\ProductMock; |
||||
| 6 | use TarfinLabs\Parasut\Models\Product; |
||||
| 7 | use TarfinLabs\Parasut\Repositories\ProductRepository; |
||||
| 8 | |||||
| 9 | class ProductTest extends TestCase |
||||
| 10 | { |
||||
| 11 | /** @test */ |
||||
| 12 | public function user_can_list_products(): void |
||||
| 13 | { |
||||
| 14 | ProductMock::all(); |
||||
| 15 | |||||
| 16 | $productRepository = new ProductRepository(); |
||||
| 17 | |||||
| 18 | $products = $productRepository->all(); |
||||
| 19 | |||||
| 20 | $this->assertNotNull(Product::all()); |
||||
| 21 | $this->assertInstanceOf(Product::class, $products->first()); |
||||
| 22 | } |
||||
| 23 | |||||
| 24 | /** @test */ |
||||
| 25 | public function user_can_create_a_new_product(): void |
||||
| 26 | { |
||||
| 27 | $product = factory(Product::class) |
||||
| 28 | ->states(['creation', 'response']) |
||||
| 29 | ->make(); |
||||
| 30 | |||||
| 31 | ProductMock::create($product); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 32 | |||||
| 33 | $ProductRepository = new ProductRepository(); |
||||
| 34 | |||||
| 35 | $productReturned = $ProductRepository->create($product); |
||||
|
0 ignored issues
–
show
It seems like
$product can also be of type Illuminate\Database\Eloquent\Collection; however, parameter $model of TarfinLabs\Parasut\Repos...aseRepository::create() does only seem to accept TarfinLabs\Parasut\Models\BaseModel, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 36 | |||||
| 37 | $this->assertInstanceOf( |
||||
| 38 | Product::class, |
||||
| 39 | $product |
||||
| 40 | ); |
||||
| 41 | |||||
| 42 | $this->assertEquals( |
||||
| 43 | $product->name, |
||||
| 44 | $productReturned->name |
||||
|
0 ignored issues
–
show
|
|||||
| 45 | ); |
||||
| 46 | } |
||||
| 47 | |||||
| 48 | /** @test */ |
||||
| 49 | public function user_can_view_a_product(): void |
||||
| 50 | { |
||||
| 51 | $productId = ProductMock::find(); |
||||
| 52 | |||||
| 53 | $ProductRepository = new ProductRepository(); |
||||
| 54 | |||||
| 55 | $product = $ProductRepository->find($productId); |
||||
| 56 | |||||
| 57 | $this->assertInstanceOf( |
||||
| 58 | Product::class, |
||||
| 59 | $product |
||||
| 60 | ); |
||||
| 61 | |||||
| 62 | $this->assertEquals( |
||||
| 63 | $productId, |
||||
| 64 | $product->id |
||||
| 65 | ); |
||||
| 66 | } |
||||
| 67 | |||||
| 68 | /** @test */ |
||||
| 69 | public function user_can_edit_a_product(): void |
||||
| 70 | { |
||||
| 71 | $product = factory(Product::class) |
||||
| 72 | ->states(['creation', 'response']) |
||||
| 73 | ->make(); |
||||
| 74 | |||||
| 75 | ProductMock::create($product); |
||||
|
0 ignored issues
–
show
It seems like
$product can also be of type Illuminate\Database\Eloquent\Collection; however, parameter $product of TarfinLabs\Parasut\Mocks\ProductMock::create() does only seem to accept TarfinLabs\Parasut\Models\BaseModel, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 76 | $ProductRepository = new ProductRepository(); |
||||
| 77 | $product = $ProductRepository->create($product); |
||||
|
0 ignored issues
–
show
It seems like
$product can also be of type Illuminate\Database\Eloquent\Collection; however, parameter $model of TarfinLabs\Parasut\Repos...aseRepository::create() does only seem to accept TarfinLabs\Parasut\Models\BaseModel, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 78 | |||||
| 79 | $newProduct = factory(Product::class)->make(); |
||||
| 80 | $newProduct->id = $product->id; |
||||
|
0 ignored issues
–
show
|
|||||
| 81 | |||||
| 82 | ProductMock::update($product); |
||||
| 83 | $updatedContact = $ProductRepository->update($newProduct); |
||||
|
0 ignored issues
–
show
It seems like
$newProduct can also be of type Illuminate\Database\Eloquent\Collection; however, parameter $model of TarfinLabs\Parasut\Repos...aseRepository::update() does only seem to accept TarfinLabs\Parasut\Models\BaseModel, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 84 | |||||
| 85 | $this->assertInstanceOf( |
||||
| 86 | Product::class, |
||||
| 87 | $updatedContact |
||||
| 88 | ); |
||||
| 89 | |||||
| 90 | $this->assertEquals( |
||||
| 91 | $updatedContact->name, |
||||
|
0 ignored issues
–
show
|
|||||
| 92 | $newProduct->name |
||||
| 93 | ); |
||||
| 94 | } |
||||
| 95 | |||||
| 96 | /** @test */ |
||||
| 97 | public function user_can_delete_a_product(): void |
||||
| 98 | { |
||||
| 99 | $product = factory(Product::class) |
||||
| 100 | ->states(['creation', 'response']) |
||||
| 101 | ->make(); |
||||
| 102 | |||||
| 103 | ProductMock::create($product); |
||||
|
0 ignored issues
–
show
It seems like
$product can also be of type Illuminate\Database\Eloquent\Collection; however, parameter $product of TarfinLabs\Parasut\Mocks\ProductMock::create() does only seem to accept TarfinLabs\Parasut\Models\BaseModel, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 104 | $ProductRepository = new ProductRepository(); |
||||
| 105 | $product = $ProductRepository->create($product); |
||||
|
0 ignored issues
–
show
It seems like
$product can also be of type Illuminate\Database\Eloquent\Collection; however, parameter $model of TarfinLabs\Parasut\Repos...aseRepository::create() does only seem to accept TarfinLabs\Parasut\Models\BaseModel, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 106 | |||||
| 107 | ProductMock::delete($product); |
||||
| 108 | $result = $ProductRepository->delete($product); |
||||
| 109 | |||||
| 110 | $this->assertTrue($result); |
||||
| 111 | } |
||||
| 112 | } |
||||
| 113 |