class SortArray{
/* Test Data */
static function testArray(){
return Array (
0 => Array
(
'lastName' => 'Abercrombie',
'firstName' => 'Neil',
'gender' => 'Male',
'dob' => '2/13/1943',
'color' => 'Tan',
),
1 => Array
(
'lastName' => 'Bishop',
'firstName' => 'Timothy',
'gender' => 'Male',
'dob' => '4/23/1967',
'color' => 'Yellow',
),
3 => Array
(
'lastName' => 'Smith',
'firstName' => 'Steve',
'mi' => 'D',
'gender' => 'Male',
'color' => 'Red',
'dob' => '3/3/1985',
) ,
2 => Array
(
'lastName' => 'Kelly',
'firstName' => 'Sue',
'gender' => 'Female',
'dob' => '7/12/1959',
'color' => 'Pink',
),
4 => Array
(
'lastName' => 'Bonk',
'firstName' => 'Radek',
'mi' => 'S',
'gender' => 'Male',
'color' => 'Green',
'dob' => '6/3/1975',
),
5 => Array
(
'lastName' => 'Bouillon',
'firstName' => 'Francis',
'mi' => 'G',
'gender' => 'Male',
'color' => 'Blue',
'dob' => '6/3/1975',
),
6 => Array
(
'lastName' => 'Kournikova',
'firstName' => 'Anna',
'gender' => 'Female',
'color' => 'Red',
'dob' => '6/3/1975',
),
7 => Array
(
'lastName' => 'Hingis',
'firstName' => 'Martina',
'gender' => 'Female',
'color' => 'Green',
'dob' => '4/2/1979'
),
8 => Array
(
'lastName' => 'Seles',
'firstName' => 'Monica',
'gender' => 'Female',
'color' => 'Black',
'dob' => '12/2/1973',
)
);
}
};
class SortDateTest extends PHPUnit_Framework_TestCase{
/* how to sort */
private $_order;
/* sort index */
private $_index;
/* test against this array */
private $_testOriginalList;
protected function setUp(){
$this->_testOriginalList = SortArray::testArray();
$this->listAsc = new PersonsList( $this->_testOriginalList );
$this->listAsc->sort( new SortDate() );
$this->SortLastNameListAsc = array( 'Abercrombie', 'Kelly', 'Bishop', 'Seles', 'Bonk', 'Bouillon', 'Kournikova', 'Hingis', 'Smith' );
$this->listDesc = new PersonsList( $this->_testOriginalList );
$this->listDesc->sort( new SortDate( 'descending' ) );
$this->SortLastNameListDesc = array_reverse( array( 'Abercrombie', 'Kelly', 'Bishop', 'Seles', 'Kournikova','Bouillon', 'Bonk', 'Hingis', 'Smith' ) );
}
public function testSortAsc(){
$counter = 0;
foreach( $this->listAsc->getList() as $value ){
$this->assertEquals( $this->SortLastNameListAsc[$counter], $value['lastName'] );
$counter++;
}
}/* End of method testSortAsc() */
public function testSortDesc(){
$counter = 0;
foreach( $this->listDesc->getList() as $value ){
$this->assertEquals( $this->SortLastNameListDesc[$counter], $value['lastName'] );
$counter++;
}
}/* End of method testSortAsc() */
}/* End of class SortDateTest */
$testSuite = new PHPUnit_Framework_TestSuite();
$testSuite->addTest( new SortDateTest( 'testSortAsc' ) );
$testSuite->addTest( new SortDateTest( 'testSortDesc' ) );
PHPUnit_TextUI_TestRunner::run( $testSuite );
class SortGenderTest extends PHPUnit_Framework_TestCase{
/* how to sort */
private $_order;
/* sort index */
private $_index;
/* test against this array */
private $_testOriginalList;
protected function setUp(){
$this->_testOriginalList = SortArray::testArray();
$this->list = new PersonsList( $this->_testOriginalList );
$this->list->sort( new SortGender( ) );
$this->SortLastList = array( 'Hingis', 'Kelly', 'Kournikova', 'Seles', 'Abercrombie', 'Bishop', 'Bonk', 'Bouillon', 'Smith' );
}
public function testSort(){
$counter = 0;
foreach( $this->list->getList() as $value ){
$this->assertEquals( $this->SortLastList[$counter], $value['lastName'] );
$counter++;
}
}/* End of method sort() */
}/* End of class SortGenderTest */
$testSuite = new PHPUnit_Framework_TestSuite();
$testSuite->addTest( new SortGenderTest( 'testSort' ) );
PHPUnit_TextUI_TestRunner::run( $testSuite );
class SortLastNameTest extends PHPUnit_Framework_TestCase{
/* how to sort */
private $_order;
/* sort index */
private $_index;
/* test against this array */
private $_testOriginalList;
protected function setUp(){
$this->_testOriginalList = SortArray::testArray();
$this->listDesc = new PersonsList( $this->_testOriginalList );
$this->listDesc->sort( new SortLastName( 'descending' ) );
$this->SortLastNameListDesc = array( 'Smith', 'Seles', 'Kournikova', 'Kelly', 'Hingis', 'Bouillon', 'Bonk', 'Bishop', 'Abercrombie' );
$this->listAsc = new PersonsList( $this->_testOriginalList );
$this->listAsc->sort( new SortLastName( 'ascending' ) );
$this->SortLastNameListAsc = array_reverse(array( 'Smith', 'Seles', 'Kournikova', 'Kelly', 'Hingis', 'Bouillon', 'Bonk', 'Bishop', 'Abercrombie' ));
}
public function testSortDesc(){
$counter = 0;
foreach( $this->listDesc->getList() as $value ){
$this->assertEquals( $this->SortLastNameListDesc[$counter], $value['lastName'] );
$counter++;
}
}/* End of method testSortDesc() */
public function testSortAsc(){
$counter = 0;
foreach( $this->listAsc->getList() as $value ){
$this->assertEquals( $this->SortLastNameListAsc[$counter], $value['lastName'] );
$counter++;
}
}/* End of method testSortDesc() */
}/* End of class SortLastNameTest */
$testSuite = new PHPUnit_Framework_TestSuite();
$testSuite->addTest( new SortLastNameTest( 'testSortDesc' ) );
$testSuite->addTest( new SortLastNameTest( 'testSortAsc' ) );
PHPUnit_TextUI_TestRunner::run( $testSuite );