ContextTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: yf
  5. * Date: 2019-01-06
  6. * Time: 23:27
  7. */
  8. namespace EasySwoole\Component\Tests;
  9. use EasySwoole\Component\Context\ContextManager;
  10. use EasySwoole\Component\Tests\Lib\ContextContextItemHandler;
  11. use PHPUnit\Framework\TestCase;
  12. class ContextTest extends TestCase
  13. {
  14. function __construct(?string $name = null, array $data = [], string $dataName = '')
  15. {
  16. ContextManager::getInstance()->registerItemHandler('handler',new ContextContextItemHandler());
  17. parent::__construct($name, $data, $dataName);
  18. }
  19. function testHandler()
  20. {
  21. $object = ContextManager::getInstance()->get('handler');
  22. $this->assertEquals('handler',$object->text);
  23. ContextManager::getInstance()->destroy();
  24. $this->assertEquals(true,$object->destroy);
  25. }
  26. function testSet()
  27. {
  28. ContextManager::getInstance()->set('key1','key1');
  29. $this->assertEquals('key1',ContextManager::getInstance()->get('key1'));
  30. }
  31. function testUnset()
  32. {
  33. ContextManager::getInstance()->set('key1','key1');
  34. ContextManager::getInstance()->unset('key1');
  35. $this->assertEquals(null,ContextManager::getInstance()->get('key1'));
  36. }
  37. function testDestroy()
  38. {
  39. ContextManager::getInstance()->destroy();
  40. $this->assertEquals(null,ContextManager::getInstance()->getContextArray());
  41. }
  42. }