Skip to content

Commit

Permalink
Updated phpunit path and fixed upper/lowecase.
Browse files Browse the repository at this point in the history
Added exception for not-implemented sorter
  • Loading branch information
michalsvec committed Feb 19, 2014
1 parent 3efab1e commit ec03ca8
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 5 deletions.
17 changes: 14 additions & 3 deletions components/LogGenerator/LogGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,27 @@ protected function getTicketInformation($logList)
return $ticketLog;
}


/**
* Orders that RFCs are 1st, bugfixes 2nd, support 3rd and the rest below
*
* @param array $issues
* @return array
*/
private function orderByIssueType($issues)
{
//trigger_error("Sorting not implemented!", E_USER_NOTICE);
trigger_error("Sorting not implemented!", E_USER_NOTICE);
return $issues;
}

/**
* P1 at the top, then P2, .....
*
* @param $issues
* @return mixed
*/
private function orderByPriority($issues)
{
//trigger_error("Sorting not implemented!", E_USER_NOTICE);
trigger_error("Sorting not implemented!", E_USER_NOTICE);
return $issues;
}

Expand Down
133 changes: 133 additions & 0 deletions components/LogGenerator/Tests/LogGeneratorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php

class SvnHelperTest extends PHPUnit_Framework_TestCase {

/**
* @param array $returnValue
* @return JiraWrapper
*/
private function getJiraMock($returnValue = array())
{
$mock = $this->getMockBuilder('JiraWrapper')
->disableOriginalConstructor()
->getMock();

$mock->expects($this->any())
->method('getTicketInfo')
->will($this->returnValue($returnValue));

return $mock;
}

/**
* @param int $count
* @return array
*/
private function getTicketData($count = 3)
{
$ticketData = array(
1 => array(
'revision' => 1,
'author' => "user01",
'date' => "2014-02-07T07:32:03.065437Z",
'msg' => "[XXX-73] message"
),
2 => array(
'revision' => 2,
'author' => "user01",
'date' => "2014-02-06T17:30:08.106324Z",
'msg' => "Without ticket"
),
3 => array(
'revision' => 3,
'author' => "user01",
'date' => "2014-02-06T17:30:08.106324Z",
'msg' => "Without ticket 2"
)
);

return array_slice($ticketData, 0, $count);
}

public function testParseRevisionMessage_correctMessage()
{
$generator = new LogGenerator($this->getJiraMock());

$result = $generator->parseRevisionMessage("[TEST-12] testing\n- lorem ipsum");
$this->assertEquals('TEST-12', $result['ticket']);
}

public function testParseRevisionMessage_wrongMessage()
{
$generator = new LogGenerator($this->getJiraMock());

$result = $generator->parseRevisionMessage("testing\n- lorem ipsum");
$this->assertEquals('', $result['ticket']);

}

public function testGenerateTicketLog_correctData()
{
$generator = new LogGenerator($this->getJiraMock());
$ticketLog = $generator->generateTicketLog($this->getTicketData(3));

$this->assertArrayHasKey('ALL', $ticketLog);
$this->assertArrayHasKey('OTHER', $ticketLog);
$this->assertArrayHasKey('XXX-73', $ticketLog['OTHER']);
$this->assertCount(2, $ticketLog);
$this->assertCount(3, $ticketLog['ALL']);
$this->assertCount(3, $ticketLog['OTHER']);
}


public function testGenerateTicketLog_issueType_RFC()
{
$ticketInfo = array(
'key' => 'XXX-73',
'typeName' => 'RFC',
);

$generator = new LogGenerator($this->getJiraMock($ticketInfo));
$ticketLog = $generator->generateTicketLog($this->getTicketData(1)); // temporary @ till sorting will be implemented

$this->assertArrayHasKey('ALL', $ticketLog);
$this->assertArrayHasKey('RFC', $ticketLog);
$this->assertArrayHasKey('XXX-73', $ticketLog['RFC']);
$this->assertCount(2, $ticketLog);
$this->assertCount(1, $ticketLog['RFC']);
}

public function testGenerateTicketLog_issueType_Bug()
{
$ticketInfo = array(
'key' => 'XXX-73',
'typeName' => 'Technical task',
);

$generator = new LogGenerator($this->getJiraMock($ticketInfo));
$ticketLog = $generator->generateTicketLog($this->getTicketData(1)); // temporary @ till sorting will be implemented

$this->assertArrayHasKey('ALL', $ticketLog);
$this->assertArrayHasKey('RFC', $ticketLog);
$this->assertArrayHasKey('XXX-73', $ticketLog['RFC']);
$this->assertCount(2, $ticketLog);
$this->assertCount(1, $ticketLog['RFC']);
}

public function testGenerateTicketLog_issueType_Support()
{
$ticketInfo = array(
'key' => 'XXX-73',
'typeName' => 'Support Request',
);

$generator = new LogGenerator($this->getJiraMock($ticketInfo));
$ticketLog = $generator->generateTicketLog($this->getTicketData(1)); // temporary @ till sorting will be implemented

$this->assertArrayHasKey('ALL', $ticketLog);
$this->assertArrayHasKey('SUPPORT', $ticketLog);
$this->assertArrayHasKey('XXX-73', $ticketLog['SUPPORT']);
$this->assertCount(2, $ticketLog);
$this->assertCount(1, $ticketLog['SUPPORT']);
}
}
1 change: 0 additions & 1 deletion components/LogGenerator/tests/LogGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ public function testGenerateTicketLog_issueType_Bug()
$this->assertCount(1, $ticketLog['RFC']);
}


public function testGenerateTicketLog_issueType_Support()
{
$ticketInfo = array(
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
>
<testsuites>
<testsuite name="Components tests">
<directory>components/*/Tests/</directory>
<directory>./components/*</directory>
</testsuite>
</testsuites>
</phpunit>

0 comments on commit ec03ca8

Please sign in to comment.