11<?php
2+
3+ declare (strict_types=1 );
24/**
35 * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
46 * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
79
810namespace Tests \Core \Command \Config \App ;
911
10- use OC \AppConfig ;
1112use OC \Core \Command \Config \App \GetConfig ;
1213use OCP \Exceptions \AppConfigUnknownKeyException ;
14+ use OCP \IAppConfig ;
15+ use PHPUnit \Framework \MockObject \MockObject ;
16+ use Symfony \Component \Console \Command \Command ;
1317use Symfony \Component \Console \Input \InputInterface ;
1418use Symfony \Component \Console \Output \OutputInterface ;
1519use Test \TestCase ;
1620
1721class GetConfigTest extends TestCase {
18- /** @var \PHPUnit\Framework\MockObject\MockObject */
19- protected $ config ;
20-
21- /** @var \PHPUnit\Framework\MockObject\MockObject */
22- protected $ consoleInput ;
23- /** @var \PHPUnit\Framework\MockObject\MockObject */
24- protected $ consoleOutput ;
25-
26- /** @var \Symfony\Component\Console\Command\Command */
27- protected $ command ;
22+ protected IAppConfig &MockObject $ appConfig ;
23+ protected InputInterface &MockObject $ consoleInput ;
24+ protected OutputInterface &MockObject $ consoleOutput ;
25+ protected Command $ command ;
2826
2927 protected function setUp (): void {
3028 parent ::setUp ();
3129
32- $ config = $ this ->config = $ this ->getMockBuilder (AppConfig::class)
33- ->disableOriginalConstructor ()
34- ->getMock ();
35- $ this ->consoleInput = $ this ->getMockBuilder (InputInterface::class)->getMock ();
36- $ this ->consoleOutput = $ this ->getMockBuilder (OutputInterface::class)->getMock ();
30+ $ this ->appConfig = $ this ->createMock (IAppConfig::class);
31+ $ this ->consoleInput = $ this ->createMock (InputInterface::class);
32+ $ this ->consoleOutput = $ this ->createMock (OutputInterface::class);
3733
38- /** @var \OCP\IAppConfig $config */
39- $ this ->command = new GetConfig ($ config );
34+ $ this ->command = new GetConfig ($ this ->appConfig );
4035 }
4136
4237
43- public function getData () {
38+ public static function dataGet (): array {
4439 return [
4540 // String output as json
4641 ['name ' , 'newvalue ' , true , null , false , 'json ' , 0 , json_encode ('newvalue ' )],
@@ -83,29 +78,20 @@ public function getData() {
8378 }
8479
8580 /**
86- * @dataProvider getData
87- *
88- * @param string $configName
89- * @param mixed $value
90- * @param bool $configExists
91- * @param mixed $defaultValue
92- * @param bool $hasDefault
93- * @param string $outputFormat
94- * @param int $expectedReturn
95- * @param string $expectedMessage
81+ * @dataProvider dataGet
9682 */
97- public function testGet ($ configName , $ value , $ configExists , $ defaultValue , $ hasDefault , $ outputFormat , $ expectedReturn , $ expectedMessage ): void {
83+ public function testGet (string $ configName , mixed $ value , bool $ configExists , mixed $ defaultValue , bool $ hasDefault , string $ outputFormat , int $ expectedReturn , ? string $ expectedMessage ): void {
9884 if (!$ expectedReturn ) {
9985 if ($ configExists ) {
100- $ this ->config ->expects ($ this ->once ())
86+ $ this ->appConfig ->expects ($ this ->once ())
10187 ->method ('getDetails ' )
10288 ->with ('app-name ' , $ configName )
10389 ->willReturn (['value ' => $ value ]);
10490 }
10591 }
10692
10793 if (!$ configExists ) {
108- $ this ->config ->expects ($ this ->once ())
94+ $ this ->appConfig ->expects ($ this ->once ())
10995 ->method ('getDetails ' )
11096 ->with ('app-name ' , $ configName )
11197 ->willThrowException (new AppConfigUnknownKeyException ());
@@ -117,14 +103,12 @@ public function testGet($configName, $value, $configExists, $defaultValue, $hasD
117103 ['app ' , 'app-name ' ],
118104 ['name ' , $ configName ],
119105 ]);
120- $ this ->consoleInput ->expects ($ this ->any ())
121- ->method ('getOption ' )
106+ $ this ->consoleInput ->method ('getOption ' )
122107 ->willReturnMap ([
123108 ['default-value ' , $ defaultValue ],
124109 ['output ' , $ outputFormat ],
125110 ]);
126- $ this ->consoleInput ->expects ($ this ->any ())
127- ->method ('hasParameterOption ' )
111+ $ this ->consoleInput ->method ('hasParameterOption ' )
128112 ->willReturnMap ([
129113 ['--output ' , false , true ],
130114 ['--default-value ' , false , $ hasDefault ],
@@ -134,16 +118,15 @@ public function testGet($configName, $value, $configExists, $defaultValue, $hasD
134118 global $ output ;
135119
136120 $ output = '' ;
137- $ this ->consoleOutput ->expects ($ this ->any ())
138- ->method ('writeln ' )
121+ $ this ->consoleOutput ->method ('writeln ' )
139122 ->willReturnCallback (function ($ value ) {
140123 global $ output ;
141124 $ output .= $ value . "\n" ;
142125 return $ output ;
143126 });
144127 }
145128
146- $ this ->assertSame ($ expectedReturn , $ this -> invokePrivate ($ this ->command , 'execute ' , [$ this ->consoleInput , $ this ->consoleOutput ]));
129+ $ this ->assertSame ($ expectedReturn , self :: invokePrivate ($ this ->command , 'execute ' , [$ this ->consoleInput , $ this ->consoleOutput ]));
147130
148131 if ($ expectedMessage !== null ) {
149132 global $ output ;
0 commit comments