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 */
1313
1414use PHPUnit_Framework_TestCase as TestCase ;
1515use plumthedev \PhpCsFixer \Finder ;
16+ use ReflectionClass ;
17+ use yii \base \InvalidArgumentException ;
1618
1719class 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