From d0a8db25d817fa9d643a4692ee23b704b68c2b49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Chardonnet?= Date: Sun, 5 Apr 2015 13:08:12 +0100 Subject: [PATCH 1/3] Moved PhpSearchStrategy as last registered to avoid PHP notice --- src/Gnugat/Redaktilo/Service/EditorBuilder.php | 2 +- tests/spec/Gnugat/Redaktilo/Service/EditorBuilderSpec.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Gnugat/Redaktilo/Service/EditorBuilder.php b/src/Gnugat/Redaktilo/Service/EditorBuilder.php index ded97e1..e131bfa 100644 --- a/src/Gnugat/Redaktilo/Service/EditorBuilder.php +++ b/src/Gnugat/Redaktilo/Service/EditorBuilder.php @@ -83,10 +83,10 @@ protected function getSearchEngine() $engine = new SearchEngine(); $phpConverter = $this->getPhpConverter(); - $engine->registerStrategy(new PhpSearchStrategy($phpConverter)); $engine->registerStrategy(new LineRegexSearchStrategy(), 20); $engine->registerStrategy(new SameSearchStrategy(), 10); $engine->registerStrategy(new LineNumberSearchStrategy()); + $engine->registerStrategy(new PhpSearchStrategy($phpConverter)); foreach ($this->searchStrategies as $priority => $strategies) { foreach ($strategies as $strategy) { diff --git a/tests/spec/Gnugat/Redaktilo/Service/EditorBuilderSpec.php b/tests/spec/Gnugat/Redaktilo/Service/EditorBuilderSpec.php index ac6dc97..7b748ce 100644 --- a/tests/spec/Gnugat/Redaktilo/Service/EditorBuilderSpec.php +++ b/tests/spec/Gnugat/Redaktilo/Service/EditorBuilderSpec.php @@ -26,10 +26,10 @@ function it_can_build_the_default_editor() $editor->shouldBeAnInstanceOf('Gnugat\Redaktilo\Editor'); $editor->shouldHaveSearchStrategies(array( - 'Gnugat\Redaktilo\Search\PhpSearchStrategy', - 'Gnugat\Redaktilo\Search\LineNumberSearchStrategy', 'Gnugat\Redaktilo\Search\LineRegexSearchStrategy', 'Gnugat\Redaktilo\Search\SameSearchStrategy', + 'Gnugat\Redaktilo\Search\LineNumberSearchStrategy', + 'Gnugat\Redaktilo\Search\PhpSearchStrategy', )); $editor->shouldHaveCommands(array( From 3dc9a59ebdff9542b45a4989b1065559f677db58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Chardonnet?= Date: Mon, 6 Apr 2015 10:57:02 +0100 Subject: [PATCH 2/3] Removed unused use statements --- tests/example/BundleRegistrationTest.php | 1 - tests/example/DocumentationReformattingTest.php | 2 -- 2 files changed, 3 deletions(-) diff --git a/tests/example/BundleRegistrationTest.php b/tests/example/BundleRegistrationTest.php index 6e6291d..e5fe7b1 100644 --- a/tests/example/BundleRegistrationTest.php +++ b/tests/example/BundleRegistrationTest.php @@ -12,7 +12,6 @@ namespace example\Gnugat\Redaktilo; use Gnugat\Redaktilo\EditorFactory; -use Gnugat\Redaktilo\Search\Php\TokenBuilder; use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem; class BundleRegistrationTest extends \PHPUnit_Framework_TestCase diff --git a/tests/example/DocumentationReformattingTest.php b/tests/example/DocumentationReformattingTest.php index c4a07ee..733862a 100644 --- a/tests/example/DocumentationReformattingTest.php +++ b/tests/example/DocumentationReformattingTest.php @@ -12,8 +12,6 @@ namespace example\Gnugat\Redaktilo; use Gnugat\Redaktilo\EditorFactory; -use Gnugat\Redaktilo\Editor; -use Gnugat\Redaktilo\File; use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem; class DocumentationReformattingTest extends \PHPUnit_Framework_TestCase From 4a05ac11494bc7f137e3dfd1f9fe2332210f62c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Chardonnet?= Date: Mon, 6 Apr 2015 10:57:21 +0100 Subject: [PATCH 3/3] Added test for issue #120 --- tests/example/LineJumpingTest.php | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/example/LineJumpingTest.php diff --git a/tests/example/LineJumpingTest.php b/tests/example/LineJumpingTest.php new file mode 100644 index 0000000..6c06f02 --- /dev/null +++ b/tests/example/LineJumpingTest.php @@ -0,0 +1,43 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace example\Gnugat\Redaktilo; + +use Gnugat\Redaktilo\EditorFactory; +use Gnugat\Redaktilo\Text; + +class LineJumpingTest extends \PHPUnit_Framework_TestCase +{ + private $editor; + + protected function setUp() + { + $this->editor = EditorFactory::createEditor(); + set_error_handler(function($errno, $errstr, $errfile, $errline) { + throw new \RuntimeException($errstr . " on line " . $errline . " in file " . $errfile); + }); + } + + /** + * @expectedException \RuntimeException + * @expectedExceptionMessage Gnugat\Redaktilo\Search\LineNumberSearchStrategy has been replaced by Text#setCurrentLineNumber on line 50 in file /home/gnucat/Projects/gnugat/redaktilo/src/Gnugat/Redaktilo/Search/LineNumberSearchStrategy.php + */ + public function testItCannotFindNonExistingLine() + { + $text = Text::fromArray(array('')); + $this->editor->jumpBelow($text, 0); + } + + protected function tearDown() + { + restore_error_handler(); + } +}