Skip to content

Commit 433a186

Browse files
author
plumthedev
committed
write new tests
1 parent 9e97c63 commit 433a186

File tree

2 files changed

+56
-12
lines changed

2 files changed

+56
-12
lines changed

tests/ConfigTest.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* @author Kacper Pruszynski (plumthedev)
66
* @link https://github.com/plumthedev/yii2-php-cs-fixer-config
7-
* @copyright Copyright (c) 2019 plumthedev
7+
* @copyright Copyright (c) 2019 - 2019 plumthedev
88
* @license https://github.com/plumthedev/yii2-php-cs-fixer-config/blob/master/LICENSE
99
* @version 1.0.1
1010
*/
@@ -28,6 +28,11 @@ public function testIsInstanceOfPhpCsFixerConfig()
2828
$this->assertInstanceOf('PhpCsFixer\Config', $this->csFixerConfig);
2929
}
3030

31+
public function testIsInstanceOfYiiCsFixerConfig()
32+
{
33+
$this->assertInstanceOf('yii\cs\YiiConfig', $this->csFixerConfig);
34+
}
35+
3136
public function testHasRules()
3237
{
3338
$this->assertNotEmpty($this->csFixerConfig->getRules());
@@ -52,13 +57,4 @@ public function testHasValidName()
5257
{
5358
$this->assertEquals('yii2-php-cs-fixer-config', $this->csFixerConfig->getName());
5459
}
55-
56-
public function testMergeSuccessfully()
57-
{
58-
$this->csFixerConfig->mergeRules([
59-
'mergedSuccessfully' => true,
60-
]);
61-
$csFixerConfigRules = $this->csFixerConfig->getRules();
62-
$this->assertTrue($csFixerConfigRules['mergedSuccessfully']);
63-
}
6460
}

tests/FinderTest.php

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* @author Kacper Pruszynski (plumthedev)
66
* @link https://github.com/plumthedev/yii2-php-cs-fixer-config
7-
* @copyright Copyright (c) 2019 plumthedev
7+
* @copyright Copyright (c) 2019 - 2019 plumthedev
88
* @license https://github.com/plumthedev/yii2-php-cs-fixer-config/blob/master/LICENSE
99
* @version 1.0.1
1010
*/
@@ -13,6 +13,8 @@
1313

1414
use PHPUnit_Framework_TestCase as TestCase;
1515
use plumthedev\PhpCsFixer\Finder;
16+
use ReflectionClass;
17+
use yii\base\InvalidArgumentException;
1618

1719
class FinderTest extends TestCase
1820
{
@@ -30,6 +32,52 @@ public function testIsInstanceOfPhpCsFixerFinder()
3032

3133
public function testIsExcludingDirs()
3234
{
33-
$this->assertNotEmpty($this->csFixerFinder->yiiProjectExcludePaths);
35+
$this->assertNotEmpty($this->csFixerFinder->yiiAppExclude);
36+
}
37+
38+
public function testIsExcludingYiiAppBasicDirs()
39+
{
40+
$getYiiAppBasicExcludeMethod = self::getMethod('getYiiAppBasicExclude');
41+
$yiiAppBasicExclude = $getYiiAppBasicExcludeMethod->invoke($this->csFixerFinder);
42+
foreach ($yiiAppBasicExclude as $exclude) {
43+
$this->assertContains($exclude, $this->csFixerFinder->getYiiAppExclude());
44+
}
45+
}
46+
47+
public function testIsExcludingYiiAppAdvancedDirs()
48+
{
49+
$getYiiAppAdvancedExcludeMethod = self::getMethod('getYiiAppAdvancedExclude');
50+
$yiiAppAdvancedExclude = $getYiiAppAdvancedExcludeMethod->invoke($this->csFixerFinder);
51+
foreach ($yiiAppAdvancedExclude as $exclude) {
52+
$this->assertContains($exclude, $this->csFixerFinder->getYiiAppExclude());
53+
}
54+
}
55+
56+
public function testExceptionOnNotArraySetter()
57+
{
58+
$this->setExpectedException(InvalidArgumentException::class);
59+
$this->csFixerFinder->setYiiAppExclude('notArray');
60+
}
61+
62+
public function testIsMergingWithDefault()
63+
{
64+
$this->csFixerFinder->setYiiAppExclude(['mergeWithDef']);
65+
$this->assertContains('mergeWithDef', $this->csFixerFinder->getYiiAppExclude());
66+
$this->testIsExcludingYiiAppAdvancedDirs();
67+
$this->testIsExcludingYiiAppBasicDirs();
68+
}
69+
70+
public function testIsNotMergingWitHDefault()
71+
{
72+
$this->csFixerFinder->setYiiAppExclude(['mergeWithDef'], false);
73+
$this->assertCount(1, $this->csFixerFinder->getYiiAppExclude());
74+
}
75+
76+
protected static function getMethod($name)
77+
{
78+
$class = new ReflectionClass('plumthedev\PhpCsFixer\Finder');
79+
$method = $class->getMethod($name);
80+
$method->setAccessible(true);
81+
return $method;
3482
}
3583
}

0 commit comments

Comments
 (0)