destroyApplication(); } /** * Populates Yii::$app with a new application * The application will be destroyed on tearDown() automatically. * @param array $config The application configuration, if needed * @param string $appClass name of the application class to create */ protected function mockApplication($config = [], $appClass = '\yii\console\Application') { new $appClass(ArrayHelper::merge([ 'id' => 'testapp', 'basePath' => __DIR__, 'vendorPath' => $this->getVendorPath(), ], $config)); } protected function mockWebApplication($config = [], $appClass = '\yii\web\Application') { new $appClass(ArrayHelper::merge([ 'id' => 'testapp', 'basePath' => __DIR__, 'vendorPath' => $this->getVendorPath(), 'components' => [ 'request' => [ 'cookieValidationKey' => 'wefJDF8sfdsfSDefwqdxj9oq', 'scriptFile' => __DIR__ . '/index.php', 'scriptUrl' => '/index.php', ], ] ], $config)); } protected function getVendorPath() { $vendor = dirname(dirname(__DIR__)) . '/vendor'; if (!is_dir($vendor)) { $vendor = dirname(dirname(dirname(dirname(__DIR__)))); } return $vendor; } /** * Destroys application in Yii::$app by setting it to null. */ protected function destroyApplication() { if (\Yii::$app && \Yii::$app->has('session', true)) { \Yii::$app->session->close(); } \Yii::$app = null; } /** * Asserting two strings equality ignoring line endings * @param string $expected * @param string $actual */ protected function assertEqualsWithoutLE($expected, $actual) { $expected = str_replace("\r\n", "\n", $expected); $actual = str_replace("\r\n", "\n", $actual); $this->assertEquals($expected, $actual); } protected function invokeMethod($object, $method, $args = []) { $reflection = new \ReflectionClass($object->className()); $method = $reflection->getMethod($method); $method->setAccessible(true); return $method->invokeArgs($object, $args); } }