TestCase.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yiiunit\twig;
  8. use yii\di\Container;
  9. use yii\helpers\ArrayHelper;
  10. use Yii;
  11. /**
  12. * This is the base class for all yii framework unit tests.
  13. */
  14. abstract class TestCase extends \PHPUnit\Framework\TestCase
  15. {
  16. /**
  17. * Clean up after test.
  18. * By default the application created with [[mockApplication]] will be destroyed.
  19. */
  20. protected function tearDown()
  21. {
  22. parent::tearDown();
  23. $this->destroyApplication();
  24. }
  25. protected function mockWebApplication($config = [], $appClass = '\yii\web\Application')
  26. {
  27. new $appClass(ArrayHelper::merge([
  28. 'id' => 'testapp',
  29. 'basePath' => __DIR__,
  30. 'vendorPath' => dirname(__DIR__) . '/vendor',
  31. 'aliases' => [
  32. '@bower' => '@vendor/bower-asset',
  33. '@npm' => '@vendor/npm-asset',
  34. ],
  35. 'components' => [
  36. 'request' => [
  37. 'cookieValidationKey' => 'wefJDF8sfdsfSDefwqdxj9oq',
  38. 'scriptFile' => __DIR__ .'/index.php',
  39. 'scriptUrl' => '/index.php',
  40. ],
  41. ]
  42. ], $config));
  43. }
  44. /**
  45. * Destroys application in Yii::$app by setting it to null.
  46. */
  47. protected function destroyApplication()
  48. {
  49. Yii::$app = null;
  50. Yii::$container = new Container();
  51. }
  52. }