Created
May 26, 2011 22:16
-
-
Save mattleff/994226 to your computer and use it in GitHub Desktop.
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
<?php | |
class SF_mapMethod_mock extends DateTime | |
{ | |
public function __toString() | |
{ | |
return $this->format('Y-m-d H:i:s'); | |
} | |
} | |
class SF_unit_test_static_helper extends PHPUnit_Framework_TestCase | |
{ | |
function test_safeArrayAccess_fallback() | |
{ | |
$boolean = true; | |
$this->assertEquals( "fallback", SF_static_helper::safeArrayAccess( 'test', $boolean, "fallback" ) ); | |
$empty_array = array(); | |
$this->assertEquals( "fallback", SF_static_helper::safeArrayAccess( 'test', $empty_array, "fallback" ) ); | |
$wrong_array = array( 'something' => 'else' ); | |
$this->assertNull( SF_static_helper::safeArrayAccess( 'test', $empty_array ) ); | |
} | |
function test_safeArrayAccess_set() | |
{ | |
$example_array = array( 'person' => 'Matthew', 'age' => 22, 'gender' => 'male' ); | |
$this->assertEquals( "Matthew", SF_static_helper::safeArrayAccess( 'person', $example_array ) ); | |
$this->assertNull( SF_static_helper::safeArrayAccess( 'parent', $example_array ) ); | |
$this->assertSame( 22, SF_static_helper::safeArrayAccess( 'age', $example_array ) ); | |
} | |
function test_safeArrayAccess_object() | |
{ | |
$array_object = new ArrayObject( array( 'person' => 'Matthew', 'age' => 22, 'gender' => 'male' ) ); | |
$this->assertEquals( "Matthew", SF_static_helper::safeArrayAccess( 'person', $array_object ) ); | |
$this->assertNull( SF_static_helper::safeArrayAccess( 'parent', $array_object ) ); | |
$this->assertSame( 22, SF_static_helper::safeArrayAccess( 'age', $array_object ) ); | |
} | |
function test_mapMethod_basic() | |
{ | |
$object_array = array( new SF_mapMethod_mock('2011-01-01'), new SF_mapMethod_mock('1920-02-29'), new SF_mapMethod_mock('1999-12-31 12:34:56') ); | |
$dates_array = array( '2011-01-01 00:00:00', '1920-02-29 00:00:00', '1999-12-31 12:34:56' ); | |
$this->assertSame( $dates_array, SF_static_helper::mapMethod( $object_array, '__toString' ) ); | |
} | |
function test_mapMethod_params() | |
{ | |
$object_array = array( new DateTime('2011-01-01'), new DateTime('1920-02-29'), new DateTime('1999-12-31 12:34:56') ); | |
$modified_dates_array = array( new DateTime('2011-01-01 19:13:11'), new DateTime('1920-02-29 19:13:11'), new DateTime('1999-12-31 19:13:11') ); | |
$this->assertSame( $modified_dates_array, SF_static_helper::mapMethod( $object_array, 'setTime', array( 19, 13, 11 ) ) ); | |
$object_array = array( new DateTime('2011-01-01'), new DateTime('1920-02-29'), new DateTime('1999-12-31 12:34:56') ); | |
$dates_array = array( '2011-01-01 00:00:00', '1920-02-29 00:00:00', '1999-12-31 12:34:56' ); | |
$this->assertSame( $dates_array, SF_static_helper::mapMethod( $object_array, 'format', array( 'Y-m-d H:i:s', 'Y-m-d H:i:s', 'Y-m-d H:i:s' ) ) ); | |
$new_dates_array = array( '2011-01-01 01:00:00', '1920-02-29 10:00:00', '1999-12-31 02:34:56' ); | |
$this->assertSame( $new_dates_array, SF_static_helper::mapMethod( $object_array, 'modify', array( '+1 hour', '+10 hours', '-10 hours' ), 'format', array( 'Y-m-d H:i:s', 'Y-m-d H:i:s', 'Y-m-d H:i:s' ) ) ); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment