From 2a0925f0eba3ee77b2f5a7c85da4b068e71cfe59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Mu=C3=B1oz?= Date: Fri, 27 Jun 2014 01:38:16 -0500 Subject: [PATCH] Added capability of change Credentials after ProxmoxVE object creation --- src/ProxmoxVE.php | 11 +++++++++++ tests/ProxmoxVETest.php | 26 +++++++++++++++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/ProxmoxVE.php b/src/ProxmoxVE.php index a4173a0..701593b 100644 --- a/src/ProxmoxVE.php +++ b/src/ProxmoxVE.php @@ -201,6 +201,17 @@ public function getCredentials() } + /** + * Assign the passed Credentials object to the ProxmoxVE. + * + * @param ZzAntares\ProxmoxVE\Credentials $credentials to assign. + */ + public function setCredentials($credentials) + { + $this->credentials = $credentials; + } + + /** * Performs a GET request to the Proxmox server. * diff --git a/tests/ProxmoxVETest.php b/tests/ProxmoxVETest.php index 816838e..b4cd7cb 100644 --- a/tests/ProxmoxVETest.php +++ b/tests/ProxmoxVETest.php @@ -15,15 +15,18 @@ class ProxmoxVETest extends \PHPUnit_Framework_TestCase { public function setUp() { - $this->credentials = new Credentials('myproxmox.tld', 'root', 'abc123'); + $fakeToken = new AuthToken('csrf', 'ticket', 'owner'); - $this->proxmox = $this->getMockBuilder('ZzAntares\ProxmoxVE\ProxmoxVE') - ->disableOriginalConstructor() - ->getMock(); + $this->credentials = $this->getMockBuilder('ZzAntares\ProxmoxVE\Credentials') + ->setMethods(array('login')) + ->setConstructorArgs(array('myproxmox.tld', 'root', 'abc123')) + ->getMock(); - $this->proxmox->expects($this->any()) - ->method('getCredentials') - ->will($this->returnValue($this->credentials)); + $this->credentials->expects($this->any()) + ->method('login') + ->will($this->returnValue($fakeToken)); + + $this->proxmox = new ProxmoxVE($this->credentials); } @@ -43,6 +46,15 @@ public function testConstructorThrowsExceptionWhenBadParamsArePassed() } + public function testChangesCredentialsCorrectly() + { + $newCredentials = new Credentials('host', 'user', 'pass'); + $this->proxmox->setCredentials($newCredentials); + + $this->assertEquals($newCredentials, $this->proxmox->getCredentials()); + } + + /* * Add test for get, post, put and delete functions. Need to create mocks. */