Skip to content

Commit

Permalink
Merge pull request #250 from elliotchance/1.7.2/250-resources-not-ren…
Browse files Browse the repository at this point in the history
…dered-correctly

Resources are not rendered correctly
  • Loading branch information
elliotchance committed Mar 12, 2015
2 parents 4f768ef + caa931d commit 539ada0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/Concise/Services/ValueRenderer.php
Expand Up @@ -52,6 +52,9 @@ public function colorize($value)
if (is_float($value)) {
return (string) $c($value)->{$this->theme['value.float']};
}
if (is_resource($value)) {
return (string) $c((string) $value)->{$this->theme['value.string']};
}

return $this->colorizeLines($value);
}
Expand Down
36 changes: 31 additions & 5 deletions tests/Concise/Services/SyntaxRendererTest.php
Expand Up @@ -7,13 +7,28 @@

class SyntaxRendererTest extends TestCase
{
/**
* @var SyntaxRenderer
*/
protected $renderer;

public function setUp()
{
parent::setUp();
$this->renderer = new SyntaxRenderer();
}

public function testCanSubstituteValuesFromArrayIntoPlaceholders()
{
$renderer = new SyntaxRenderer();
$data = array(1, '2', 3.1);
$c = new Color();
$expected = (string) $c('1')->red . ' is ' . (string) $c('"2"')->yellow . ' bla ' . (string) $c(3.1)->magenta;
$this->assert($expected, equals, $renderer->render('? is ? bla ?', $data));
$expected = (string) $c('1')->red . ' is ' . (string) $c('"2"')->yellow
. ' bla ' . (string) $c(3.1)->magenta;
$this->assert(
$expected,
equals,
$this->renderer->render('? is ? bla ?', $data)
);
}

/**
Expand All @@ -22,7 +37,18 @@ public function testCanSubstituteValuesFromArrayIntoPlaceholders()
*/
public function testSyntaxMustBeAString()
{
$renderer = new SyntaxRenderer();
$renderer->render(123);
$this->renderer->render(123);
}

/**
* @group #250
*/
public function testResourceRendering()
{
$this->assert(
$this->renderer->render('?', array(fopen('.', 'r'))),
matches_regex,
'/Resource id #\\d+/'
);
}
}

0 comments on commit 539ada0

Please sign in to comment.