Skip to content

Commit f8705ea

Browse files
authored
Merge pull request Codeception#6027 from mwi-gofore/4.1
Prepend backslash on class constant default values
2 parents c2eadda + a154c10 commit f8705ea

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

src/Codeception/Util/ReflectionHelper.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ public static function getDefaultValue(ReflectionParameter $param)
115115
list($class, $const) = explode('::', $constName);
116116
if (in_array($class, ['self', 'static'])) {
117117
$constName = '\\' . $param->getDeclaringClass()->getName() . '::' . $const;
118+
} elseif (substr($class, 0, 1) !== '\\') {
119+
$constName = '\\' . $constName;
118120
}
119121
}
120122

tests/unit/Codeception/Util/ReflectionHelperTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ public function testGetDefaultValue()
112112
ReflectionHelper::getDefaultValue(new ReflectionParameter(array($object, 'setDebug'), 'flavor'))
113113
);
114114

115+
$this->assertEquals(
116+
'\Codeception\Codecept::VERSION',
117+
ReflectionHelper::getDefaultValue(new ReflectionParameter(array($object, 'setFlavorImportedDefault'), 'flavor'))
118+
);
119+
115120
$this->assertEquals(
116121
PHP_VERSION_ID < 70100 ? 'null' : "''",
117122
ReflectionHelper::getDefaultValue(new ReflectionParameter(array($object, 'setValue'), 0))

tests/unit/Codeception/Util/ReflectionTestClass56.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace Codeception\Util;
33

4+
use Codeception\Codecept;
5+
46
class ReflectionTestClass
57
{
68
const FOO = 'bar';
@@ -48,6 +50,11 @@ static public function setFlavor($flavor = self::FOO)
4850
self::$flavorOfTheWeek = $flavor;
4951
}
5052

53+
public function setFlavorImportedDefault($flavor = Codecept::VERSION)
54+
{
55+
self::$flavorOfTheWeek = $flavor;
56+
}
57+
5158
private function getSecret($s)
5259
{
5360
return sprintf("I'm a %s!", $s);

tests/unit/Codeception/Util/ReflectionTestClass70.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace Codeception\Util;
33

4+
use Codeception\Codecept;
5+
46
class ReflectionTestClass
57
{
68
const FOO = 'bar';
@@ -43,7 +45,12 @@ public function setDebug(Debug $obj, $flavor = self::FOO): self
4345
return $this;
4446
}
4547

46-
static public function setFlavor(string $flavor = self::FOO)
48+
static public function setFlavor(string $flavor = self::FOO): void
49+
{
50+
self::$flavorOfTheWeek = $flavor;
51+
}
52+
53+
public function setFlavorImportedDefault(string $flavor = Codecept::VERSION): void
4754
{
4855
self::$flavorOfTheWeek = $flavor;
4956
}

0 commit comments

Comments
 (0)