From 17dd932061a10dc6d62ff49407c3664f61032d38 Mon Sep 17 00:00:00 2001 From: Eddie Jaoude Date: Thu, 21 Feb 2013 09:16:13 +0000 Subject: [PATCH 1/3] Yaml Dumper Class to 100% code coverage --- src/Symfony/Component/Yaml/Dumper.php | 10 ++++++++++ .../Component/Yaml/Tests/DumperTest.php | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/Symfony/Component/Yaml/Dumper.php b/src/Symfony/Component/Yaml/Dumper.php index 8709f8b7e4628..0da120eadedd8 100644 --- a/src/Symfony/Component/Yaml/Dumper.php +++ b/src/Symfony/Component/Yaml/Dumper.php @@ -35,6 +35,16 @@ public function setIndentation($num) $this->indentation = (int) $num; } + /** + * Gets the indentation. + * + * @return int + */ + public function getIndentation() + { + return $this->indentation; + } + /** * Dumps a PHP value to YAML. * diff --git a/src/Symfony/Component/Yaml/Tests/DumperTest.php b/src/Symfony/Component/Yaml/Tests/DumperTest.php index 1199118d77981..80a440331ea81 100644 --- a/src/Symfony/Component/Yaml/Tests/DumperTest.php +++ b/src/Symfony/Component/Yaml/Tests/DumperTest.php @@ -35,6 +35,24 @@ protected function tearDown() $this->path = null; } + public function testGetIndentationDefault() + { + $this->assertEquals(4, $this->dumper->getIndentation()); + } + + public function testSetGetIndentation() + { + $this->dumper->setIndentation(6); + $this->assertEquals(6, $this->dumper->getIndentation()); + } + + public function testSetGetIndentationCastToInt() + { + $this->dumper->setIndentation('8'); + $this->assertTrue(is_int($this->dumper->getIndentation())); + $this->assertEquals(8, $this->dumper->getIndentation()); + } + public function testSpecifications() { $files = $this->parser->parse(file_get_contents($this->path.'/index.yml')); From c47c6484ad78fe50d453be1ca1c22c0b8ba776c0 Mon Sep 17 00:00:00 2001 From: Eddie Jaoude Date: Sat, 23 Feb 2013 06:55:29 +0000 Subject: [PATCH 2/3] Refactored Yaml indentation test as discussed - removed getter, tested indentation by using dump --- src/Symfony/Component/Yaml/Dumper.php | 10 ---- .../Component/Yaml/Tests/DumperTest.php | 49 +++++++++++++------ 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/Symfony/Component/Yaml/Dumper.php b/src/Symfony/Component/Yaml/Dumper.php index 0da120eadedd8..8709f8b7e4628 100644 --- a/src/Symfony/Component/Yaml/Dumper.php +++ b/src/Symfony/Component/Yaml/Dumper.php @@ -35,16 +35,6 @@ public function setIndentation($num) $this->indentation = (int) $num; } - /** - * Gets the indentation. - * - * @return int - */ - public function getIndentation() - { - return $this->indentation; - } - /** * Dumps a PHP value to YAML. * diff --git a/src/Symfony/Component/Yaml/Tests/DumperTest.php b/src/Symfony/Component/Yaml/Tests/DumperTest.php index 80a440331ea81..bf6e32be42640 100644 --- a/src/Symfony/Component/Yaml/Tests/DumperTest.php +++ b/src/Symfony/Component/Yaml/Tests/DumperTest.php @@ -35,22 +35,43 @@ protected function tearDown() $this->path = null; } - public function testGetIndentationDefault() + public function testSetIndentation() { - $this->assertEquals(4, $this->dumper->getIndentation()); - } - - public function testSetGetIndentation() - { - $this->dumper->setIndentation(6); - $this->assertEquals(6, $this->dumper->getIndentation()); - } + $this->dumper->setIndentation(7); + $array = array( + '' => 'bar', + 'foo' => '#bar', + 'foo\'bar' => array(), + 'bar' => array(1, 'foo'), + 'foobar' => array( + 'foo' => 'bar', + 'bar' => array(1, 'foo'), + 'foobar' => array( + 'foo' => 'bar', + 'bar' => array(1, 'foo'), + ), + ), + ); +$expected = <<dumper->setIndentation('8'); - $this->assertTrue(is_int($this->dumper->getIndentation())); - $this->assertEquals(8, $this->dumper->getIndentation()); +EOF; + $this->assertEquals($expected, $this->dumper->dump($array, 4, 0)); } public function testSpecifications() From 499450056fb51a1287eb5ddbd607956473251ace Mon Sep 17 00:00:00 2001 From: Eddie Jaoude Date: Sat, 23 Feb 2013 06:59:37 +0000 Subject: [PATCH 3/3] Refactored Yaml tests - moved dummy data to class property as used in multiple places --- .../Component/Yaml/Tests/DumperTest.php | 63 ++++++++----------- 1 file changed, 25 insertions(+), 38 deletions(-) diff --git a/src/Symfony/Component/Yaml/Tests/DumperTest.php b/src/Symfony/Component/Yaml/Tests/DumperTest.php index bf6e32be42640..c51a257dc08f3 100644 --- a/src/Symfony/Component/Yaml/Tests/DumperTest.php +++ b/src/Symfony/Component/Yaml/Tests/DumperTest.php @@ -21,6 +21,21 @@ class DumperTest extends \PHPUnit_Framework_TestCase protected $dumper; protected $path; + protected $array = array( + '' => 'bar', + 'foo' => '#bar', + 'foo\'bar' => array(), + 'bar' => array(1, 'foo'), + 'foobar' => array( + 'foo' => 'bar', + 'bar' => array(1, 'foo'), + 'foobar' => array( + 'foo' => 'bar', + 'bar' => array(1, 'foo'), + ), + ), + ); + protected function setUp() { $this->parser = new Parser(); @@ -33,25 +48,13 @@ protected function tearDown() $this->parser = null; $this->dumper = null; $this->path = null; + $this->array = null; } public function testSetIndentation() { $this->dumper->setIndentation(7); - $array = array( - '' => 'bar', - 'foo' => '#bar', - 'foo\'bar' => array(), - 'bar' => array(1, 'foo'), - 'foobar' => array( - 'foo' => 'bar', - 'bar' => array(1, 'foo'), - 'foobar' => array( - 'foo' => 'bar', - 'bar' => array(1, 'foo'), - ), - ), - ); + $expected = <<assertEquals($expected, $this->dumper->dump($array, 4, 0)); + $this->assertEquals($expected, $this->dumper->dump($this->array, 4, 0)); } public function testSpecifications() @@ -102,27 +105,11 @@ public function testSpecifications() public function testInlineLevel() { - // inline level - $array = array( - '' => 'bar', - 'foo' => '#bar', - 'foo\'bar' => array(), - 'bar' => array(1, 'foo'), - 'foobar' => array( - 'foo' => 'bar', - 'bar' => array(1, 'foo'), - 'foobar' => array( - 'foo' => 'bar', - 'bar' => array(1, 'foo'), - ), - ), - ); - $expected = <<assertEquals($expected, $this->dumper->dump($array, -10), '->dump() takes an inline level argument'); -$this->assertEquals($expected, $this->dumper->dump($array, 0), '->dump() takes an inline level argument'); +$this->assertEquals($expected, $this->dumper->dump($this->array, -10), '->dump() takes an inline level argument'); +$this->assertEquals($expected, $this->dumper->dump($this->array, 0), '->dump() takes an inline level argument'); $expected = <<assertEquals($expected, $this->dumper->dump($array, 1), '->dump() takes an inline level argument'); + $this->assertEquals($expected, $this->dumper->dump($this->array, 1), '->dump() takes an inline level argument'); $expected = <<assertEquals($expected, $this->dumper->dump($array, 2), '->dump() takes an inline level argument'); + $this->assertEquals($expected, $this->dumper->dump($this->array, 2), '->dump() takes an inline level argument'); $expected = <<assertEquals($expected, $this->dumper->dump($array, 3), '->dump() takes an inline level argument'); + $this->assertEquals($expected, $this->dumper->dump($this->array, 3), '->dump() takes an inline level argument'); $expected = <<assertEquals($expected, $this->dumper->dump($array, 4), '->dump() takes an inline level argument'); - $this->assertEquals($expected, $this->dumper->dump($array, 10), '->dump() takes an inline level argument'); + $this->assertEquals($expected, $this->dumper->dump($this->array, 4), '->dump() takes an inline level argument'); + $this->assertEquals($expected, $this->dumper->dump($this->array, 10), '->dump() takes an inline level argument'); } public function testObjectSupportEnabled()