Skip to content
This repository has been archived by the owner on Mar 30, 2018. It is now read-only.

Commit

Permalink
Mutate only methods, no functions (#201)
Browse files Browse the repository at this point in the history
* Mutate only methods, no functions

According to @MarkRedeman, only methods should be mutated right now and
function support is pending. `$inMethod` was set to `true` for functions
as well, because it didn't check whether it's inside a class.

* Fix iShouldSeeContaining and version feature test

Output changed in symfony/console@324d1c1.

* Make real fatal error for PHP 7

A bad method call is an exception starting with PHP 7, not a fatal error anymore.

* E_USER_ERROR isn't a real fatal, use require instead

* Update branch for review; add note to README
  • Loading branch information
kelunik authored and padraic committed May 13, 2017
1 parent 21a582d commit 8ee0e7e
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,9 @@ Humbug implements a basic suite of Mutators, which essentially tells us when a
particular PHP token can be mutated, and also apply that mutation to an array
of tokens.

Note: Source code held within functions (rather than class methods) is not mutated
at this time.

Binary Arithmetic:

| Original | Mutated | Original | Mutated |
Expand Down
2 changes: 1 addition & 1 deletion features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function iShouldSee(PyStringNode $string)
*/
public function iShouldSeeContaining(PyStringNode $string)
{
if (!preg_match('/' . preg_quote((string) $string) . '/', $this->appTester->getDisplay())) {
if (!preg_match('/' . preg_quote((string) $string, '/') . '/', $this->appTester->getDisplay())) {
throw new \RuntimeException(sprintf(
'Output did not match expected pattern:%s%s', PHP_EOL, $this->appTester->getDisplay()
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Feature: Use Humbug
$foo = new Foo;
$r = $foo->add(2, 1);
// emulate error
if ($r !== 3) $foo->bar();
if ($r !== 3) require __DIR__ . '/this.does.not.exist.xyz';
$this->assertEquals(3, $r);
}
}
Expand Down
2 changes: 1 addition & 1 deletion features/version.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Feature: Developer runs Humbug with --version option
Scenario: View Humbug version
Given I am in any directory
When I run humbug with "--version"
Then I should see:
Then I should see output containing:
"""
_ _ _
| || |_ _ _ __ | |__ _ _ __ _
Expand Down
2 changes: 1 addition & 1 deletion src/Mutable.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function generate()
}

//TODO: handle whitespace!
if (is_array($token) && $token[0] == T_FUNCTION) {
if (is_array($token) && $token[0] == T_FUNCTION && '???' !== $className) {
if (!isset($tokens[$index+2][1])) {
continue; // ignore closure
}
Expand Down

0 comments on commit 8ee0e7e

Please sign in to comment.