3131 */
3232final class ServiceMapBehaviorTest extends TestCase
3333{
34+ /**
35+ * Base path for configuration files used in tests.
36+ */
37+ private const BASE_PATH = __DIR__ . DIRECTORY_SEPARATOR . 'config ' . DIRECTORY_SEPARATOR ;
38+
3439 /**
3540 * @throws ReflectionException if the component definition is invalid or can't be resolved.
3641 */
3742 public function testReturnBehaviorsWhenValidClassIsClassString (): void
3843 {
39- $ ds = DIRECTORY_SEPARATOR ;
40- $ configPath = __DIR__ . "{$ ds }config {$ ds }config.php " ;
41- $ serviceMap = new ServiceMap ($ configPath );
44+ $ serviceMap = new ServiceMap (self ::BASE_PATH . 'phpstan-config.php ' );
4245
4346 $ behaviors = $ serviceMap ->getBehaviorsByClassName (MyComponent::class);
4447
@@ -57,9 +60,7 @@ public function testReturnBehaviorsWhenValidClassIsClassString(): void
5760 */
5861 public function testReturnBehaviorsWhenValidClassIsString (): void
5962 {
60- $ ds = DIRECTORY_SEPARATOR ;
61- $ configPath = __DIR__ . "{$ ds }config {$ ds }config.php " ;
62- $ serviceMap = new ServiceMap ($ configPath );
63+ $ serviceMap = new ServiceMap (self ::BASE_PATH . 'phpstan-config.php ' );
6364
6465 $ behaviors = $ serviceMap ->getBehaviorsByClassName ('yii2\extensions\phpstan\tests\stub\MyComponent ' );
6566
@@ -78,9 +79,7 @@ public function testReturnBehaviorsWhenValidClassIsString(): void
7879 */
7980 public function testReturnEmptyArrayWhenClassHasNotBehaviors (): void
8081 {
81- $ ds = DIRECTORY_SEPARATOR ;
82- $ configPath = __DIR__ . "{$ ds }config {$ ds }config.php " ;
83- $ serviceMap = new ServiceMap ($ configPath );
82+ $ serviceMap = new ServiceMap (self ::BASE_PATH . 'phpstan-config.php ' );
8483
8584 $ behaviors = $ serviceMap ->getBehaviorsByClassName ('NonExistentClass ' );
8685
@@ -96,9 +95,7 @@ public function testReturnEmptyArrayWhenClassHasNotBehaviors(): void
9695 */
9796 public function testReturnEmptyArrayWhenNotBehaviorsConfigured (): void
9897 {
99- $ ds = DIRECTORY_SEPARATOR ;
100- $ configPath = __DIR__ . "{$ ds }config {$ ds }config.php " ;
101- $ serviceMap = new ServiceMap ($ configPath );
98+ $ serviceMap = new ServiceMap (self ::BASE_PATH . 'phpstan-config.php ' );
10299
103100 $ behaviors = $ serviceMap ->getBehaviorsByClassName ('AnyClass ' );
104101
@@ -114,36 +111,29 @@ public function testReturnEmptyArrayWhenNotBehaviorsConfigured(): void
114111 */
115112 public function testThrowExceptionWhenBehaviorDefinitionNotArray (): void
116113 {
117- $ ds = DIRECTORY_SEPARATOR ;
118- $ configPath = __DIR__ . "{$ ds }config {$ ds }behaviors-unsupported-definition-not-array.php " ;
119-
120114 $ this ->expectException (RuntimeException::class);
121115 $ this ->expectExceptionMessage ('Behavior definition for \'MyComponent \' must be an array. ' );
122116
123- new ServiceMap ($ configPath );
117+ new ServiceMap (self :: BASE_PATH . ' behaviors-unsupported-definition-not-array.php ' );
124118 }
125119
126120 /**
127121 * @throws ReflectionException if the component definition is invalid or can't be resolved.
128122 */
129123 public function testThrowExceptionWhenBehaviorIdNotString (): void
130124 {
131- $ ds = DIRECTORY_SEPARATOR ;
132- $ configPath = __DIR__ . "{$ ds }config {$ ds }behaviors-unsupported-id-not-string.php " ;
133-
134125 $ this ->expectException (RuntimeException::class);
135126 $ this ->expectExceptionMessage ('\'Behavior class \': \'ID \' must be a \'string \', got \'integer \'. ' );
136127
137- new ServiceMap ($ configPath );
128+ new ServiceMap (self :: BASE_PATH . ' behaviors-unsupported-id-not-string.php ' );
138129 }
139130
140131 /**
141132 * @throws ReflectionException if the component definition is invalid or can't be resolved.
142133 */
143134 public function testThrowExceptionWhenBehaviorsNotArray (): void
144135 {
145- $ ds = DIRECTORY_SEPARATOR ;
146- $ configPath = __DIR__ . "{$ ds }config {$ ds }behaviors-unsupported-is-not-array.php " ;
136+ $ configPath = self ::BASE_PATH . 'behaviors-unsupported-is-not-array.php ' ;
147137
148138 $ this ->expectException (RuntimeException::class);
149139 $ this ->expectExceptionMessage ("Configuration file ' {$ configPath }' must contain a valid 'behaviors' 'array'. " );
0 commit comments