Skip to content

Commit

Permalink
Added first Test
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Schläpfer committed Oct 10, 2023
1 parent 0be25ba commit 92c701f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function setDi(\Pimple\Container|null $di): void
{
$this->di = $di;
}

public function getDi(): ?\Pimple\Container
{
return $this->di;
Expand Down
53 changes: 51 additions & 2 deletions tests/Serviceproxmox/ServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,56 @@ public function testgetDi()
$this->assertEquals($di, $getDi);
}




public function test_create()
{
// Mocking the order model
$orderModel = new \Model_ClientOrder();
$orderModel->loadBean(new \DummyBean());
$orderModel->config = json_encode(['some_config_key' => 'some_config_value']); // Example config
$orderModel->product_id = 123; // Example product ID

// Mocking the product model
$productModel = new \Model_Product();
$productModel->loadBean(new \DummyBean());

// Mocking the database
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
$dbMock->expects($this->atLeastOnce())
->method('getExistingModelById')
->with('Product', $orderModel->product_id, 'Product not found')
->will($this->returnValue($productModel));

$serviceProxmoxModel = new \RedBeanPHP\SimpleModel();
$serviceProxmoxModel->loadBean(new \DummyBean());
$dbMock->expects($this->atLeastOnce())
->method('dispense')
->with('service_proxmox')
->will($this->returnValue($serviceProxmoxModel));

$dbMock->expects($this->atLeastOnce())
->method('store')
->with($serviceProxmoxModel);

$di = new \Pimple\Container();
$di['db'] = $dbMock;

// Mocking the find_empty method
$serviceProxmoxMock = $this->getMockBuilder('\Box\Mod\Serviceproxmox\Service')
->setMethods(['find_empty'])
->getMock();
$serviceProxmoxMock->expects($this->once())
->method('find_empty')
->with($productModel)
->will($this->returnValue(1)); // Example server ID

$serviceProxmoxMock->setDi($di);
$result = $serviceProxmoxMock->create($orderModel);

$this->assertInstanceOf('\RedBeanPHP\SimpleModel', $result);
$this->assertEquals($orderModel->client_id, $result->client_id);
$this->assertEquals(1, $result->server_id); // Asserting the server ID is set correctly
}


}

0 comments on commit 92c701f

Please sign in to comment.