Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
composer.lock
tests/.phpunit.result.cache
vendor
/.php-cs-fixer.cache
38 changes: 38 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__.'/hamcrest')
->in(__DIR__.'/generator')
->in(__DIR__.'/tests')
->notPath('Matchers.php')
->notPath('Hamcrest.php')
->name('*.php')
;

return (new PhpCsFixer\Config())
->setRules([
// Use PSR-12 as base but disable the cosmetic rules
'@PSR12' => true,

// namespace should come directly after the opening tag
'blank_line_after_opening_tag' => false,
'linebreak_after_opening_tag' => true,
'blank_lines_before_namespace' => ['min_line_breaks' => 1, 'max_line_breaks' => 1],

// add semicolons to the last lines of chained calls
'multiline_whitespace_before_semicolons' => ['strategy' => 'new_line_for_chained_calls'],
'method_chaining_indentation' => true,

// parentheses on new expressions when there are no arguments
'new_with_parentheses' => ['named_class' => true, 'anonymous_class' => true],

// use consistent naming for boolean, bool, integer, int, etc
'phpdoc_scalar' => true,

// allow a new line after the class opening
'no_blank_lines_after_class_opening' => false,

])
->setFinder($finder)
->setRiskyAllowed(false)
;
9 changes: 8 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ Feel free to ask any questions and share your experiences in the [Issue tracking
1. Create your feature addition or a bug fix branch based on __`master`__ branch in your repository's fork.
2. Make necessary changes, but __don't mix__ code reformatting with code changes on topic.
3. Add tests for those changes (please look into `tests/` folder for some examples). This is important so we don't break it in a future version unintentionally.
4. Check your code using "Coding Standard" (see below).
4. Fix your code style by using the "Coding Standard" (see below).
5. Commit your code.
6. Squash your commits by topic to preserve a clean and readable log.
7. Create Pull Request.

## Coding Standard

To keep a consice coding standard in the repository, run:
```bash
vendor/bin/php-cs-fixer fix
```

## Running the Tests

### Installation/Configuration
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

"require-dev": {
"phpunit/php-file-iterator": "^1.4 || ^2.0 || ^3.0",
"phpunit/phpunit": "^4.8.36 || ^5.7 || ^6.5 || ^7.0 || ^8.0 || ^9.0"
"phpunit/phpunit": "^4.8.36 || ^5.7 || ^6.5 || ^7.0 || ^8.0 || ^9.0",
"friendsofphp/php-cs-fixer": "^3.75"
},

"replace": {
Expand Down
2 changes: 1 addition & 1 deletion generator/FactoryCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class FactoryCall
*
* @var string
*/
const INDENT = ' ';
public const INDENT = ' ';

/**
* @var FactoryMethod
Expand Down
2 changes: 1 addition & 1 deletion generator/FactoryFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract class FactoryFile
*
* @var string
*/
const INDENT = ' ';
public const INDENT = ' ';

private $indent;

Expand Down
4 changes: 2 additions & 2 deletions generator/GlobalFunctionFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public function build()
public function generateFactoryCall(FactoryCall $call)
{
$code = "if (!function_exists('{$call->getName()}')) {\n";
$code.= parent::generateFactoryCall($call);
$code.= "}\n";
$code .= parent::generateFactoryCall($call);
$code .= "}\n";

return $code;
}
Expand Down
17 changes: 9 additions & 8 deletions hamcrest/Hamcrest/Arrays/IsArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ protected function describeMismatchSafely($actual, Description $mismatchDescript
return;
} elseif (array_keys($actual) != array_keys($this->_elementMatchers)) {
$mismatchDescription->appendText('array keys were ')
->appendValueList(
$this->descriptionStart(),
$this->descriptionSeparator(),
$this->descriptionEnd(),
array_keys($actual)
)
;
->appendValueList(
$this->descriptionStart(),
$this->descriptionSeparator(),
$this->descriptionEnd(),
array_keys($actual)
)
;

return;
}
Expand All @@ -70,7 +70,8 @@ protected function describeMismatchSafely($actual, Description $mismatchDescript
foreach ($this->_elementMatchers as $k => $matcher) {
if (!$matcher->matches($actual[$k])) {
$mismatchDescription->appendText('element ')->appendValue($k)
->appendText(' was ')->appendValue($actual[$k]);
->appendText(' was ')->appendValue($actual[$k])
;
Comment on lines 72 to +74
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably write it more like:

      $mismatchDescription
          ->appendText('element ')
          ->appendValue($k)
          ->appendText(' was ')
          ->appendValue($actual[$k])
    ;


return;
}
Expand Down
4 changes: 2 additions & 2 deletions hamcrest/Hamcrest/Arrays/IsArrayContaining.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ protected function describeMismatchSafely($array, Description $mismatchDescripti
public function describeTo(Description $description)
{
$description
->appendText('an array containing ')
->appendDescriptionOf($this->_elementMatcher)
->appendText('an array containing ')
->appendDescriptionOf($this->_elementMatcher)
;
}

Expand Down
4 changes: 2 additions & 2 deletions hamcrest/Hamcrest/Arrays/IsArrayContainingInAnyOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ protected function matchesSafelyWithDiagnosticDescription($array, Description $m
public function describeTo(Description $description)
{
$description->appendList('[', ', ', ']', $this->_elementMatchers)
->appendText(' in any order')
;
->appendText(' in any order')
;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions hamcrest/Hamcrest/Arrays/IsArrayContainingKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ protected function describeMismatchSafely($array, Description $mismatchDescripti
{
//Not using appendValueList() so that keys can be shown
$mismatchDescription->appendText('array was ')
->appendText('[')
;
->appendText('[')
;
Comment on lines 41 to +43
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

     $mismatchDescription
         ->appendText('array was ')
         ->appendText('[')
     ;

$loop = false;
foreach ($array as $key => $value) {
if ($loop) {
Expand All @@ -55,9 +55,9 @@ protected function describeMismatchSafely($array, Description $mismatchDescripti
public function describeTo(Description $description)
{
$description
->appendText('array with key ')
->appendDescriptionOf($this->_keyMatcher)
;
->appendText('array with key ')
->appendDescriptionOf($this->_keyMatcher)
;
Comment on lines 57 to +60
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks more concise to me!

}

/**
Expand Down
14 changes: 7 additions & 7 deletions hamcrest/Hamcrest/Arrays/IsArrayContainingKeyValuePair.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ protected function describeMismatchSafely($array, Description $mismatchDescripti
{
//Not using appendValueList() so that keys can be shown
$mismatchDescription->appendText('array was ')
->appendText('[')
;
->appendText('[')
;
$loop = false;
foreach ($array as $key => $value) {
if ($loop) {
Expand All @@ -58,11 +58,11 @@ protected function describeMismatchSafely($array, Description $mismatchDescripti
public function describeTo(Description $description)
{
$description->appendText('array containing [')
->appendDescriptionOf($this->_keyMatcher)
->appendText(' => ')
->appendDescriptionOf($this->_valueMatcher)
->appendText(']')
;
->appendDescriptionOf($this->_keyMatcher)
->appendText(' => ')
->appendDescriptionOf($this->_valueMatcher)
->appendText(']')
;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions hamcrest/Hamcrest/Arrays/MatchingOnce.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public function isFinished($items)
}

$this->_mismatchDescription
->appendText('No item matches: ')->appendList('', ', ', '', $this->_elementMatchers)
->appendText(' in ')->appendValueList('[', ', ', ']', $items)
;
->appendText('No item matches: ')->appendList('', ', ', '', $this->_elementMatchers)
->appendText(' in ')->appendValueList('[', ', ', ']', $items)
;

return false;
}
Expand All @@ -53,7 +53,7 @@ private function _isNotSurplus($item)

private function _isMatched($item)
{
/** @var $matcher \Hamcrest\Matcher */
/** @var $matcher \Hamcrest\Matcher */
foreach ($this->_elementMatchers as $i => $matcher) {
if ($matcher->matches($item)) {
unset($this->_elementMatchers[$i]);
Expand Down
2 changes: 1 addition & 1 deletion hamcrest/Hamcrest/Collection/IsEmptyTraversable.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function describeTo(Description $description)
public static function emptyTraversable()
{
if (!self::$_INSTANCE) {
self::$_INSTANCE = new self;
self::$_INSTANCE = new self();
}

return self::$_INSTANCE;
Expand Down
2 changes: 1 addition & 1 deletion hamcrest/Hamcrest/Core/DescribedAs.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DescribedAs extends BaseMatcher
private $_matcher;
private $_values;

const ARG_PATTERN = '/%([0-9]+)/';
public const ARG_PATTERN = '/%([0-9]+)/';

public function __construct($descriptionTemplate, Matcher $matcher, array $values)
{
Expand Down
6 changes: 3 additions & 3 deletions hamcrest/Hamcrest/Core/IsCollectionContaining.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ protected function describeMismatchSafely($items, Description $mismatchDescripti
public function describeTo(Description $description)
{
$description
->appendText('a collection containing ')
->appendDescriptionOf($this->_elementMatcher)
;
->appendText('a collection containing ')
->appendDescriptionOf($this->_elementMatcher)
;
}

/**
Expand Down
7 changes: 4 additions & 3 deletions hamcrest/Hamcrest/Core/IsInstanceOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ protected function matchesWithDiagnosticDescription($item, Description $mismatch

if (!($item instanceof $this->_theClass)) {
$mismatchDescription->appendText('[' . get_class($item) . '] ')
->appendValue($item);
->appendValue($item)
;

return false;
}
Expand All @@ -48,8 +49,8 @@ protected function matchesWithDiagnosticDescription($item, Description $mismatch
public function describeTo(Description $description)
{
$description->appendText('an instance of ')
->appendText($this->_theClass)
;
->appendText($this->_theClass)
;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions hamcrest/Hamcrest/Core/IsSame.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public function matches($object)
public function describeTo(Description $description)
{
$description->appendText('sameInstance(')
->appendValue($this->_object)
->appendText(')')
;
->appendValue($this->_object)
->appendText(')')
;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions hamcrest/Hamcrest/Core/IsTypeOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public function describeMismatch($item, Description $description)
$description->appendText('was null');
} else {
$description->appendText('was ')
->appendText(self::getTypeDescription(strtolower(gettype($item))))
->appendText(' ')
->appendValue($item)
;
->appendText(self::getTypeDescription(strtolower(gettype($item))))
->appendText(' ')
->appendValue($item)
;
}
}

Expand Down
7 changes: 4 additions & 3 deletions hamcrest/Hamcrest/FeatureMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public function matchesSafelyWithDiagnosticDescription($actual, Description $mis

if (!$this->_subMatcher->matches($featureValue)) {
$mismatchDescription->appendText($this->_featureName)
->appendText(' was ')->appendValue($featureValue);
->appendText(' was ')->appendValue($featureValue)
;

return false;
}
Expand All @@ -61,7 +62,7 @@ public function matchesSafelyWithDiagnosticDescription($actual, Description $mis
final public function describeTo(Description $description)
{
$description->appendText($this->_featureDescription)->appendText(' ')
->appendDescriptionOf($this->_subMatcher)
;
->appendDescriptionOf($this->_subMatcher)
;
}
}
24 changes: 12 additions & 12 deletions hamcrest/Hamcrest/Matcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ interface Matcher extends SelfDescribing
*
* @param mixed $item the object against which the matcher is evaluated.
*
* @return boolean <code>true</code> if <var>$item</var> matches,
* @return bool <code>true</code> if <var>$item</var> matches,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

up for discussion of course, i like it more if its concise (but dont care if its boolean or bool)

* otherwise <code>false</code>.
*
* @see Hamcrest\BaseMatcher
*/
public function matches($item);

/**
* Generate a description of why the matcher has not accepted the item.
* The description will be part of a larger description of why a matching
* failed, so it should be concise.
* This method assumes that <code>matches($item)</code> is false, but
* will not check this.
*
* @param mixed $item The item that the Matcher has rejected.
* @param Description $description
* @return
*/
/**
* Generate a description of why the matcher has not accepted the item.
* The description will be part of a larger description of why a matching
* failed, so it should be concise.
* This method assumes that <code>matches($item)</code> is false, but
* will not check this.
*
* @param mixed $item The item that the Matcher has rejected.
* @param Description $description
* @return
*/
public function describeMismatch($item, Description $description);
}
5 changes: 3 additions & 2 deletions hamcrest/Hamcrest/MatcherAssert.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ private static function doAssert($identifier, $actual, Matcher $matcher)
$description->appendText($identifier . PHP_EOL);
}
$description->appendText('Expected: ')
->appendDescriptionOf($matcher)
->appendText(PHP_EOL . ' but: ');
->appendDescriptionOf($matcher)
->appendText(PHP_EOL . ' but: ')
;

$matcher->describeMismatch($actual, $description);

Expand Down
Loading