|
5 | 5 | namespace yii2\extensions\phpstan\tests\console\data\property;
|
6 | 6 |
|
7 | 7 | use Yii;
|
8 |
| -use yii\console\Application; |
| 8 | +use yii\base\{Security, View}; |
| 9 | +use yii\console\{Application, Controller, ErrorHandler, Request, Response}; |
| 10 | +use yii\db\Connection; |
| 11 | +use yii\i18n\{Formatter, I18N}; |
| 12 | +use yii\log\Dispatcher; |
| 13 | +use yii\mail\MailerInterface; |
| 14 | +use yii\web\{AssetManager, UrlManager}; |
9 | 15 |
|
10 | 16 | use function PHPStan\Testing\assertType;
|
11 | 17 |
|
| 18 | +/** |
| 19 | + * Data provider for property reflection of Yii Console Application properties in PHPStan analysis. |
| 20 | + * |
| 21 | + * Validates type inference and return types for core properties and components of {@see Application} via `Yii::$app`, |
| 22 | + * ensuring that PHPStan correctly recognizes and infers types for all supported application-level properties as if they |
| 23 | + * were natively declared on the application class. |
| 24 | + * |
| 25 | + * These tests cover scenarios including direct property access, component-based properties, nullable and interface |
| 26 | + * typed properties, and type assertions for both native and dynamic attached components, verifying that type assertions |
| 27 | + * match the expected return types for each case. |
| 28 | + * |
| 29 | + * Key features. |
| 30 | + * - Coverage for all documented core console application properties and components. |
| 31 | + * - Ensures compatibility with PHPStan property reflection for Yii console application context. |
| 32 | + * - Type assertion for native, interface, and nullable properties. |
| 33 | + * - Validates correct type inference for all supported property types, including interfaces and union types. |
| 34 | + * |
| 35 | + * @copyright Copyright (C) 2023 Terabytesoftw. |
| 36 | + * @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License. |
| 37 | + */ |
12 | 38 | final class ApplicationPropertiesClassReflectionType
|
13 | 39 | {
|
14 | 40 | public function testReturnApplicationInstanceFromYiiApp(): void
|
15 | 41 | {
|
16 | 42 | assertType(Application::class, Yii::$app);
|
17 | 43 | }
|
| 44 | + |
| 45 | + public function testReturnAssetManagerFromComponent(): void |
| 46 | + { |
| 47 | + assertType(AssetManager::class, Yii::$app->assetManager); |
| 48 | + } |
| 49 | + |
| 50 | + public function testReturnAuthManagerFromComponent(): void |
| 51 | + { |
| 52 | + assertType('yii\rbac\ManagerInterface|null', Yii::$app->authManager); |
| 53 | + } |
| 54 | + |
| 55 | + public function testReturnStringFromBasePathProperty(): void |
| 56 | + { |
| 57 | + assertType('string', Yii::$app->basePath); |
| 58 | + } |
| 59 | + |
| 60 | + public function testReturnCacheFromComponent(): void |
| 61 | + { |
| 62 | + assertType('yii\caching\CacheInterface|null', Yii::$app->cache); |
| 63 | + } |
| 64 | + |
| 65 | + public function testReturnStringFromCharsetProperty(): void |
| 66 | + { |
| 67 | + assertType('string', Yii::$app->charset); |
| 68 | + } |
| 69 | + |
| 70 | + public function testReturnControllerFromProperty(): void |
| 71 | + { |
| 72 | + assertType(Controller::class, Yii::$app->controller); |
| 73 | + } |
| 74 | + |
| 75 | + public function testReturnStringFromControllerNamespaceProperty(): void |
| 76 | + { |
| 77 | + assertType('string', Yii::$app->controllerNamespace); |
| 78 | + } |
| 79 | + |
| 80 | + public function testReturnDbFromComponent(): void |
| 81 | + { |
| 82 | + assertType(Connection::class, Yii::$app->db); |
| 83 | + } |
| 84 | + |
| 85 | + public function testReturnStringFromDefaultRouteProperty(): void |
| 86 | + { |
| 87 | + assertType('string', Yii::$app->defaultRoute); |
| 88 | + } |
| 89 | + |
| 90 | + public function testReturnBoolFromEnableCoreCommandsProperty(): void |
| 91 | + { |
| 92 | + assertType('bool', Yii::$app->enableCoreCommands); |
| 93 | + } |
| 94 | + |
| 95 | + public function testReturnErrorHandlerFromComponent(): void |
| 96 | + { |
| 97 | + assertType(ErrorHandler::class, Yii::$app->errorHandler); |
| 98 | + } |
| 99 | + |
| 100 | + public function testReturnFormatterFromComponent(): void |
| 101 | + { |
| 102 | + assertType(Formatter::class, Yii::$app->formatter); |
| 103 | + } |
| 104 | + |
| 105 | + public function testReturnI18nFromComponent(): void |
| 106 | + { |
| 107 | + assertType(I18N::class, Yii::$app->i18n); |
| 108 | + } |
| 109 | + |
| 110 | + public function testReturnStringFromLanguageProperty(): void |
| 111 | + { |
| 112 | + assertType('string', Yii::$app->language); |
| 113 | + } |
| 114 | + |
| 115 | + public function testReturnLogFromComponent(): void |
| 116 | + { |
| 117 | + assertType(Dispatcher::class, Yii::$app->log); |
| 118 | + } |
| 119 | + |
| 120 | + public function testReturnMailerFromComponent(): void |
| 121 | + { |
| 122 | + assertType(MailerInterface::class, Yii::$app->mailer); |
| 123 | + } |
| 124 | + |
| 125 | + public function testReturnStringFromNameProperty(): void |
| 126 | + { |
| 127 | + assertType('string', Yii::$app->name); |
| 128 | + } |
| 129 | + |
| 130 | + public function testReturnRequestFromComponent(): void |
| 131 | + { |
| 132 | + assertType(Request::class, Yii::$app->request); |
| 133 | + } |
| 134 | + |
| 135 | + public function testReturnResponseFromComponent(): void |
| 136 | + { |
| 137 | + assertType(Response::class, Yii::$app->response); |
| 138 | + } |
| 139 | + |
| 140 | + public function testReturnStringFromRuntimePathProperty(): void |
| 141 | + { |
| 142 | + assertType('string', Yii::$app->runtimePath); |
| 143 | + } |
| 144 | + |
| 145 | + public function testReturnSecurityFromComponent(): void |
| 146 | + { |
| 147 | + assertType(Security::class, Yii::$app->security); |
| 148 | + } |
| 149 | + |
| 150 | + public function testReturnStringFromSourceLanguageProperty(): void |
| 151 | + { |
| 152 | + assertType('string', Yii::$app->sourceLanguage); |
| 153 | + } |
| 154 | + |
| 155 | + public function testReturnStringFromTimeZoneProperty(): void |
| 156 | + { |
| 157 | + assertType('string', Yii::$app->timeZone); |
| 158 | + } |
| 159 | + |
| 160 | + public function testReturnStringFromUniqueIdProperty(): void |
| 161 | + { |
| 162 | + assertType('string', Yii::$app->uniqueId); |
| 163 | + } |
| 164 | + |
| 165 | + public function testReturnUrlManagerFromComponent(): void |
| 166 | + { |
| 167 | + assertType(UrlManager::class, Yii::$app->urlManager); |
| 168 | + } |
| 169 | + |
| 170 | + public function testReturnStringFromVendorPathProperty(): void |
| 171 | + { |
| 172 | + assertType('string', Yii::$app->vendorPath); |
| 173 | + } |
| 174 | + |
| 175 | + public function testReturnViewFromComponent(): void |
| 176 | + { |
| 177 | + assertType(View::class, Yii::$app->view); |
| 178 | + } |
18 | 179 | }
|
0 commit comments