Skip to content

Commit

Permalink
Fix stringify-ing booleans
Browse files Browse the repository at this point in the history
Fixes #226
  • Loading branch information
rquadling committed May 4, 2017
1 parent 2f688ee commit 3e59192
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,11 @@
# Change Log
All notable changes to this project will be documented in this file.

## 2.7.6 - 2017-05-04

### Fixes
- Fixed stringification of booleans (Thank to [Philipp Rieber](https://github.com/beberlei/assert/issues/226))

## 2.7.5 - 2017-04-29
### Added assertions
- `Assert\Assertion:isResource()` (Thanks to [Timothy Younger](https://github.com/beberlei/assert/pull/222))
Expand Down
10 changes: 5 additions & 5 deletions lib/Assert/Assertion.php
Expand Up @@ -2497,7 +2497,7 @@ protected static function stringify($value)
$result = $value ? '<TRUE>' : '<FALSE>';
}

if (\is_scalar($value)) {
else if (\is_scalar($value)) {
$val = (string) $value;

if (\strlen($val) > 100) {
Expand All @@ -2507,19 +2507,19 @@ protected static function stringify($value)
$result = $val;
}

if (\is_array($value)) {
else if (\is_array($value)) {
$result = '<ARRAY>';
}

if (\is_object($value)) {
else if (\is_object($value)) {
$result = \get_class($value);
}

if (\is_resource($value)) {
else if (\is_resource($value)) {
$result = \get_resource_type($value);
}

if ($value === null) {
else if ($value === null) {
$result = '<NULL>';
}

Expand Down
12 changes: 9 additions & 3 deletions tests/Assert/Tests/PR142_AllowOverridingStringifyTest.php
Expand Up @@ -14,6 +14,9 @@

namespace Assert\Tests;

use Assert\Assertion;
use Assert\AssertionFailedException;

class PR142_AllowOverridingStringifyTest extends \PHPUnit_Framework_TestCase
{
public static function dataInvalidString()
Expand All @@ -30,14 +33,17 @@ public static function dataInvalidString()

/**
* @dataProvider dataInvalidString
* @expectedException \Assert\AssertionFailedException
* @expectedExceptionCode \Assert\Assertion::INVALID_STRING
*
* @param string $invalidString
* @param string $exceptionMessage
*/
public function testInvalidStringWithOverriddenStringify($invalidString, $exceptionMessage)
{
Fixtures\PR142_OverrideStringify::string($invalidString);
try {
Fixtures\PR142_OverrideStringify::string($invalidString);
} catch (AssertionFailedException $ex) {
$this->assertSame(Assertion::INVALID_STRING, $ex->getCode());
$this->assertSame($exceptionMessage, $ex->getMessage());
}
}
}

0 comments on commit 3e59192

Please sign in to comment.