Skip to content

Commit

Permalink
Merge branch 'master' into mutator/mbstring
Browse files Browse the repository at this point in the history
  • Loading branch information
majkel89 committed Mar 23, 2019
2 parents 7420b4c + fc4a96f commit 4b513a1
Show file tree
Hide file tree
Showing 17 changed files with 223 additions and 52 deletions.
11 changes: 11 additions & 0 deletions .travis.yml
Expand Up @@ -147,6 +147,17 @@ jobs:
INFECTION_PR_FLAGS=$(get-infection-pr-flags);
phpdbg -qrr bin/infection $INFECTION_FLAGS $INFECTION_PR_FLAGS;
- stage: PHPUnit 8 future-proofing
php: 7.2
env: PHPUNIT_BIN='vendor/bin/phpunit'
install:
- composer config --unset platform.php
- composer require --dev phpunit/phpunit:^8 --no-update
- composer update
script:
- if [[ $PHPDBG != 1 ]]; then xdebug-enable; fi
- if [[ $PHPDBG != 1 ]]; then $PHPUNIT_BIN; else phpdbg -qrr $PHPUNIT_BIN; fi

- stage: Deploy
php: 7.2
install:
Expand Down
27 changes: 26 additions & 1 deletion src/Mutator/Arithmetic/Division.php
Expand Up @@ -56,6 +56,31 @@ public function mutate(Node $node)

protected function mutatesNode(Node $node): bool
{
return $node instanceof Node\Expr\BinaryOp\Div;
if (!$node instanceof Node\Expr\BinaryOp\Div) {
return false;
}

if ($this->isNumericOne($node->left) || $this->isNumericOne($node->right)) {
return false;
}

if ($node->left instanceof Node\Expr\UnaryMinus && $this->isNumericOne($node->left->expr)) {
return false;
}

if ($node->right instanceof Node\Expr\UnaryMinus && $this->isNumericOne($node->right->expr)) {
return false;
}

return true;
}

private function isNumericOne(Node $node): bool
{
if ($node instanceof Node\Scalar\LNumber && $node->value === 1) {
return true;
}

return $node instanceof Node\Scalar\DNumber && $node->value === 1.0;
}
}
27 changes: 26 additions & 1 deletion src/Mutator/Arithmetic/Multiplication.php
Expand Up @@ -56,6 +56,31 @@ public function mutate(Node $node)

protected function mutatesNode(Node $node): bool
{
return $node instanceof Node\Expr\BinaryOp\Mul;
if (!$node instanceof Node\Expr\BinaryOp\Mul) {
return false;
}

if ($this->isNumericOne($node->left) || $this->isNumericOne($node->right)) {
return false;
}

if ($node->left instanceof Node\Expr\UnaryMinus && $this->isNumericOne($node->left->expr)) {
return false;
}

if ($node->right instanceof Node\Expr\UnaryMinus && $this->isNumericOne($node->right->expr)) {
return false;
}

return true;
}

private function isNumericOne(Node $node): bool
{
if ($node instanceof Node\Scalar\LNumber && $node->value === 1) {
return true;
}

return $node instanceof Node\Scalar\DNumber && $node->value === 1.0;
}
}
12 changes: 5 additions & 7 deletions tests/AutoReview/ProjectCodeTest.php
Expand Up @@ -246,7 +246,7 @@ public function test_non_extension_points_are_internal(string $className): void
)
);
}
$this->assertNotContains(
$this->assertStringNotContainsString(
'@internal',
$docBlock,
sprintf(
Expand All @@ -258,15 +258,14 @@ public function test_non_extension_points_are_internal(string $className): void
return;
}

$this->assertInternalType(
'string',
$this->assertIsString(
$docBlock,
sprintf(
'The "%s" class is not an extension point, and should be marked as internal.',
$className
)
);
$this->assertContains(
$this->assertStringContainsString(
'@internal',
$docBlock,
sprintf(
Expand Down Expand Up @@ -389,15 +388,14 @@ public function test_all_test_classes_are_marked_internal(string $className): vo
$rc = new \ReflectionClass($className);
$docBlock = $rc->getDocComment();

$this->assertInternalType(
'string',
$this->assertIsString(
$docBlock,
sprintf(
'Test class "%s" must be marked internal.',
$className
)
);
$this->assertContains(
$this->assertStringContainsString(
'@internal',
$rc->getDocComment(),
sprintf(
Expand Down
8 changes: 6 additions & 2 deletions tests/Console/E2ETest.php
Expand Up @@ -78,6 +78,10 @@ protected function setUp(): void
$this->markTestSkipped('This test needs copious amounts of virtual memory. It will fail unless it is allowed to overcommit memory.');
}

if (\version_compare(\PHPUnit\Runner\Version::id(), '8', '>=')) {
$this->markTestSkipped('Most E2E tests use an earlier version of PHPUnit, which is incompatible with PHPUnit 8 and later');
}

// E2E tests usually require to chdir to their location
// Hence we would need to go back to this dir
$this->cwd = getcwd();
Expand Down Expand Up @@ -129,7 +133,7 @@ public function test_it_runs_configure_command_if_no_configuration(): void

$output = $this->runInfection(self::EXPECT_ERROR);

$this->assertContains(ConfigureCommand::NONINTERACTIVE_MODE_ERROR, $output);
$this->assertStringContainsString(ConfigureCommand::NONINTERACTIVE_MODE_ERROR, $output);
}

/**
Expand All @@ -155,7 +159,7 @@ public function e2eTestSuiteDataProvider(): \Generator
continue;
}

yield basename((string) $dirName) => [$dirName];
yield basename((string) $dirName) => [(string) $dirName];
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Console/LogVerbosityTest.php
Expand Up @@ -57,7 +57,7 @@ public function test_it_works_if_verbosity_is_valid(): void
/**
* @dataProvider provideConvertedLogVerbosity
*/
public function test_it_converts_int_version_to_string_version_of_verbosity(int $input, string $output): void
public function test_it_converts_int_version_to_string_version_of_verbosity($input, string $output): void
{
$input = $this->setInputExpectationsWhenItDoesChange($input, $output);
$io = $this->createMock(SymfonyStyle::class);
Expand Down
10 changes: 5 additions & 5 deletions tests/Finder/Exception/FinderExceptionTest.php
Expand Up @@ -48,7 +48,7 @@ public function test_composer_not_found_exception(): void
$exception = FinderException::composerNotFound();

$this->assertInstanceOf(FinderException::class, $exception);
$this->assertContains(
$this->assertStringContainsString(
'Unable to locate a Composer executable on local system',
$exception->getMessage()
);
Expand All @@ -59,7 +59,7 @@ public function test_php_executable_not_found(): void
$exception = FinderException::phpExecutableNotFound();

$this->assertInstanceOf(FinderException::class, $exception);
$this->assertContains(
$this->assertStringContainsString(
'Unable to locate the PHP executable on the local system',
$exception->getMessage()
);
Expand All @@ -70,11 +70,11 @@ public function test_test_framework_not_found(): void
$exception = FinderException::testFrameworkNotFound('framework');

$this->assertInstanceOf(FinderException::class, $exception);
$this->assertContains(
$this->assertStringContainsString(
'Unable to locate a framework executable on local system.',
$exception->getMessage()
);
$this->assertContains(
$this->assertStringContainsString(
'Ensure that framework is installed and available.',
$exception->getMessage()
);
Expand All @@ -85,7 +85,7 @@ public function test_test_custom_path_does_not_exsist(): void
$exception = FinderException::testCustomPathDoesNotExist('framework', 'foo/bar/abc');

$this->assertInstanceOf(FinderException::class, $exception);
$this->assertContains(
$this->assertStringContainsString(
'The custom path to framework was set as "foo/bar/abc"',
$exception->getMessage()
);
Expand Down
2 changes: 1 addition & 1 deletion tests/Finder/TestFrameworkFinderTest.php
Expand Up @@ -157,7 +157,7 @@ public function test_it_adds_vendor_bin_to_path_if_needed(): void

// Vendor bin should be the first item
$pathList = explode(PATH_SEPARATOR, $pathAfterTest);
$this->assertContains('vendor', $pathList[0]);
$this->assertStringContainsString('vendor', $pathList[0]);

$this->assertNotSame($path, $pathAfterTest);

Expand Down
81 changes: 64 additions & 17 deletions tests/Mutator/Arithmetic/DivisionTest.php
Expand Up @@ -50,10 +50,9 @@ public function test_mutator($input, $expected = null): void
$this->doTest($input, $expected);
}

public function provideMutationCases(): array
public function provideMutationCases(): \Generator
{
return [
'It changes regular divison' => [
yield 'It changes regular divison' => [
<<<'PHP'
<?php
Expand All @@ -65,31 +64,79 @@ public function provideMutationCases(): array
$a = 10 * 2;
PHP
,
],
'It does not change division equals' => [
];

yield 'It does not change division equals' => [
<<<'PHP'
<?php
$a = 10;
$a /= 5;
PHP
,
],
];
}

public function test_replaces_division_with_multiplication(): void
{
$code = '<?php 1 / 2;';
$mutations = $this->mutate($code);
yield 'It does not mutate when the left side is 1 to avoid an equivalent mutation' => [
<<<'PHP'
<?php
$expectedMutatedCode = <<<'PHP'
$a = 1 / $b;
PHP
];

yield 'It does not mutate when the right side is 1 to avoid an equivalent mutation' => [
<<<'PHP'
<?php
1 * 2;
PHP;
$a = $b / 1;
PHP
];

yield 'It does not mutate when the left side is -1 to avoid an equivalent mutation' => [
<<<'PHP'
<?php
$a = -1 / $b;
PHP
];

yield 'It does not mutate when the right side is -1 to avoid an equivalent mutation' => [
<<<'PHP'
<?php
$this->assertSame($expectedMutatedCode, $mutations[0]);
$a = $b / -1;
PHP
];

yield 'It does not mutate when the left side is 1.0 to avoid an equivalent mutation' => [
<<<'PHP'
<?php
$a = 1.0 / $b;
PHP
];

yield 'It does not mutate when the right side is 1.0 to avoid an equivalent mutation' => [
<<<'PHP'
<?php
$a = $b / 1.0;
PHP
];

yield 'It does not mutate when the left side is -1.0 to avoid an equivalent mutation' => [
<<<'PHP'
<?php
$a = -1.0 / $b;
PHP
];

yield 'It does not mutate when the right side is -1.0 to avoid an equivalent mutation' => [
<<<'PHP'
<?php
$a = $b / -1.0;
PHP
];
}
}

0 comments on commit 4b513a1

Please sign in to comment.