Skip to content

Commit

Permalink
Merge pull request #1086 from MPC-khajiit/fix/1.3/constants
Browse files Browse the repository at this point in the history
Fix: array to string conversion in ConstantsPass [1.3]
  • Loading branch information
davedevelopment committed Jul 29, 2020
2 parents 9b6f117 + 8c654cf commit db6e1dd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
Expand Up @@ -21,7 +21,7 @@ public function apply($code, MockConfiguration $config)

$constantsCode = '';
foreach ($cm as $constant => $value) {
$constantsCode .= sprintf("\n const %s = '%s';\n", $constant, $value);
$constantsCode .= sprintf("\n const %s = %s;\n", $constant, var_export($value, true));
}

$i = strrpos($code, '}');
Expand Down
4 changes: 4 additions & 0 deletions tests/Mockery/Fixtures/ClassWithConstants.php
Expand Up @@ -26,4 +26,8 @@ class ClassWithConstants
const FOO = 'bar';

const X = 1;

const BAZ = [
'qux' => 'quux'
];
}
4 changes: 4 additions & 0 deletions tests/Mockery/MockingClassConstantsTest.php
Expand Up @@ -32,12 +32,16 @@ public function itShouldAllowToMockClassConstants()
'ClassWithConstants' => [
'FOO' => 'baz',
'X' => 2,
'BAZ' => [
'qux' => 'daz'
]
]
]);

$mock = \Mockery::mock('overload:ClassWithConstants');

self::assertEquals('baz', $mock::FOO);
self::assertEquals(2, $mock::X);
self::assertEquals(['qux' => 'daz'], $mock::BAZ);
}
}

0 comments on commit db6e1dd

Please sign in to comment.