From 58083f6ed0197f80b91647a339d51cd42bd332ab Mon Sep 17 00:00:00 2001 From: Michael Bodnarchuk Date: Wed, 31 Jul 2013 22:39:13 +0300 Subject: [PATCH 1/3] A simple patch to get AspectMock and Go Aop working with Yii2 This is a very tiny patch that changes nothing in code logic, but is required to get [AspectMock](https://github.com/Codeception/AspectMock) and Go Aop working with Yii2. Go Aop is processing all `include` and `require` directives, replacing them with its filters. Unfortunately it doesn't play well with one-liners. So I had to break the code into few lines to get that working. I was trying to fix this issue in [Go Aop](https://github.com/lisachenko/go-aop-php/pull/78) but looks like, the only option is to fix that in Yii2. AspectMock can dramaticly improve unit testing in Yii2, and I plan to do a blogpost with tutorial about it. --- framework/yii/helpers/SecurityBase.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/framework/yii/helpers/SecurityBase.php b/framework/yii/helpers/SecurityBase.php index 9b743c4..69f7ee8 100644 --- a/framework/yii/helpers/SecurityBase.php +++ b/framework/yii/helpers/SecurityBase.php @@ -120,7 +120,10 @@ class SecurityBase static $keys; $keyFile = Yii::$app->getRuntimePath() . '/keys.php'; if ($keys === null) { - $keys = is_file($keyFile) ? require($keyFile) : array(); + $keys = array(); + if (is_file($keyFile)) { + $keys = require($keyFile); + } } if (!isset($keys[$name])) { $keys[$name] = static::generateRandomKey($length); From 2a08297ac836794bd848ddb962bdf9141da40cf6 Mon Sep 17 00:00:00 2001 From: davert Date: Wed, 31 Jul 2013 22:47:45 +0300 Subject: [PATCH 2/3] formatting fix --- framework/yii/helpers/SecurityBase.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/yii/helpers/SecurityBase.php b/framework/yii/helpers/SecurityBase.php index 69f7ee8..ca7978d 100644 --- a/framework/yii/helpers/SecurityBase.php +++ b/framework/yii/helpers/SecurityBase.php @@ -120,10 +120,10 @@ class SecurityBase static $keys; $keyFile = Yii::$app->getRuntimePath() . '/keys.php'; if ($keys === null) { - $keys = array(); + $keys = array(); if (is_file($keyFile)) { - $keys = require($keyFile); - } + $keys = require($keyFile); + } } if (!isset($keys[$name])) { $keys[$name] = static::generateRandomKey($length); From 7f2d2da52c476143cd270d9e73345ff26a841c7c Mon Sep 17 00:00:00 2001 From: davert Date: Wed, 31 Jul 2013 23:01:11 +0300 Subject: [PATCH 3/3] formatting fix --- framework/yii/helpers/SecurityBase.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/yii/helpers/SecurityBase.php b/framework/yii/helpers/SecurityBase.php index ca7978d..05b2682 100644 --- a/framework/yii/helpers/SecurityBase.php +++ b/framework/yii/helpers/SecurityBase.php @@ -120,10 +120,10 @@ class SecurityBase static $keys; $keyFile = Yii::$app->getRuntimePath() . '/keys.php'; if ($keys === null) { - $keys = array(); + $keys = array(); if (is_file($keyFile)) { - $keys = require($keyFile); - } + $keys = require($keyFile); + } } if (!isset($keys[$name])) { $keys[$name] = static::generateRandomKey($length);