Skip to content

Commit d786b78

Browse files
authored
Helper independent (#14050)
* Made sure most helpers are independent of Yii::$app * Made sure most validators are independent of Yii::$app
1 parent 6792099 commit d786b78

23 files changed

+99
-19
lines changed

tests/framework/helpers/ArrayHelperTest.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ class ArrayHelperTest extends TestCase
4444
protected function setUp()
4545
{
4646
parent::setUp();
47-
$this->mockApplication();
47+
48+
// destroy application, Helper must work without Yii::$app
49+
$this->destroyApplication();
4850
}
4951

5052
public function testToArray()
@@ -267,6 +269,7 @@ public function testMultisortUseSort()
267269
$sort = new Sort([
268270
'attributes' => ['name', 'age'],
269271
'defaultOrder' => ['name' => SORT_ASC],
272+
'params' => [],
270273
]);
271274
$orders = $sort->getOrders();
272275

@@ -284,6 +287,7 @@ public function testMultisortUseSort()
284287
$sort = new Sort([
285288
'attributes' => ['name', 'age'],
286289
'defaultOrder' => ['name' => SORT_ASC, 'age' => SORT_DESC],
290+
'params' => [],
287291
]);
288292
$orders = $sort->getOrders();
289293

tests/framework/helpers/ConsoleTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
*/
1313
class ConsoleTest extends TestCase
1414
{
15+
protected function setUp()
16+
{
17+
parent::setUp();
18+
19+
// destroy application, Helper must work without Yii::$app
20+
$this->destroyApplication();
21+
}
22+
1523
public function testStripAnsiFormat()
1624
{
1725
ob_start();

tests/framework/helpers/FileHelperTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@ public function setUp()
3333
*/
3434
$this->markTestInComplete('Unit tests runtime directory should be local!');
3535
}
36+
37+
parent::setUp();
38+
39+
// destroy application, Helper must work without Yii::$app
40+
$this->destroyApplication();
3641
}
3742

43+
3844
public function tearDown()
3945
{
4046
$this->removeDir($this->testFilePath);

tests/framework/helpers/InflectorTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
*/
1111
class InflectorTest extends TestCase
1212
{
13+
protected function setUp()
14+
{
15+
parent::setUp();
16+
17+
// destroy application, Helper must work without Yii::$app
18+
$this->destroyApplication();
19+
}
20+
1321
public function testPluralize()
1422
{
1523
$testData = [

tests/framework/helpers/JsonTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
*/
1515
class JsonTest extends TestCase
1616
{
17+
protected function setUp()
18+
{
19+
parent::setUp();
20+
21+
// destroy application, Helper must work without Yii::$app
22+
$this->destroyApplication();
23+
}
24+
1725
public function testEncode()
1826
{
1927
// basic data encoding

tests/framework/helpers/MarkdownTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
*/
1313
class MarkdownTest extends TestCase
1414
{
15+
protected function setUp()
16+
{
17+
parent::setUp();
18+
19+
// destroy application, Helper must work without Yii::$app
20+
$this->destroyApplication();
21+
}
22+
1523
public function testOriginalFlavor()
1624
{
1725
$text = <<<TEXT

tests/framework/helpers/VarDumperTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
*/
1111
class VarDumperTest extends TestCase
1212
{
13+
protected function setUp()
14+
{
15+
parent::setUp();
16+
17+
// destroy application, Helper must work without Yii::$app
18+
$this->destroyApplication();
19+
}
20+
1321
public function testDumpIncompleteObject()
1422
{
1523
$serializedObj = 'O:16:"nonExistingClass":0:{}';

tests/framework/validators/BooleanValidatorTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ class BooleanValidatorTest extends TestCase
1414
protected function setUp()
1515
{
1616
parent::setUp();
17-
$this->mockApplication();
17+
18+
// destroy application, Validator must work without Yii::$app
19+
$this->destroyApplication();
1820
}
1921

2022
public function testValidateValue()

tests/framework/validators/CompareValidatorTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ class CompareValidatorTest extends TestCase
1414
protected function setUp()
1515
{
1616
parent::setUp();
17-
$this->mockApplication();
17+
18+
// destroy application, Validator must work without Yii::$app
19+
$this->destroyApplication();
1820
}
1921

2022
public function testValidateValueException()

tests/framework/validators/DefaultValueValidatorTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ class DefaultValueValidatorTest extends TestCase
1313
protected function setUp()
1414
{
1515
parent::setUp();
16-
$this->mockApplication();
16+
17+
// destroy application, Validator must work without Yii::$app
18+
$this->destroyApplication();
1719
}
1820

1921
public function testValidateAttribute()

tests/framework/validators/EachValidatorTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ class EachValidatorTest extends TestCase
1414
protected function setUp()
1515
{
1616
parent::setUp();
17-
$this->mockApplication();
17+
18+
// destroy application, Validator must work without Yii::$app
19+
$this->destroyApplication();
1820
}
1921

2022
public function testArrayFormat()

tests/framework/validators/EmailValidatorTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ class EmailValidatorTest extends TestCase
1313
protected function setUp()
1414
{
1515
parent::setUp();
16-
$this->mockApplication();
16+
17+
// destroy application, Validator must work without Yii::$app
18+
$this->destroyApplication();
1719
}
1820

1921
public function testValidateValue()

tests/framework/validators/ExistValidatorTest.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414

1515
abstract class ExistValidatorTest extends DatabaseTestCase
1616
{
17-
public function setUp()
17+
protected function setUp()
1818
{
1919
parent::setUp();
20-
$this->mockApplication();
20+
21+
// destroy application, Validator must work without Yii::$app
22+
$this->destroyApplication();
2123
ActiveRecord::$db = $this->getConnection();
2224
}
2325

tests/framework/validators/FileValidatorTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
*/
1515
class FileValidatorTest extends TestCase
1616
{
17-
public function setUp()
17+
protected function setUp()
1818
{
19+
parent::setUp();
1920
$this->mockApplication();
2021
}
2122

tests/framework/validators/FilterValidatorTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ class FilterValidatorTest extends TestCase
1414
protected function setUp()
1515
{
1616
parent::setUp();
17-
$this->mockApplication();
17+
// destroy application, Validator must work without Yii::$app
18+
$this->destroyApplication();
1819
}
1920

2021
public function testAssureExceptionOnInit()

tests/framework/validators/IpValidatorTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ class IpValidatorTest extends TestCase
1414
protected function setUp()
1515
{
1616
parent::setUp();
17-
$this->mockApplication();
17+
// destroy application, Validator must work without Yii::$app
18+
$this->destroyApplication();
1819
}
1920

2021
public function testInitException()

tests/framework/validators/NumberValidatorTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ private function restoreLocale()
4646
protected function setUp()
4747
{
4848
parent::setUp();
49-
$this->mockApplication();
49+
5050
$this->oldLocale = setlocale(LC_NUMERIC, 0);
51+
52+
// destroy application, Validator must work without Yii::$app
53+
$this->destroyApplication();
5154
}
5255

5356
public function testEnsureMessageOnInit()

tests/framework/validators/RangeValidatorTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ class RangeValidatorTest extends TestCase
1414
protected function setUp()
1515
{
1616
parent::setUp();
17-
$this->mockApplication();
17+
18+
// destroy application, Validator must work without Yii::$app
19+
$this->destroyApplication();
1820
}
1921

2022
public function testInitException()

tests/framework/validators/RegularExpressionValidatorTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ class RegularExpressionValidatorTest extends TestCase
1414
protected function setUp()
1515
{
1616
parent::setUp();
17-
$this->mockApplication();
17+
18+
// destroy application, Validator must work without Yii::$app
19+
$this->destroyApplication();
1820
}
1921

2022
public function testValidateValue()

tests/framework/validators/RequiredValidatorTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ class RequiredValidatorTest extends TestCase
1313
protected function setUp()
1414
{
1515
parent::setUp();
16-
$this->mockApplication();
16+
17+
// destroy application, Validator must work without Yii::$app
18+
$this->destroyApplication();
1719
}
1820

1921
public function testValidateValueWithDefaults()

tests/framework/validators/UniqueValidatorTest.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616

1717
abstract class UniqueValidatorTest extends DatabaseTestCase
1818
{
19-
public function setUp()
19+
protected function setUp()
2020
{
2121
parent::setUp();
22-
$this->mockApplication();
2322
ActiveRecord::$db = $this->getConnection();
23+
24+
// destroy application, Validator must work without Yii::$app
25+
$this->destroyApplication();
2426
}
2527

2628
public function testAssureMessageSetOnInit()

tests/framework/validators/UrlValidatorTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ class UrlValidatorTest extends TestCase
1414
protected function setUp()
1515
{
1616
parent::setUp();
17-
$this->mockApplication();
17+
18+
// destroy application, Validator must work without Yii::$app
19+
$this->destroyApplication();
1820
}
1921

2022
public function testValidateValue()

tests/framework/validators/ValidatorTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ class ValidatorTest extends TestCase
1717
protected function setUp()
1818
{
1919
parent::setUp();
20-
$this->mockApplication();
20+
21+
// destroy application, Validator must work without Yii::$app
22+
$this->destroyApplication();
2123
}
2224

2325
protected function getTestModel($additionalAttributes = [])

0 commit comments

Comments
 (0)