瀏覽代碼

Add test coverage for new exception types.

Justin Hileman 13 年之前
父節點
當前提交
8b02366a3f

+ 27 - 0
test/Mustache/Test/Exception/SyntaxExceptionTest.php

@@ -0,0 +1,27 @@
+<?php
+
+/*
+ * This file is part of Mustache.php.
+ *
+ * (c) 2013 Justin Hileman
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+class Mustache_Test_Exception_SyntaxExceptionTest extends PHPUnit_Framework_TestCase
+{
+    public function testInstance()
+    {
+        $e = new Mustache_Exception_SyntaxException('whot', array('is' => 'this'));
+        $this->assertTrue($e instanceof LogicException);
+        $this->assertTrue($e instanceof Mustache_Exception);
+    }
+
+    public function testGetToken()
+    {
+        $token = array(Mustache_Tokenizer::TYPE => 'whatever');
+        $e = new Mustache_Exception_SyntaxException('ignore this', $token);
+        $this->assertEquals($token, $e->getToken());
+    }
+}

+ 32 - 0
test/Mustache/Test/Exception/UnknownFilterExceptionTest.php

@@ -0,0 +1,32 @@
+<?php
+
+/*
+ * This file is part of Mustache.php.
+ *
+ * (c) 2013 Justin Hileman
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+class Mustache_Test_Exception_UnknownFilterExceptionTest extends PHPUnit_Framework_TestCase
+{
+    public function testInstance()
+    {
+        $e = new Mustache_Exception_UnknownFilterException('bacon');
+        $this->assertTrue($e instanceof UnexpectedValueException);
+        $this->assertTrue($e instanceof Mustache_Exception);
+    }
+
+    public function testMessage()
+    {
+        $e = new Mustache_Exception_UnknownFilterException('sausage');
+        $this->assertEquals('Unknown filter: sausage', $e->getMessage());
+    }
+
+    public function testGetFilterName()
+    {
+        $e = new Mustache_Exception_UnknownFilterException('eggs');
+        $this->assertEquals('eggs', $e->getFilterName());
+    }
+}

+ 32 - 0
test/Mustache/Test/Exception/UnknownHelperExceptionTest.php

@@ -0,0 +1,32 @@
+<?php
+
+/*
+ * This file is part of Mustache.php.
+ *
+ * (c) 2013 Justin Hileman
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+class Mustache_Test_Exception_UnknownHelperExceptionTest extends PHPUnit_Framework_TestCase
+{
+    public function testInstance()
+    {
+        $e = new Mustache_Exception_UnknownHelperException('alpha');
+        $this->assertTrue($e instanceof InvalidArgumentException);
+        $this->assertTrue($e instanceof Mustache_Exception);
+    }
+
+    public function testMessage()
+    {
+        $e = new Mustache_Exception_UnknownHelperException('beta');
+        $this->assertEquals('Unknown helper: beta', $e->getMessage());
+    }
+
+    public function testGetHelperName()
+    {
+        $e = new Mustache_Exception_UnknownHelperException('gamma');
+        $this->assertEquals('gamma', $e->getHelperName());
+    }
+}

+ 32 - 0
test/Mustache/Test/Exception/UnknownTemplateExceptionTest.php

@@ -0,0 +1,32 @@
+<?php
+
+/*
+ * This file is part of Mustache.php.
+ *
+ * (c) 2013 Justin Hileman
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+class Mustache_Test_Exception_UnknownTemplateExceptionTest extends PHPUnit_Framework_TestCase
+{
+    public function testInstance()
+    {
+        $e = new Mustache_Exception_UnknownTemplateException('mario');
+        $this->assertTrue($e instanceof InvalidArgumentException);
+        $this->assertTrue($e instanceof Mustache_Exception);
+    }
+
+    public function testMessage()
+    {
+        $e = new Mustache_Exception_UnknownTemplateException('luigi');
+        $this->assertEquals('Unknown template: luigi', $e->getMessage());
+    }
+
+    public function testGetTemplateName()
+    {
+        $e = new Mustache_Exception_UnknownTemplateException('yoshi');
+        $this->assertEquals('yoshi', $e->getTemplateName());
+    }
+}