Skip to content

Commit d3acfa2

Browse files
test: Add tests for session property availability in Console and Web Applications. (#43)
1 parent f528c8f commit d3acfa2

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Enh #40: Enhance `PHPStan` analysis for `Behavior` type inference and testing (@terabytesoftw)
1111
- Enh #41: Refactor `PHPDoc` comments for consistency and clarity (@terabytesoftw)
1212
- Bug #42: Move `ApplicationPropertiesClassReflectionExtension` to `property` directory and add testing (@terabytesoftw)
13+
- Enh #43: Add tests for session property availability in `Console` and `Web` `Applications` (@terabytesoftw)
1314

1415
## 0.2.3 June 09, 2025
1516

tests/fixture/data/property/ApplicationConsolePropertiesClassReflectionType.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,23 @@ public function testReturnStringWhenComplexChainedAccess(): void
121121
assertType('string', Yii::$app->request->method);
122122
assertType('string', Yii::$app->response->format);
123123
}
124+
125+
/**
126+
* @throws InvalidConfigException if the configuration is invalid or incomplete.
127+
*
128+
* Session property doesn't exist natively in Yii Console Application.
129+
*/
130+
public function testSessionPropertyNotAvailableInConsoleApplication(): void
131+
{
132+
$app = new Application(['id' => 'testApp']);
133+
134+
Yii::$app = $app;
135+
136+
// @phpstan-ignore-next-line property.notFound
137+
assertType('*ERROR*', $app->session);
138+
// @phpstan-ignore-next-line property.notFound
139+
assertType('*ERROR*', Yii::$app->session);
140+
141+
unset(Yii::$app);
142+
}
124143
}

tests/fixture/data/property/ApplicationWebPropertiesClassReflectionType.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,11 @@ public function testReturnSessionAndIdPropertyFromApplicationWeb(): void
104104
{
105105
$app = new Application(['id' => 'testApp']);
106106

107+
Yii::$app = $app;
108+
107109
assertType(Session::class, $app->session);
108110
assertType('string', $app->id);
111+
assertType(Session::class, Yii::$app->session);
109112
}
110113

111114
/**

0 commit comments

Comments
 (0)