-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
143 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace eiriksm\CosyComposerTest\unit\Providers; | ||
|
||
use eiriksm\CosyComposer\Providers\Gitlab; | ||
use Gitlab\Client; | ||
|
||
class GitlabProviderTest extends ProvidersTestBase | ||
{ | ||
protected $authenticateArguments = [ | ||
'testUser', | ||
Client::AUTH_OAUTH_TOKEN | ||
]; | ||
|
||
protected $authenticatePrivateArguments = [ | ||
'testUser', | ||
Client::AUTH_OAUTH_TOKEN | ||
]; | ||
|
||
public function testRepoIsPrivate() | ||
{ | ||
$client = $this->getMockClient(); | ||
$provider = $this->getProvider($client); | ||
$this->assertEquals(true, $provider->repoIsPrivate('testUser', 'testRepo')); | ||
} | ||
|
||
protected function getProvider(Client $client) | ||
{ | ||
return new Gitlab($client); | ||
} | ||
|
||
protected function getMockClient() | ||
{ | ||
return $this->createMock(Client::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace eiriksm\CosyComposerTest\unit\Providers; | ||
|
||
use eiriksm\CosyComposer\ProviderInterface; | ||
|
||
abstract class ProvidersTestBase extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
||
protected $authenticateArguments = []; | ||
|
||
public function testAuthenticate() | ||
{ | ||
$client = $this->getMockClient(); | ||
$expect = $client->expects($this->once()) | ||
->method('authenticate'); | ||
$this->configureArguments('authenticateArguments', $expect); | ||
$provider = $this->getProvider($client); | ||
$this->runAuthenticate($provider); | ||
} | ||
|
||
public function testAuthenticatePrivate() | ||
{ | ||
$mock_client = $this->getMockClient(); | ||
$expect = $mock_client->expects($this->once()) | ||
->method('authenticate'); | ||
$this->configureArguments('authenticatePrivateArguments', $expect); | ||
$provider = $this->getProvider($mock_client); | ||
$this->runAuthenticate($provider, 'authenticatePrivate'); | ||
} | ||
|
||
protected function configureArguments($key, \PHPUnit_Framework_MockObject_Builder_InvocationMocker $object) | ||
{ | ||
$arguments = $this->{$key}; | ||
switch (count($arguments)) { | ||
case 2: | ||
list($one, $two) = $arguments; | ||
$object->with($one, $two); | ||
break; | ||
|
||
case 3: | ||
list($one, $two, $three) = $arguments; | ||
$object->with($one, $two, $three); | ||
break; | ||
|
||
default: | ||
throw new \Exception('Auth arguments not configured'); | ||
} | ||
} | ||
|
||
protected function runAuthenticate(ProviderInterface $provider, $method = 'authenticate') | ||
{ | ||
$user = 'testUser'; | ||
$password = 'testPassword'; | ||
$provider->{$method}($user, $password); | ||
} | ||
|
||
protected function getPrData() | ||
{ | ||
return [ | ||
'testUser', | ||
'testRepo', | ||
[ | ||
'param1' => true, | ||
], | ||
]; | ||
} | ||
} |