Created
January 9, 2014 08:40
-
-
Save itsananderson/8331193 to your computer and use it in GitHub Desktop.
Tests various inputs into Search_Replace_Ccmmand::recursive_unserialize_replace
This file contains hidden or 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 | |
require_once getcwd() . '/php/class-wp-cli.php'; | |
require_once getcwd() . '/php/class-wp-cli-command.php'; | |
require_once getcwd() . '/php/commands/search-replace.php'; | |
class UnserializeReplaceTest extends PHPUnit_Framework_TestCase { | |
function testReplaceString() { | |
$orig = 'foo'; | |
$replacement = Search_Replace_Command::recursive_unserialize_replace( 'foo', 'bar', $orig ); | |
$this->assertEquals( 'bar', $replacement ); | |
} | |
function testPrivateConstructor() { | |
$old_obj = ClassWithPrivateConstructor::get_instance(); | |
$new_obj = Search_Replace_Command::recursive_unserialize_replace( 'foo', 'bar', $old_obj, false, true ); | |
$this->assertEquals( 'bar', $new_obj->prop ); | |
} | |
function testObjectLoop() { | |
$old_object = new stdClass(); | |
$old_object->prop = 'foo'; | |
$old_object->self = $old_object; | |
$new_obj = Search_Replace_Command::recursive_unserialize_replace( 'foo', 'bar', $old_object, false, true ); | |
$this->assertEquals( 'bar', $new_obj->prop ); | |
} | |
function testArrayLoop() { | |
$old_array = array( 'prop' => 'foo' ); | |
$old_array['self'] = &$old_array; | |
$new_array = Search_Replace_Command::recursive_unserialize_replace( 'foo', 'bar', $old_array, false, true ); | |
$this->assertEquals( 'bar', $new_array['prop'] ); | |
} | |
function testMixedObjectArrayLoop() { | |
$old_object = new stdClass(); | |
$old_object->prop = 'foo'; | |
$old_object->array = array('prop' => 'foo'); | |
$old_object->array['object'] = $old_object; | |
$new_object = Search_Replace_Command::recursive_unserialize_replace( 'foo', 'bar', $old_object, false, true ); | |
$this->assertEquals( 'bar', $new_object->prop ); | |
$this->assertEquals( 'bar', $new_object->array['prop']); | |
} | |
function testMixedArrayObjectLoop() { | |
$old_array = array( 'prop' => 'foo', 'object' => new stdClass() ); | |
$old_array['object']->prop = 'foo'; | |
$old_array['object']->array = &$old_array; | |
$new_array = Search_Replace_Command::recursive_unserialize_replace( 'foo', 'bar', $old_array, false, true ); | |
$this->assertEquals( 'bar', $new_array['prop'] ); | |
$this->assertEquals( 'bar', $new_array['object']->prop); | |
} | |
} | |
class ClassWithPrivateConstructor { | |
public $prop = 'foo'; | |
private function __construct() {} | |
public static function get_instance() { | |
return new self; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment