PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/test/tests/hash.php

http://github.com/kballenegger/MongoModel
PHP | 92 lines | 67 code | 25 blank | 0 comment | 16 complexity | bfa4158287eb95a7dfc0c9fcebcd9388 MD5 | raw file
  1. <?php
  2. require_once dirname(__FILE__).'/../../lib/hash.php';
  3. class HashTester extends Tester {
  4. public static $array;
  5. public static function test_construct() {
  6. self::$array = null;
  7. $data = array(
  8. 'numeric' => 123,
  9. 'string' => 'something',
  10. 'object' => new stdClass,
  11. 'array' => array('one', 'two', 3),
  12. 'hash' => array(
  13. 'one' => 1,
  14. 'two' => 2,
  15. 'three' => 3,
  16. )
  17. );
  18. $array = Hash::create($data);
  19. if (!$array instanceof Hash)
  20. throw new TestError('Hash not created correctly.');
  21. self::$array = $array;
  22. }
  23. public static function test_numeric() {
  24. self::depends_on('construct');
  25. $array = self::$array;
  26. if (!$array instanceof Hash)
  27. throw new TestError('Hash statically stored not readable.');
  28. if ($array->numeric != 123)
  29. throw new TestError('Numeric data failure.'."\n".var_export($array->numeric, true));
  30. }
  31. public static function test_string() {
  32. self::depends_on('construct');
  33. $array = self::$array;
  34. if (!$array instanceof Hash)
  35. throw new TestError('Hash statically stored not readable.');
  36. if ($array->string != 'something')
  37. throw new TestError('String data failure.'."\n".var_export($array->string, true));
  38. }
  39. public static function test_object() {
  40. self::depends_on('construct');
  41. $array = self::$array;
  42. if (!$array instanceof Hash)
  43. throw new TestError('Hash statically stored not readable.');
  44. if (!$array->object instanceof stdClass)
  45. throw new TestError('Object data failure.'."\n".var_export($array->object, true));
  46. }
  47. public static function test_array() {
  48. self::depends_on('construct');
  49. $array = self::$array;
  50. if (!$array instanceof Hash)
  51. throw new TestError('Hash statically stored not readable.');
  52. if (!is_array($array->array))
  53. throw new TestError('Array member is not array.'."\n".var_export($array->array, true));
  54. if (!is_array($array->array))
  55. throw new TestError('Array data failure.');
  56. }
  57. public static function test_hash() {
  58. self::depends_on('construct');
  59. $array = self::$array;
  60. if (!$array instanceof Hash)
  61. throw new TestError('Hash statically stored not readable.');
  62. if (!$array->hash instanceof Hash)
  63. throw new TestError('Hash member is not hash.'."\n".var_export($array->hash, true));
  64. if ($array->hash->one != 1)
  65. throw new TestError('Hash member content not as expected.'."\n".var_export($array->hash, true));
  66. }
  67. }