Skip to content

Commit

Permalink
Complete configuration for ordered_class_elements fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Mar 30, 2018
1 parent 536f4d8 commit 9f0b379
Show file tree
Hide file tree
Showing 17 changed files with 585 additions and 581 deletions.
6 changes: 6 additions & 0 deletions .php_cs.dist
Expand Up @@ -90,16 +90,22 @@ return PhpCsFixer\Config::create()
'constant_public',
'constant_protected',
'constant_private',
'property_public_static',
'property_protected_static',
'property_private_static',
'property_public',
'property_protected',
'property_private',
'method_public_static',
'construct',
'destruct',
'magic',
'phpunit',
'method_public',
'method_protected',
'method_private',
'method_protected_static',
'method_private_static',
],
],
'ordered_imports' => true,
Expand Down
28 changes: 14 additions & 14 deletions src/Framework/Constraint/LogicalNot.php
Expand Up @@ -21,20 +21,6 @@ class LogicalNot extends Constraint
*/
private $constraint;

/**
* @param Constraint $constraint
*/
public function __construct($constraint)
{
parent::__construct();

if (!($constraint instanceof Constraint)) {
$constraint = new IsEqual($constraint);
}

$this->constraint = $constraint;
}

/**
* @param string $string
*
Expand Down Expand Up @@ -93,6 +79,20 @@ public static function negate($string): string
return $negatedString;
}

/**
* @param Constraint $constraint
*/
public function __construct($constraint)
{
parent::__construct();

if (!($constraint instanceof Constraint)) {
$constraint = new IsEqual($constraint);
}

$this->constraint = $constraint;
}

/**
* Evaluates the constraint for parameter $other
*
Expand Down
234 changes: 117 additions & 117 deletions src/Framework/TestCase.php
Expand Up @@ -261,6 +261,123 @@ abstract class TestCase extends Assert implements Test, SelfDescribing
*/
private $customComparators = [];

/**
* Returns a matcher that matches when the method is executed
* zero or more times.
*/
public static function any(): AnyInvokedCountMatcher
{
return new AnyInvokedCountMatcher;
}

/**
* Returns a matcher that matches when the method is never executed.
*/
public static function never(): InvokedCountMatcher
{
return new InvokedCountMatcher(0);
}

/**
* Returns a matcher that matches when the method is executed
* at least N times.
*/
public static function atLeast(int $requiredInvocations): InvokedAtLeastCountMatcher
{
return new InvokedAtLeastCountMatcher(
$requiredInvocations
);
}

/**
* Returns a matcher that matches when the method is executed at least once.
*/
public static function atLeastOnce(): InvokedAtLeastOnceMatcher
{
return new InvokedAtLeastOnceMatcher;
}

/**
* Returns a matcher that matches when the method is executed exactly once.
*/
public static function once(): InvokedCountMatcher
{
return new InvokedCountMatcher(1);
}

/**
* Returns a matcher that matches when the method is executed
* exactly $count times.
*/
public static function exactly(int $count): InvokedCountMatcher
{
return new InvokedCountMatcher($count);
}

/**
* Returns a matcher that matches when the method is executed
* at most N times.
*/
public static function atMost(int $allowedInvocations): InvokedAtMostCountMatcher
{
return new InvokedAtMostCountMatcher($allowedInvocations);
}

/**
* Returns a matcher that matches when the method is executed
* at the given index.
*/
public static function at(int $index): InvokedAtIndexMatcher
{
return new InvokedAtIndexMatcher($index);
}

/**
* @param mixed $value
*/
public static function returnValue($value): ReturnStub
{
return new ReturnStub($value);
}

public static function returnValueMap(array $valueMap): ReturnValueMapStub
{
return new ReturnValueMapStub($valueMap);
}

public static function returnArgument(int $argumentIndex): ReturnArgumentStub
{
return new ReturnArgumentStub($argumentIndex);
}

/**
* @param mixed $callback
*/
public static function returnCallback($callback): ReturnCallbackStub
{
return new ReturnCallbackStub($callback);
}

/**
* Returns the current object.
*
* This method is useful when mocking a fluent interface.
*/
public static function returnSelf(): ReturnSelfStub
{
return new ReturnSelfStub;
}

public static function throwException(Throwable $exception): ExceptionStub
{
return new ExceptionStub($exception);
}

public static function onConsecutiveCalls(...$args): ConsecutiveCallsStub
{
return new ConsecutiveCallsStub($args);
}

/**
* @param string $name
* @param array $data
Expand Down Expand Up @@ -951,123 +1068,6 @@ public function getNumAssertions(): int
return $this->numAssertions;
}

/**
* Returns a matcher that matches when the method is executed
* zero or more times.
*/
public static function any(): AnyInvokedCountMatcher
{
return new AnyInvokedCountMatcher;
}

/**
* Returns a matcher that matches when the method is never executed.
*/
public static function never(): InvokedCountMatcher
{
return new InvokedCountMatcher(0);
}

/**
* Returns a matcher that matches when the method is executed
* at least N times.
*/
public static function atLeast(int $requiredInvocations): InvokedAtLeastCountMatcher
{
return new InvokedAtLeastCountMatcher(
$requiredInvocations
);
}

/**
* Returns a matcher that matches when the method is executed at least once.
*/
public static function atLeastOnce(): InvokedAtLeastOnceMatcher
{
return new InvokedAtLeastOnceMatcher;
}

/**
* Returns a matcher that matches when the method is executed exactly once.
*/
public static function once(): InvokedCountMatcher
{
return new InvokedCountMatcher(1);
}

/**
* Returns a matcher that matches when the method is executed
* exactly $count times.
*/
public static function exactly(int $count): InvokedCountMatcher
{
return new InvokedCountMatcher($count);
}

/**
* Returns a matcher that matches when the method is executed
* at most N times.
*/
public static function atMost(int $allowedInvocations): InvokedAtMostCountMatcher
{
return new InvokedAtMostCountMatcher($allowedInvocations);
}

/**
* Returns a matcher that matches when the method is executed
* at the given index.
*/
public static function at(int $index): InvokedAtIndexMatcher
{
return new InvokedAtIndexMatcher($index);
}

/**
* @param mixed $value
*/
public static function returnValue($value): ReturnStub
{
return new ReturnStub($value);
}

public static function returnValueMap(array $valueMap): ReturnValueMapStub
{
return new ReturnValueMapStub($valueMap);
}

public static function returnArgument(int $argumentIndex): ReturnArgumentStub
{
return new ReturnArgumentStub($argumentIndex);
}

/**
* @param mixed $callback
*/
public static function returnCallback($callback): ReturnCallbackStub
{
return new ReturnCallbackStub($callback);
}

/**
* Returns the current object.
*
* This method is useful when mocking a fluent interface.
*/
public static function returnSelf(): ReturnSelfStub
{
return new ReturnSelfStub;
}

public static function throwException(Throwable $exception): ExceptionStub
{
return new ExceptionStub($exception);
}

public static function onConsecutiveCalls(...$args): ConsecutiveCallsStub
{
return new ConsecutiveCallsStub($args);
}

public function usesDataProvider(): bool
{
return !empty($this->data);
Expand Down
72 changes: 36 additions & 36 deletions src/Framework/TestFailure.php
Expand Up @@ -31,6 +31,42 @@ class TestFailure
*/
private $testName;

/**
* Returns a description for an exception.
*
* @param Throwable $e
*
* @throws \InvalidArgumentException
*
* @return string
*/
public static function exceptionToString(Throwable $e): string
{
if ($e instanceof SelfDescribing) {
$buffer = $e->toString();

if ($e instanceof ExpectationFailedException && $e->getComparisonFailure()) {
$buffer .= $e->getComparisonFailure()->getDiff();
}

if (!empty($buffer)) {
$buffer = \trim($buffer) . "\n";
}

return $buffer;
}

if ($e instanceof Error) {
return $e->getMessage() . "\n";
}

if ($e instanceof ExceptionWrapper) {
return $e->getClassName() . ': ' . $e->getMessage() . "\n";
}

return \get_class($e) . ': ' . $e->getMessage() . "\n";
}

/**
* Constructs a TestFailure with the given test and exception.
*
Expand Down Expand Up @@ -78,42 +114,6 @@ public function getExceptionAsString(): string
return self::exceptionToString($this->thrownException);
}

/**
* Returns a description for an exception.
*
* @param Throwable $e
*
* @throws \InvalidArgumentException
*
* @return string
*/
public static function exceptionToString(Throwable $e): string
{
if ($e instanceof SelfDescribing) {
$buffer = $e->toString();

if ($e instanceof ExpectationFailedException && $e->getComparisonFailure()) {
$buffer .= $e->getComparisonFailure()->getDiff();
}

if (!empty($buffer)) {
$buffer = \trim($buffer) . "\n";
}

return $buffer;
}

if ($e instanceof Error) {
return $e->getMessage() . "\n";
}

if ($e instanceof ExceptionWrapper) {
return $e->getClassName() . ': ' . $e->getMessage() . "\n";
}

return \get_class($e) . ': ' . $e->getMessage() . "\n";
}

/**
* Returns the name of the failing test (including data set, if any).
*
Expand Down

0 comments on commit 9f0b379

Please sign in to comment.