-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from ericduran/certify-command-test
UGH THIS WAS NOT EASY
- Loading branch information
Showing
3 changed files
with
130 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
namespace flo\Test\Command\PullRequest; | ||
|
||
use flo\Test; | ||
use flo\Console\Application; | ||
use Github; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
class CertifyCommandTest extends Test\FunctionalFramework { | ||
|
||
/** | ||
* The main flo application. | ||
* | ||
* @var string | ||
*/ | ||
private $application; | ||
|
||
/** | ||
* set up test environment filesystem. | ||
*/ | ||
public function setUp() { | ||
$this->application = new Application(); | ||
parent::setUp(); | ||
} | ||
|
||
/** | ||
* Test Running pr-deploy with an string instead of PR Number. | ||
* | ||
* @expectedException Exception | ||
* @expectedExceptionMessageRegExp #PR must be a number.# | ||
*/ | ||
public function testNANPRCertifyException() { | ||
$command_run_script = $this->application->find('pr-certify'); | ||
$command_tester = new CommandTester($command_run_script); | ||
$command_tester->execute(array( | ||
'command' => $command_run_script->getName(), | ||
'pull-request' => "Not-A-Valid-PR", | ||
)); | ||
} | ||
|
||
/** | ||
* Test Running pr-deploy with an string instead of PR Number. | ||
*/ | ||
public function testAddingCertifyLabel() { | ||
$this->writeConfig(); | ||
|
||
//TODO: CLEAN THIS UP AND UNDERSTAND THIS!!!!! | ||
//I FINALLY UNDERSTAND HOW TO MOCK OBJECTS!!!!!!!!!!! | ||
|
||
$httpClientMock = $this->getMock('Guzzle\Http\Client', array('send')); | ||
$httpClientMock | ||
->expects($this->any()) | ||
->method('send'); | ||
|
||
$mock = $this->getMock('Github\HttpClient\HttpClient', array(), array(array(), $httpClientMock)); | ||
$client = new Github\Client($mock); | ||
$client->setHttpClient($mock); | ||
|
||
// Mock the Issue API. | ||
$IssueMock = $this->getMockBuilder('Github\Api\Issue') | ||
->setMethods(array('labels')) | ||
->setConstructorArgs(array($client)) | ||
->getMock(); | ||
|
||
// Mock the label API. | ||
$labelsMock = $this->getMockBuilder('Github\Api\Issue\Labels') | ||
->setMethods(array('get', 'post', 'postRaw', 'patch', 'delete', 'put', 'head')) | ||
->setConstructorArgs(array($client)) | ||
->getMock(); | ||
|
||
// This actually runs an assert and makes sure our API call actually returns that :-O. | ||
$labelsMock->expects($this->once()) | ||
->method('post') | ||
->with('repos/NBCUOTS/Publisher7_nbcuflo/issues/1/labels') | ||
->will($this->returnValue('Test')); | ||
|
||
// Set up the Issue API to return the Label api. | ||
$IssueMock->expects($this->once()) | ||
->method('labels') | ||
->willReturn($labelsMock); | ||
|
||
|
||
// Now after ALLLLL that set up, lets call our command | ||
$command_run_script = $this->application->find('pr-certify'); | ||
$command_run_script->github = $IssueMock; | ||
|
||
$command_tester = new CommandTester($command_run_script); | ||
$command_tester->execute(array( | ||
'command' => $command_run_script->getName(), | ||
'pull-request' => "1", | ||
)); | ||
|
||
$this->assertEquals("PR #1 has been certified.\n", $command_tester->getDisplay()); | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -52,6 +52,29 @@ public function setUp() { | |
parent::setUp(); | ||
} | ||
|
||
/** | ||
* Helper function to write configuration file. | ||
*/ | ||
protected function writeConfig() { | ||
// Create a sample flo.yml file. | ||
$project_config = <<<EOT | ||
--- | ||
organization: NBCUOTS | ||
repository: Publisher7_nbcuflo | ||
shortname: Publisher7_nbcuflo | ||
github_git_uri: [email protected]:NBCUOTS/Publisher7_nbcuflo.git | ||
pull_request: | ||
domain: pr.publisher7.com | ||
prefix: flo-test | ||
scripts: | ||
pre_deploy_cmd: | ||
- scripts/pre-deploy.sh | ||
post_deploy_cmd: | ||
- scripts/post-deploy.sh | ||
EOT; | ||
$this->fs->dumpFile($this->root . "/flo.yml", $project_config); | ||
} | ||
|
||
/** | ||
* Remove the files and directories created for this test. | ||
*/ | ||
|