From 968728d84b86e8fbaa2e59153832b53b956e7338 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Wed, 23 Jul 2014 18:29:50 +0200 Subject: [PATCH] added countLines method --- src/Intervention/Image/AbstractFont.php | 10 ++++++++++ tests/AbstractFontTest.php | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Intervention/Image/AbstractFont.php b/src/Intervention/Image/AbstractFont.php index e21f6d9a..9e3cca92 100644 --- a/src/Intervention/Image/AbstractFont.php +++ b/src/Intervention/Image/AbstractFont.php @@ -233,4 +233,14 @@ abstract class AbstractFont return false; } + + /** + * Counts lines of text to be written + * + * @return integer + */ + public function countLines() + { + return count(explode(PHP_EOL, $this->text)); + } } diff --git a/tests/AbstractFontTest.php b/tests/AbstractFontTest.php index 9bc5133c..cf1d03b5 100644 --- a/tests/AbstractFontTest.php +++ b/tests/AbstractFontTest.php @@ -61,4 +61,17 @@ class AbstractFontTest extends PHPUnit_Framework_TestCase $font->file('test.ttf'); $this->assertEquals('test.ttf', $font->file); } + + public function testCountLines() + { + $font = $this->getMockForAbstractClass('\Intervention\Image\AbstractFont'); + $font->text('foo'.PHP_EOL.'bar'.PHP_EOL.'baz'); + $this->assertEquals(3, $font->countLines()); + $font->text("foo\nbar\nbaz"); + $this->assertEquals(3, $font->countLines()); + $font->text('foo + bar + baz'); + $this->assertEquals(3, $font->countLines()); + } }