- Timestamp:
- 08/12/2022 01:22:25 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/functions/isSerializedString.php
r49006 r53889 12 12 13 13 /** 14 * Data provider method for testing `is_serialized_string()`. 15 * 16 * @return array 17 */ 18 public function _is_serialized_string() { 19 return array( 20 21 // pass array. 22 array( array(), false ), 23 24 // pass a class. 25 array( new stdClass(), false ), 26 27 // Not a string. 28 array( 0, false ), 29 30 // Too short when trimmed. 31 array( 's:3 ', false ), 32 33 // Too short. 34 array( 's:3', false ), 35 36 // No colon in second position. 37 array( 's!3:"foo";', false ), 38 39 // No trailing semicolon. 40 array( 's:3:"foo"', false ), 41 42 // Wrong type. 43 array( 'a:3:"foo";', false ), 44 45 // No closing quote. 46 array( 'a:3:"foo;', false ), 47 48 // have to use double Quotes. 49 array( "s:12:'foo';", false ), 50 51 // Wrong number of characters is close enough for is_serialized_string(). 52 array( 's:12:"foo";', true ), 53 54 // Okay. 55 array( 's:3:"foo";', true ), 56 ); 57 } 58 59 /** 60 * Run tests on `is_serialized_string()`. 61 * 62 * @dataProvider _is_serialized_string 14 * @dataProvider data_is_serialized_string 63 15 * 64 16 * @param array|object|int|string $data Data value to test. … … 68 20 $this->assertSame( $expected, is_serialized_string( $data ) ); 69 21 } 22 23 /** 24 * Data provider for `test_is_serialized_string()`. 25 * 26 * @return array 27 */ 28 public function data_is_serialized_string() { 29 return array( 30 'an array' => array( 31 'data' => array(), 32 'expected' => false, 33 ), 34 'a class' => array( 35 'data' => new stdClass(), 36 'expected' => false, 37 ), 38 'an integer 0' => array( 39 'data' => 0, 40 'expected' => false, 41 ), 42 'a string that is too short when trimmed' => array( 43 'data' => 's:3 ', 44 'expected' => false, 45 ), 46 'a string that is too short' => array( 47 'data' => 's:3', 48 'expected' => false, 49 ), 50 'not a colon in second position' => array( 51 'data' => 's!3:"foo";', 52 'expected' => false, 53 ), 54 'no trailing semicolon' => array( 55 'data' => 's:3:"foo"', 56 'expected' => false, 57 ), 58 'wrong type of serialized data' => array( 59 'data' => 'a:3:"foo";', 60 'expected' => false, 61 ), 62 'no closing quote' => array( 63 'data' => 'a:3:"foo;', 64 'expected' => false, 65 ), 66 'single quotes instead of double' => array( 67 'data' => "s:12:'foo';", 68 'expected' => false, 69 ), 70 'wrong number of characters (should not matter)' => array( 71 'data' => 's:12:"foo";', 72 'expected' => true, 73 ), 74 'valid serialized string' => array( 75 'data' => 's:3:"foo";', 76 'expected' => true, 77 ), 78 ); 79 } 70 80 }
Note: See TracChangeset
for help on using the changeset viewer.