PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/units/classes/superglobals.php

http://github.com/mageekguy/atoum
PHP | 76 lines | 70 code | 6 blank | 0 comment | 1 complexity | 8ef9b5771aa986ccfb8cb2809f709fce MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units;
  3. use
  4. mageekguy\atoum,
  5. mageekguy\atoum\superglobals as testedClass
  6. ;
  7. require_once __DIR__ . '/../runner.php';
  8. class superglobals extends atoum\test
  9. {
  10. public function test__get()
  11. {
  12. if (isset($GLOBALS['_SESSION']) === false)
  13. {
  14. $GLOBALS['_SESSION'] = array();
  15. }
  16. $this
  17. ->if($superglobals = new testedClass())
  18. ->then
  19. ->array->setByReferenceWith($superglobals->GLOBALS)->isReferenceTo($GLOBALS)
  20. ->array->setByReferenceWith($superglobals->_SERVER)->isReferenceTo($_SERVER)
  21. ->array->setByReferenceWith($superglobals->_GET)->isReferenceTo($_GET)
  22. ->array->setByReferenceWith($superglobals->_POST)->isReferenceTo($_POST)
  23. ->array->setByReferenceWith($superglobals->_FILES)->isReferenceTo($_FILES)
  24. ->array->setByReferenceWith($superglobals->_COOKIE)->isReferenceTo($_COOKIE)
  25. ->array->setByReferenceWith($superglobals->_SESSION)->isReferenceTo($_SESSION)
  26. ->array->setByReferenceWith($superglobals->_REQUEST)->isReferenceTo($_REQUEST)
  27. ->array->setByReferenceWith($superglobals->_ENV)->isReferenceTo($_ENV)
  28. ;
  29. }
  30. public function test__set()
  31. {
  32. $this
  33. ->if($superglobals = new testedClass())
  34. ->then
  35. ->exception(function() use ($superglobals, & $name) {
  36. $superglobals->{$name = uniqid()} = uniqid();
  37. }
  38. )
  39. ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument')
  40. ->hasMessage('PHP superglobal \'$' . $name . '\' does not exist')
  41. ->if($superglobals->GLOBALS = ($variable = uniqid()))
  42. ->then
  43. ->string($superglobals->GLOBALS)->isEqualTo($variable)
  44. ->if($superglobals->_SERVER = ($variable = uniqid()))
  45. ->then
  46. ->string($superglobals->_SERVER)->isEqualTo($variable)
  47. ->if($superglobals->_GET = ($variable = uniqid()))
  48. ->then
  49. ->string($superglobals->_GET)->isEqualTo($variable)
  50. ->if($superglobals->_POST = ($variable = uniqid()))
  51. ->then
  52. ->string($superglobals->_POST)->isEqualTo($variable)
  53. ->if($superglobals->_FILES = ($variable = uniqid()))
  54. ->then
  55. ->string($superglobals->_FILES)->isEqualTo($variable)
  56. ->if($superglobals->_COOKIE = ($variable = uniqid()))
  57. ->then
  58. ->string($superglobals->_COOKIE)->isEqualTo($variable)
  59. ->if($superglobals->_SESSION = ($variable = uniqid()))
  60. ->then
  61. ->string($superglobals->_SESSION)->isEqualTo($variable)
  62. ->if($superglobals->_REQUEST = ($variable = uniqid()))
  63. ->then
  64. ->string($superglobals->_REQUEST)->isEqualTo($variable)
  65. ->if($superglobals->_ENV = ($variable = uniqid()))
  66. ->then
  67. ->string($superglobals->_ENV)->isEqualTo($variable)
  68. ;
  69. }
  70. }