From 9ee6fe33806539d9bf92d74e156a362a66ea6dfd Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 24 Sep 2016 12:21:25 -0700 Subject: [PATCH] adding missing dots to some exception messages --- ext/twig/twig.c | 28 +++++++-------- lib/Twig/Template.php | 20 +++++------ test/Twig/Tests/ErrorTest.php | 4 +-- ...ltiline_array_with_undefined_variable.test | 2 +- ...e_array_with_undefined_variable_again.test | 2 +- ...line_function_with_undefined_variable.test | 2 +- ...multiline_tag_with_undefined_variable.test | 2 +- .../Fixtures/macros/varargs_argument.test | 1 - .../regression/combined_debug_info.test | 2 +- .../Tests/Fixtures/tags/embed/error_line.test | 2 +- test/Twig/Tests/TemplateTest.php | 36 +++++++++---------- 11 files changed, 50 insertions(+), 51 deletions(-) diff --git a/ext/twig/twig.c b/ext/twig/twig.c index e74e3d8ef..3c35520f4 100644 --- a/ext/twig/twig.c +++ b/ext/twig/twig.c @@ -144,7 +144,7 @@ static zval *TWIG_GET_ARRAYOBJECT_ELEMENT(zval *object, zval *offset TSRMLS_DC) if (!retval) { if (!EG(exception)) { - zend_error(E_ERROR, "Undefined offset for object of type %s used as array", ce->name); + zend_error(E_ERROR, "Undefined offset for object of type %s used as array.", ce->name); } return NULL; } @@ -167,7 +167,7 @@ static int TWIG_ISSET_ARRAYOBJECT_ELEMENT(zval *object, zval *offset TSRMLS_DC) if (!retval) { if (!EG(exception)) { - zend_error(E_ERROR, "Undefined offset for object of type %s used as array", ce->name); + zend_error(E_ERROR, "Undefined offset for object of type %s used as array.", ce->name); } return 0; } @@ -811,15 +811,15 @@ PHP_FUNCTION(twig_template_get_attributes) } */ if (TWIG_INSTANCE_OF(object, zend_ce_arrayaccess TSRMLS_CC)) { - TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Key \"%s\" in object with ArrayAccess of class \"%s\" does not exist", item, TWIG_GET_CLASS_NAME(object TSRMLS_CC)); + TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Key \"%s\" in object with ArrayAccess of class \"%s\" does not exist.", item, TWIG_GET_CLASS_NAME(object TSRMLS_CC)); } else if (Z_TYPE_P(object) == IS_OBJECT) { - TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Impossible to access a key \"%s\" on an object of class \"%s\" that does not implement ArrayAccess interface", item, TWIG_GET_CLASS_NAME(object TSRMLS_CC)); + TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Impossible to access a key \"%s\" on an object of class \"%s\" that does not implement ArrayAccess interface.", item, TWIG_GET_CLASS_NAME(object TSRMLS_CC)); } else if (Z_TYPE_P(object) == IS_ARRAY) { if (0 == zend_hash_num_elements(Z_ARRVAL_P(object))) { - TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Key \"%s\" does not exist as the array is empty", item); + TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Key \"%s\" does not exist as the array is empty.", item); } else { char *array_keys = TWIG_IMPLODE_ARRAY_KEYS(", ", object TSRMLS_CC); - TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Key \"%s\" for array with keys \"%s\" does not exist", item, array_keys); + TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Key \"%s\" for array with keys \"%s\" does not exist.", item, array_keys); efree(array_keys); } } else { @@ -829,15 +829,15 @@ PHP_FUNCTION(twig_template_get_attributes) convert_to_string(object); TWIG_RUNTIME_ERROR(template TSRMLS_CC, (strcmp("array", type) == 0) - ? "Impossible to access a key (\"%s\") on a %s variable" - : "Impossible to access an attribute (\"%s\") on a %s variable", + ? "Impossible to access a key (\"%s\") on a %s variable." + : "Impossible to access an attribute (\"%s\") on a %s variable.", item, type_name); } else { convert_to_string(object); TWIG_RUNTIME_ERROR(template TSRMLS_CC, (strcmp("array", type) == 0) - ? "Impossible to access a key (\"%s\") on a %s variable (\"%s\")" - : "Impossible to access an attribute (\"%s\") on a %s variable (\"%s\")", + ? "Impossible to access a key (\"%s\") on a %s variable (\"%s\")." + : "Impossible to access an attribute (\"%s\") on a %s variable (\"%s\").", item, type_name, Z_STRVAL_P(object)); } zval_ptr_dtor(&object); @@ -883,11 +883,11 @@ PHP_FUNCTION(twig_template_get_attributes) if (Z_TYPE_P(object) == IS_NULL) { convert_to_string_ex(&object); - TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Impossible to invoke a method (\"%s\") on a %s variable", item, type_name); + TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Impossible to invoke a method (\"%s\") on a %s variable.", item, type_name); } else { convert_to_string_ex(&object); - TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Impossible to invoke a method (\"%s\") on a %s variable (\"%s\")", item, type_name, Z_STRVAL_P(object)); + TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Impossible to invoke a method (\"%s\") on a %s variable (\"%s\").", item, type_name, Z_STRVAL_P(object)); } zval_ptr_dtor(&object); @@ -1020,7 +1020,7 @@ PHP_FUNCTION(twig_template_get_attributes) return null; } - throw new Twig_Error_Runtime(sprintf('Method "%s" for object "%s" does not exist', $item, get_class($object)), -1, $this->getTemplateName()); + throw new Twig_Error_Runtime(sprintf('Method "%s" for object "%s" does not exist.', $item, get_class($object)), -1, $this->getTemplateName()); } if ($isDefinedTest) { @@ -1040,7 +1040,7 @@ PHP_FUNCTION(twig_template_get_attributes) efree(item); return; } - TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Neither the property \"%s\" nor one of the methods \"%s()\", \"get%s()\"/\"is%s()\" or \"__call()\" exist and have public access in class \"%s\"", item, item, item, item, TWIG_GET_CLASS_NAME(object TSRMLS_CC)); + TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Neither the property \"%s\" nor one of the methods \"%s()\", \"get%s()\"/\"is%s()\" or \"__call()\" exist and have public access in class \"%s\".", item, item, item, item, TWIG_GET_CLASS_NAME(object TSRMLS_CC)); efree(item); return; } diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index 2a80410ce..d0e215c1b 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -477,25 +477,25 @@ abstract class Twig_Template implements Twig_TemplateInterface } if ($object instanceof ArrayAccess) { - $message = sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist', $arrayItem, get_class($object)); + $message = sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist.', $arrayItem, get_class($object)); } elseif (is_object($object)) { - $message = sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface', $item, get_class($object)); + $message = sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface.', $item, get_class($object)); } elseif (is_array($object)) { if (empty($object)) { - $message = sprintf('Key "%s" does not exist as the array is empty', $arrayItem); + $message = sprintf('Key "%s" does not exist as the array is empty.', $arrayItem); } else { - $message = sprintf('Key "%s" for array with keys "%s" does not exist', $arrayItem, implode(', ', array_keys($object))); + $message = sprintf('Key "%s" for array with keys "%s" does not exist.', $arrayItem, implode(', ', array_keys($object))); } } elseif (self::ARRAY_CALL === $type) { if (null === $object) { - $message = sprintf('Impossible to access a key ("%s") on a null variable', $item); + $message = sprintf('Impossible to access a key ("%s") on a null variable.', $item); } else { - $message = sprintf('Impossible to access a key ("%s") on a %s variable ("%s")', $item, gettype($object), $object); + $message = sprintf('Impossible to access a key ("%s") on a %s variable ("%s").', $item, gettype($object), $object); } } elseif (null === $object) { - $message = sprintf('Impossible to access an attribute ("%s") on a null variable', $item); + $message = sprintf('Impossible to access an attribute ("%s") on a null variable.', $item); } else { - $message = sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s")', $item, gettype($object), $object); + $message = sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s").', $item, gettype($object), $object); } throw new Twig_Error_Runtime($message, -1, $this->getTemplateName()); @@ -512,9 +512,9 @@ abstract class Twig_Template implements Twig_TemplateInterface } if (null === $object) { - $message = sprintf('Impossible to invoke a method ("%s") on a null variable', $item); + $message = sprintf('Impossible to invoke a method ("%s") on a null variable.', $item); } else { - $message = sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s")', $item, gettype($object), $object); + $message = sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s").', $item, gettype($object), $object); } throw new Twig_Error_Runtime($message, -1, $this->getTemplateName()); diff --git a/test/Twig/Tests/ErrorTest.php b/test/Twig/Tests/ErrorTest.php index d58c40b8d..a898cb1fd 100644 --- a/test/Twig/Tests/ErrorTest.php +++ b/test/Twig/Tests/ErrorTest.php @@ -38,7 +38,7 @@ class Twig_Tests_ErrorTest extends PHPUnit_Framework_TestCase $this->fail(); } catch (Twig_Error_Runtime $e) { - $this->assertEquals('Variable "foo" does not exist in "index.html" at line 3', $e->getMessage()); + $this->assertEquals('Variable "foo" does not exist in "index.html" at line 3.', $e->getMessage()); $this->assertEquals(3, $e->getTemplateLine()); $this->assertEquals('index.html', $e->getTemplateFile()); } @@ -69,7 +69,7 @@ class Twig_Tests_ErrorTest extends PHPUnit_Framework_TestCase $this->fail(); } catch (Twig_Error_Runtime $e) { - $this->assertEquals(sprintf('Variable "foo" does not exist in "%s" at line %d', $name, $line), $e->getMessage()); + $this->assertEquals(sprintf('Variable "foo" does not exist in "%s" at line %d.', $name, $line), $e->getMessage()); $this->assertEquals($line, $e->getTemplateLine()); $this->assertEquals($name, $e->getTemplateFile()); } diff --git a/test/Twig/Tests/Fixtures/exceptions/multiline_array_with_undefined_variable.test b/test/Twig/Tests/Fixtures/exceptions/multiline_array_with_undefined_variable.test index ce49165dc..7ff2eedb7 100644 --- a/test/Twig/Tests/Fixtures/exceptions/multiline_array_with_undefined_variable.test +++ b/test/Twig/Tests/Fixtures/exceptions/multiline_array_with_undefined_variable.test @@ -15,4 +15,4 @@ Exception for multiline array with undefined variable --DATA-- return array('foobar' => 'foobar') --EXCEPTION-- -Twig_Error_Runtime: Variable "foo2" does not exist in "index.twig" at line 11 +Twig_Error_Runtime: Variable "foo2" does not exist in "index.twig" at line 11. diff --git a/test/Twig/Tests/Fixtures/exceptions/multiline_array_with_undefined_variable_again.test b/test/Twig/Tests/Fixtures/exceptions/multiline_array_with_undefined_variable_again.test index e3c040f9c..c425069bf 100644 --- a/test/Twig/Tests/Fixtures/exceptions/multiline_array_with_undefined_variable_again.test +++ b/test/Twig/Tests/Fixtures/exceptions/multiline_array_with_undefined_variable_again.test @@ -15,4 +15,4 @@ Exception for multiline array with undefined variable --DATA-- return array() --EXCEPTION-- -Twig_Error_Runtime: Variable "foobar" does not exist in "index.twig" at line 7 +Twig_Error_Runtime: Variable "foobar" does not exist in "index.twig" at line 7. diff --git a/test/Twig/Tests/Fixtures/exceptions/multiline_function_with_undefined_variable.test b/test/Twig/Tests/Fixtures/exceptions/multiline_function_with_undefined_variable.test index d799a3906..2f94a5ee9 100644 --- a/test/Twig/Tests/Fixtures/exceptions/multiline_function_with_undefined_variable.test +++ b/test/Twig/Tests/Fixtures/exceptions/multiline_function_with_undefined_variable.test @@ -9,4 +9,4 @@ Foo --DATA-- return array() --EXCEPTION-- -Twig_Error_Runtime: Variable "with_context" does not exist in "index.twig" at line 3 +Twig_Error_Runtime: Variable "with_context" does not exist in "index.twig" at line 3. diff --git a/test/Twig/Tests/Fixtures/exceptions/multiline_tag_with_undefined_variable.test b/test/Twig/Tests/Fixtures/exceptions/multiline_tag_with_undefined_variable.test index 096a5dbf5..7b3b1daf9 100644 --- a/test/Twig/Tests/Fixtures/exceptions/multiline_tag_with_undefined_variable.test +++ b/test/Twig/Tests/Fixtures/exceptions/multiline_tag_with_undefined_variable.test @@ -9,4 +9,4 @@ Foo --DATA-- return array() --EXCEPTION-- -Twig_Error_Runtime: Variable "vars" does not exist in "index.twig" at line 3 +Twig_Error_Runtime: Variable "vars" does not exist in "index.twig" at line 3. diff --git a/test/Twig/Tests/Fixtures/macros/varargs_argument.test b/test/Twig/Tests/Fixtures/macros/varargs_argument.test index 9cfbbd205..800c262e7 100644 --- a/test/Twig/Tests/Fixtures/macros/varargs_argument.test +++ b/test/Twig/Tests/Fixtures/macros/varargs_argument.test @@ -5,4 +5,3 @@ macro with varargs argument {% endmacro %} --EXCEPTION-- Twig_Error_Syntax: The argument "varargs" in macro "test" cannot be defined because the variable "varargs" is reserved for arbitrary arguments in "index.twig" at line 2. - diff --git a/test/Twig/Tests/Fixtures/regression/combined_debug_info.test b/test/Twig/Tests/Fixtures/regression/combined_debug_info.test index df485783a..ff977ad62 100644 --- a/test/Twig/Tests/Fixtures/regression/combined_debug_info.test +++ b/test/Twig/Tests/Fixtures/regression/combined_debug_info.test @@ -12,4 +12,4 @@ foo --DATA-- return array('foo' => 'foo'); --EXCEPTION-- -Twig_Error_Runtime: Impossible to access an attribute ("bar") on a string variable ("foo") in "foo" at line 3 +Twig_Error_Runtime: Impossible to access an attribute ("bar") on a string variable ("foo") in "foo" at line 3. diff --git a/test/Twig/Tests/Fixtures/tags/embed/error_line.test b/test/Twig/Tests/Fixtures/tags/embed/error_line.test index 71ab2e018..431473707 100644 --- a/test/Twig/Tests/Fixtures/tags/embed/error_line.test +++ b/test/Twig/Tests/Fixtures/tags/embed/error_line.test @@ -13,4 +13,4 @@ BAR --DATA-- return array() --EXCEPTION-- -Twig_Error_Runtime: Variable "nothing" does not exist in "index.twig" at line 5 +Twig_Error_Runtime: Variable "nothing" does not exist in "index.twig" at line 5. diff --git a/test/Twig/Tests/TemplateTest.php b/test/Twig/Tests/TemplateTest.php index 80412c9f9..ba10e6895 100644 --- a/test/Twig/Tests/TemplateTest.php +++ b/test/Twig/Tests/TemplateTest.php @@ -56,22 +56,22 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase public function getAttributeExceptions() { $tests = array( - array('{{ string["a"] }}', 'Impossible to access a key ("a") on a string variable ("foo") in "%s" at line 1', false), - array('{{ null["a"] }}', 'Impossible to access a key ("a") on a null variable in "%s" at line 1', false), - array('{{ empty_array["a"] }}', 'Key "a" does not exist as the array is empty in "%s" at line 1', false), - array('{{ array["a"] }}', 'Key "a" for array with keys "foo" does not exist in "%s" at line 1', false), - array('{{ array_access["a"] }}', 'Key "a" in object with ArrayAccess of class "Twig_TemplateArrayAccessObject" does not exist in "%s" at line 1', false), - array('{{ string.a }}', 'Impossible to access an attribute ("a") on a string variable ("foo") in "%s" at line 1', false), - array('{{ string.a() }}', 'Impossible to invoke a method ("a") on a string variable ("foo") in "%s" at line 1', false), - array('{{ null.a }}', 'Impossible to access an attribute ("a") on a null variable in "%s" at line 1', false), - array('{{ null.a() }}', 'Impossible to invoke a method ("a") on a null variable in "%s" at line 1', false), - array('{{ empty_array.a }}', 'Key "a" does not exist as the array is empty in "%s" at line 1', false), - array('{{ array.a }}', 'Key "a" for array with keys "foo" does not exist in "%s" at line 1', false), - array('{{ attribute(array, -10) }}', 'Key "-10" for array with keys "foo" does not exist in "%s" at line 1', false), - array('{{ array_access.a }}', 'Neither the property "a" nor one of the methods "a()", "geta()"/"isa()" or "__call()" exist and have public access in class "Twig_TemplateArrayAccessObject" in "%s" at line 1', false), - array('{% from _self import foo %}{% macro foo(obj) %}{{ obj.missing_method() }}{% endmacro %}{{ foo(array_access) }}', 'Neither the property "missing_method" nor one of the methods "missing_method()", "getmissing_method()"/"ismissing_method()" or "__call()" exist and have public access in class "Twig_TemplateArrayAccessObject" in "%s" at line 1', false), + array('{{ string["a"] }}', 'Impossible to access a key ("a") on a string variable ("foo") in "%s" at line 1.', false), + array('{{ null["a"] }}', 'Impossible to access a key ("a") on a null variable in "%s" at line 1.', false), + array('{{ empty_array["a"] }}', 'Key "a" does not exist as the array is empty in "%s" at line 1.', false), + array('{{ array["a"] }}', 'Key "a" for array with keys "foo" does not exist in "%s" at line 1.', false), + array('{{ array_access["a"] }}', 'Key "a" in object with ArrayAccess of class "Twig_TemplateArrayAccessObject" does not exist in "%s" at line 1.', false), + array('{{ string.a }}', 'Impossible to access an attribute ("a") on a string variable ("foo") in "%s" at line 1.', false), + array('{{ string.a() }}', 'Impossible to invoke a method ("a") on a string variable ("foo") in "%s" at line 1.', false), + array('{{ null.a }}', 'Impossible to access an attribute ("a") on a null variable in "%s" at line 1.', false), + array('{{ null.a() }}', 'Impossible to invoke a method ("a") on a null variable in "%s" at line 1.', false), + array('{{ empty_array.a }}', 'Key "a" does not exist as the array is empty in "%s" at line 1.', false), + array('{{ array.a }}', 'Key "a" for array with keys "foo" does not exist in "%s" at line 1.', false), + array('{{ attribute(array, -10) }}', 'Key "-10" for array with keys "foo" does not exist in "%s" at line 1.', false), + array('{{ array_access.a }}', 'Neither the property "a" nor one of the methods "a()", "geta()"/"isa()" or "__call()" exist and have public access in class "Twig_TemplateArrayAccessObject" in "%s" at line 1.', false), + array('{% from _self import foo %}{% macro foo(obj) %}{{ obj.missing_method() }}{% endmacro %}{{ foo(array_access) }}', 'Neither the property "missing_method" nor one of the methods "missing_method()", "getmissing_method()"/"ismissing_method()" or "__call()" exist and have public access in class "Twig_TemplateArrayAccessObject" in "%s" at line 1.', false), array('{{ magic_exception.test }}', 'An exception has been thrown during the rendering of a template ("Hey! Don\'t try to isset me!") in "%s" at line 1.', false), - array('{{ object["a"] }}', 'Impossible to access a key "a" on an object of class "stdClass" that does not implement ArrayAccess interface in "%s" at line 1', false), + array('{{ object["a"] }}', 'Impossible to access a key "a" on an object of class "stdClass" that does not implement ArrayAccess interface in "%s" at line 1.', false), ); if (function_exists('twig_template_get_attributes')) { @@ -387,9 +387,9 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase // tests when input is not an array or object $tests = array_merge($tests, array( - array(false, null, 42, 'a', array(), $anyType, false, 'Impossible to access an attribute ("a") on a integer variable ("42")'), - array(false, null, 'string', 'a', array(), $anyType, false, 'Impossible to access an attribute ("a") on a string variable ("string")'), - array(false, null, array(), 'a', array(), $anyType, false, 'Key "a" does not exist as the array is empty'), + array(false, null, 42, 'a', array(), $anyType, false, 'Impossible to access an attribute ("a") on a integer variable ("42").'), + array(false, null, 'string', 'a', array(), $anyType, false, 'Impossible to access an attribute ("a") on a string variable ("string").'), + array(false, null, array(), 'a', array(), $anyType, false, 'Key "a" does not exist as the array is empty.'), )); // add twig_template_get_attributes tests