1010namespace  PHP_CodeSniffer \Tests \Core \Config ;
1111
1212use  PHP_CodeSniffer \Config ;
13- use  PHPUnit \Framework \TestCase ;
14- use  ReflectionProperty ;
13+ use  PHP_CodeSniffer \Tests \Core \Config \AbstractRealConfigTestCase ;
1514
1615/** 
1716 * Tests for the \PHP_CodeSniffer\Config reportWidth value. 
1817 * 
1918 * @covers \PHP_CodeSniffer\Config::__get 
2019 */ 
21- final  class  ReportWidthTest extends  TestCase 
20+ final  class  ReportWidthTest extends  AbstractRealConfigTestCase 
2221{
2322
2423
25-     /** 
26-      * Set static properties in the Config class to prevent tests influencing each other. 
27-      * 
28-      * @return void 
29-      */ 
30-     protected  function  setUp (): void 
31-     {
32-         // Set to the property's default value to clear out potentially set values from other tests. 
33-         self ::setStaticProperty ('executablePaths ' , []);
34- 
35-         // Set to values which prevent the test-runner user's `CodeSniffer.conf` file 
36-         // from being read and influencing the tests. 
37-         self ::setStaticProperty ('configData ' , []);
38-         self ::setStaticProperty ('configDataFile ' , '' );
39- 
40-     }//end setUp() 
41- 
42- 
43-     /** 
44-      * Clean up after each finished test. 
45-      * 
46-      * @return void 
47-      */ 
48-     protected  function  tearDown (): void 
49-     {
50-         $ _SERVER 'argv ' ] = [];
51- 
52-     }//end tearDown() 
53- 
54- 
55-     /** 
56-      * Reset the static properties in the Config class to their true defaults to prevent this class 
57-      * from influencing other tests. 
58-      * 
59-      * @return void 
60-      */ 
61-     public  static  function  tearDownAfterClass (): void 
62-     {
63-         self ::setStaticProperty ('executablePaths ' , []);
64-         self ::setStaticProperty ('configData ' , null );
65-         self ::setStaticProperty ('configDataFile ' , null );
66-         $ _SERVER 'argv ' ] = [];
67- 
68-     }//end tearDownAfterClass() 
69- 
70- 
7124    /** 
7225     * Test that report width without overrules will always be set to a non-0 positive integer. 
7326     * 
@@ -78,7 +31,7 @@ public static function tearDownAfterClass(): void
7831     */ 
7932    public  function  testReportWidthDefault ()
8033    {
81-         $ confignew  Config ();
34+         $ confignew  Config ([ ' --standard=PSR1 ' ] );
8235
8336        // Can't test the exact value as "auto" will resolve differently depending on the machine running the tests. 
8437        $ this assertIsInt ($ configreportWidth , 'Report width is not an integer ' );
@@ -102,9 +55,9 @@ public function testReportWidthWillBeSetFromAutoWhenNotFoundInConfFile()
10255            'show_warnings '     => '0 ' ,
10356        ];
10457
105-         $ this setStaticProperty ('configData ' , $ phpCodeSnifferConfig
58+         $ this setStaticConfigProperty ('configData ' , $ phpCodeSnifferConfig
10659
107-         $ confignew  Config ();
60+         $ confignew  Config ([ ' --standard=PSR1 ' ] );
10861
10962        // Can't test the exact value as "auto" will resolve differently depending on the machine running the tests. 
11063        $ this assertIsInt ($ configreportWidth , 'Report width is not an integer ' );
@@ -129,9 +82,9 @@ public function testReportWidthCanBeSetFromConfFile()
12982            'report_width '      => '120 ' ,
13083        ];
13184
132-         $ this setStaticProperty ('configData ' , $ phpCodeSnifferConfig
85+         $ this setStaticConfigProperty ('configData ' , $ phpCodeSnifferConfig
13386
134-         $ confignew  Config ();
87+         $ confignew  Config ([ ' --standard=PSR1 ' ] );
13588        $ this assertSame (120 , $ configreportWidth );
13689
13790    }//end testReportWidthCanBeSetFromConfFile() 
@@ -149,6 +102,7 @@ public function testReportWidthCanBeSetFromCLI()
149102    {
150103        $ _SERVER 'argv ' ] = [
151104            'phpcs ' ,
105+             '--standard=PSR1 ' ,
152106            '--report-width=100 ' ,
153107        ];
154108
@@ -170,6 +124,7 @@ public function testReportWidthWhenSetFromCLIFirstValuePrevails()
170124    {
171125        $ _SERVER 'argv ' ] = [
172126            'phpcs ' ,
127+             '--standard=PSR1 ' ,
173128            '--report-width=100 ' ,
174129            '--report-width=200 ' ,
175130        ];
@@ -199,10 +154,11 @@ public function testReportWidthSetFromCLIOverrulesConfFile()
199154            'report_width '      => '120 ' ,
200155        ];
201156
202-         $ this setStaticProperty ('configData ' , $ phpCodeSnifferConfig
157+         $ this setStaticConfigProperty ('configData ' , $ phpCodeSnifferConfig
203158
204159        $ cliArgs
205160            'phpcs ' ,
161+             '--standard=PSR1 ' ,
206162            '--report-width=180 ' ,
207163        ];
208164
@@ -221,7 +177,7 @@ public function testReportWidthSetFromCLIOverrulesConfFile()
221177     */ 
222178    public  function  testReportWidthInputHandlingForAuto ()
223179    {
224-         $ confignew  Config ();
180+         $ confignew  Config ([ ' --standard=PSR1 ' ] );
225181        $ configreportWidth  = 'auto ' ;
226182
227183        // Can't test the exact value as "auto" will resolve differently depending on the machine running the tests. 
@@ -244,7 +200,7 @@ public function testReportWidthInputHandlingForAuto()
244200     */ 
245201    public  function  testReportWidthInputHandling ($ value$ expected
246202    {
247-         $ confignew  Config ();
203+         $ confignew  Config ([ ' --standard=PSR1 ' ] );
248204        $ configreportWidth  = $ value
249205
250206        $ this assertSame ($ expected$ configreportWidth );
@@ -301,22 +257,4 @@ public static function dataReportWidthInputHandling()
301257    }//end dataReportWidthInputHandling() 
302258
303259
304-     /** 
305-      * Helper function to set a static property on the Config class. 
306-      * 
307-      * @param string $name  The name of the property to set. 
308-      * @param mixed  $value The value to set the property to. 
309-      * 
310-      * @return void 
311-      */ 
312-     public  static  function  setStaticProperty ($ name$ value
313-     {
314-         $ propertynew  ReflectionProperty ('PHP_CodeSniffer\Config ' , $ name
315-         $ propertysetAccessible (true );
316-         $ propertysetValue (null , $ value
317-         $ propertysetAccessible (false );
318- 
319-     }//end setStaticProperty() 
320- 
321- 
322260}//end class 
0 commit comments