Skip to content

Commit

Permalink
removing isset where ?? is sufficient
Browse files Browse the repository at this point in the history
uniting blocks that do no longer need to be separated in php7
replacing the last few array() with []
  • Loading branch information
Idrinth authored and sebastianbergmann committed Jul 9, 2018
1 parent c43445d commit 159a008
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 57 deletions.
53 changes: 28 additions & 25 deletions src/Framework/MockObject/Generator.php
Expand Up @@ -398,35 +398,38 @@ public function generate($type, array $methods = null, $mockClassName = '', $cal
\sort($type);
}

if ($mockClassName === '') {
$key = \md5(
\is_array($type) ? \implode('_', $type) : $type .
\serialize($methods) .
\serialize($callOriginalClone) .
\serialize($cloneArguments) .
\serialize($callOriginalMethods)
if ($mockClassName !== '') {
return $this->generateMock(
$type,
$methods,
$mockClassName,
$callOriginalClone,
$callAutoload,
$cloneArguments,
$callOriginalMethods
);

if (isset(self::$cache[$key])) {
return self::$cache[$key];
}
}

$mock = $this->generateMock(
$type,
$methods,
$mockClassName,
$callOriginalClone,
$callAutoload,
$cloneArguments,
$callOriginalMethods
$key = \md5(
\is_array($type) ? \implode('_', $type) : $type .
\serialize($methods) .
\serialize($callOriginalClone) .
\serialize($cloneArguments) .
\serialize($callOriginalMethods)
);

if (isset($key)) {
self::$cache[$key] = $mock;
if (!isset(self::$cache[$key])) {
self::$cache[$key] = $this->generateMock(
$type,
$methods,
$mockClassName,
$callOriginalClone,
$callAutoload,
$cloneArguments,
$callOriginalMethods
);
}

return $mock;
return self::$cache[$key];
}

/**
Expand Down Expand Up @@ -485,13 +488,13 @@ public function generateClassFromWsdl($wsdlFile, $className, array $methods = []
}
}

$optionsBuffer = 'array(';
$optionsBuffer = '[';

foreach ($options as $key => $value) {
$optionsBuffer .= $key . ' => ' . $value;
}

$optionsBuffer .= ')';
$optionsBuffer .= ']';

$classTemplate = $this->getTemplate('wsdl_class.tpl');
$namespace = '';
Expand Down
6 changes: 3 additions & 3 deletions src/Framework/MockObject/Matcher/ConsecutiveParameters.php
Expand Up @@ -88,9 +88,7 @@ public function verify(): void
*/
private function verifyInvocation(BaseInvocation $invocation, $callIndex): void
{
if (isset($this->parameterGroups[$callIndex])) {
$parameters = $this->parameterGroups[$callIndex];
} else {
if (!isset($this->parameterGroups[$callIndex])) {
// no parameter assertion for this call index
return;
}
Expand All @@ -101,6 +99,8 @@ private function verifyInvocation(BaseInvocation $invocation, $callIndex): void
);
}

$parameters = $this->parameterGroups[$callIndex];

if (\count($invocation->getParameters()) < \count($parameters)) {
throw new ExpectationFailedException(
\sprintf(
Expand Down
8 changes: 2 additions & 6 deletions src/Framework/TestCase.php
Expand Up @@ -894,17 +894,13 @@ public function runBare(): void
}
}
} catch (Throwable $_e) {
if (!isset($e)) {
$e = $_e;
}
$e = $e ?? $_e;
}

try {
$this->stopOutputBuffering();
} catch (RiskyTestError $_e) {
if (!isset($e)) {
$e = $_e;
}
$e = $e ?? $_e;
}

if (isset($_e)) {
Expand Down
18 changes: 7 additions & 11 deletions src/Runner/PhptTestCase.php
Expand Up @@ -269,22 +269,18 @@ private function assertPhptExpectation(array $sections, string $output): void
foreach ($assertions as $sectionName => $sectionAssertion) {
if (isset($sections[$sectionName])) {
$sectionContent = \preg_replace('/\r\n/', "\n", \trim($sections[$sectionName]));
$assertion = $sectionAssertion;
$expected = $sectionName === 'EXPECTREGEX' ? "/{$sectionContent}/" : $sectionContent;

break;
}
}

if (!isset($assertion)) {
throw new Exception('No PHPT assertion found');
}
if ($expected === null) {
throw new Exception('No PHPT expectation found');
}
Assert::$sectionAssertion($expected, $actual);

if (!isset($expected)) {
throw new Exception('No PHPT expectation found');
return;
}
}

Assert::$assertion($expected, $actual);
throw new Exception('No PHPT assertion found');
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/Runner/ResultCacheExtension.php
Expand Up @@ -96,11 +96,7 @@ private function getTestName(string $test): string
$matches = [];

if (\preg_match('/^(?:\S+::)?(?<name>\S+)(?:(?<data> with data set (?:#\d+|"[^"]+"))\s\()?/', $test, $matches)) {
$test = $matches['name'];

if (isset($matches['data'])) {
$test .= $matches['data'];
}
$test = $matches['name'] . ($matches['data'] ?? '');
}

return $test;
Expand Down
4 changes: 1 addition & 3 deletions src/TextUI/TestRunner.php
Expand Up @@ -188,9 +188,7 @@ public function doRun(Test $suite, array $arguments = [], bool $exit = true): Te
}

if ($arguments['executionOrder'] !== TestSuiteSorter::ORDER_DEFAULT || $arguments['executionOrderDefects'] !== TestSuiteSorter::ORDER_DEFAULT || $arguments['resolveDependencies']) {
if (!isset($cache)) {
$cache = new NullTestResultCache;
}
$cache = $cache ?? new NullTestResultCache;

$cache->load();

Expand Down
4 changes: 2 additions & 2 deletions src/Util/PHP/Template/TestCaseClass.tpl.dist
Expand Up @@ -69,12 +69,12 @@ function __phpunit_run_isolated_test()
}

print serialize(
array(
[
'testResult' => $test->getResult(),
'numAssertions' => $test->getNumAssertions(),
'result' => $result,
'output' => $output
)
]
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Util/PHP/Template/TestCaseMethod.tpl.dist
Expand Up @@ -71,12 +71,12 @@ function __phpunit_run_isolated_test()
}

print serialize(
array(
[
'testResult' => $test->getResult(),
'numAssertions' => $test->getNumAssertions(),
'result' => $result,
'output' => $output
)
]
);
}

Expand Down

0 comments on commit 159a008

Please sign in to comment.