TestCase.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace tests\_helpers;
  3. class TestCase extends \PHPUnit_Framework_TestCase
  4. {
  5. /**
  6. * Your application config, will be merged with base config when creating application.
  7. * @var array
  8. */
  9. protected $config = array();
  10. /**
  11. * Created application class
  12. * @var string
  13. */
  14. protected $appClass = '\yii\web\Application';
  15. protected function setUp()
  16. {
  17. parent::setUp();
  18. $this->mockApplication();
  19. }
  20. protected function tearDown()
  21. {
  22. $this->destroyApplication();
  23. parent::tearDown();
  24. }
  25. protected function mockApplication()
  26. {
  27. $baseConfig = require(__DIR__.'/../unit/_bootstrap.php');
  28. $config = \yii\helpers\ArrayHelper::merge($baseConfig,$this->config);
  29. new $this->appClass($config);
  30. }
  31. protected function destroyApplication()
  32. {
  33. \Yii::$app = null;
  34. }
  35. /**
  36. * Use this method when you need to dump variables with var_dump function.
  37. * This is caused by the buffering output of the codeception.
  38. * @param mixed $var
  39. */
  40. protected static function varDump($var)
  41. {
  42. ob_start();
  43. var_dump($var);
  44. \Codeception\Util\Debug::debug(ob_get_clean());
  45. }
  46. }