Skip to content

Commit

Permalink
Added capability of change Credentials after ProxmoxVE object creation
Browse files Browse the repository at this point in the history
  • Loading branch information
zzantares committed Jun 27, 2014
1 parent 1b71ebe commit 2a0925f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
11 changes: 11 additions & 0 deletions src/ProxmoxVE.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
26 changes: 19 additions & 7 deletions tests/ProxmoxVETest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand All @@ -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.
*/
Expand Down

0 comments on commit 2a0925f

Please sign in to comment.