Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -259,4 +259,92 @@ class ProductRepositoryTest extends TestCase
|
||||
$this->assertIsInt($quantity); // Sprawdzamy czy konwersja na int zadziałała
|
||||
$this->assertEquals(25, $quantity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test przywracania produktu z archiwum
|
||||
*/
|
||||
public function testUnarchiveUpdatesProductAndChildren()
|
||||
{
|
||||
// Arrange
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$mockDb->expects($this->exactly(2))
|
||||
->method('update')
|
||||
->withConsecutive(
|
||||
[
|
||||
$this->equalTo('pp_shop_products'),
|
||||
$this->equalTo(['status' => 1, 'archive' => 0]),
|
||||
$this->equalTo(['id' => 123])
|
||||
],
|
||||
[
|
||||
$this->equalTo('pp_shop_products'),
|
||||
$this->equalTo(['status' => 1, 'archive' => 0]),
|
||||
$this->equalTo(['parent_id' => 123])
|
||||
]
|
||||
);
|
||||
|
||||
$repository = new ProductRepository($mockDb);
|
||||
|
||||
// Act
|
||||
$result = $repository->unarchive(123);
|
||||
|
||||
// Assert
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test przenoszenia produktu do archiwum
|
||||
*/
|
||||
public function testArchiveUpdatesProductAndChildren()
|
||||
{
|
||||
// Arrange
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$mockDb->expects($this->exactly(2))
|
||||
->method('update')
|
||||
->withConsecutive(
|
||||
[
|
||||
$this->equalTo('pp_shop_products'),
|
||||
$this->equalTo(['status' => 0, 'archive' => 1]),
|
||||
$this->equalTo(['id' => 456])
|
||||
],
|
||||
[
|
||||
$this->equalTo('pp_shop_products'),
|
||||
$this->equalTo(['status' => 0, 'archive' => 1]),
|
||||
$this->equalTo(['parent_id' => 456])
|
||||
]
|
||||
);
|
||||
|
||||
$repository = new ProductRepository($mockDb);
|
||||
|
||||
// Act
|
||||
$result = $repository->archive(456);
|
||||
|
||||
// Assert
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test że unarchive zwraca bool
|
||||
*/
|
||||
public function testUnarchiveReturnsBool()
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$repository = new ProductRepository($mockDb);
|
||||
|
||||
$result = $repository->unarchive(1);
|
||||
$this->assertIsBool($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test że archive zwraca bool
|
||||
*/
|
||||
public function testArchiveReturnsBool()
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$repository = new ProductRepository($mockDb);
|
||||
|
||||
$result = $repository->archive(1);
|
||||
$this->assertIsBool($result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user