{"thread":{"id":"54644","subject":"[PATCH] userdiff: php: Improved tests catching \"abstract\" and \"final\" functions","startedAt":"2020-11-14T21:18:34Z","lastAt":"2020-11-16T22:21:50Z","messageCount":3,"participants":["Javier Spagnoletti via GitGitGadget","Johannes Sixt","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"409964","messageId":"pull.915.git.git.1605388687554.gitgitgadget@gmail.com","threadId":"54644","inReplyTo":null,"subject":"[PATCH] userdiff: php: Improved tests catching \"abstract\" and \"final\" functions","fromName":"Javier Spagnoletti via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-11-14T21:18:07Z","receivedAt":"2020-11-14T21:18:34Z","isPatch":true,"sender":{"key":"name:Javier Spagnoletti","avatar":null},"body":"From: Javier Spagnoletti <phansys@gmail.com>\n\nSince the original tests cases were using other detectable keywords (like\n\"public\" or \"protected\"), they are able to pass even if the keywords\nintended to be covered are not present.\n\nSigned-off-by: Javier Spagnoletti <phansys@gmail.com>\n---\n    userdiff: php: Improved test cases used to catch \"abstract\" and \"final\"\n    functions\n    \n    Since the original tests cases were using other detectable keywords\n    (like \"public\" or \"protected\"), they are able to pass even if the\n    keywords intended to be covered are not present. In the case of the test\n    for \"abstract\" keyword, the method's body was removed in the fixture,\n    since PHP doesn't allow an abstract method to have a body.\n    \n    Signed-off-by: Javier Spagnoletti phansys@gmail.com [phansys@gmail.com]\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-915%2Fphansys%2Fpr_864-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-915/phansys/pr_864-v1\nPull-Request: https://github.com/git/git/pull/915\n\n t/t4018/php-abstract-method | 5 ++++-\n t/t4018/php-final-method    | 2 +-\n 2 files changed, 5 insertions(+), 2 deletions(-)\n\ndiff --git a/t/t4018/php-abstract-method b/t/t4018/php-abstract-method\nindex ce215df75a..14d77e6c15 100644\n--- a/t/t4018/php-abstract-method\n+++ b/t/t4018/php-abstract-method\n@@ -1,7 +1,10 @@\n abstract class Klass\n {\n-    abstract public function RIGHT(): ?string\n+    abstract function RIGHT(): ?string\n     {\n+        // PHP doesn't allow abstract methods to have a body,\n+        // but this is here just for diff ckeck purposes.\n+\n         return 'ChangeMe';\n     }\n }\ndiff --git a/t/t4018/php-final-method b/t/t4018/php-final-method\nindex 537fb8ad9a..f7dd2dec17 100644\n--- a/t/t4018/php-final-method\n+++ b/t/t4018/php-final-method\n@@ -1,6 +1,6 @@\n class Klass\n {\n-    final public function RIGHT(): string\n+    final function RIGHT(): string\n     {\n         return 'ChangeMe';\n     }\n\nbase-commit: e31aba42fb12bdeb0f850829e008e1e3f43af500\n-- \ngitgitgadget\n"},{"id":"409969","messageId":"ce6d8478-41f7-3664-12bb-9f91e5231f61@kdbg.org","threadId":"54644","inReplyTo":"pull.915.git.git.1605388687554.gitgitgadget@gmail.com","subject":"Re: [PATCH] userdiff: php: Improved tests catching \"abstract\" and \"final\" functions","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2020-11-14T23:46:18Z","receivedAt":"2020-11-14T23:46:39Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 14.11.20 um 22:18 schrieb Javier Spagnoletti via GitGitGadget:\n> From: Javier Spagnoletti <phansys@gmail.com>\n> \n> Since the original tests cases were using other detectable keywords (like\n> \"public\" or \"protected\"), they are able to pass even if the keywords\n> intended to be covered are not present.\n\nGood find! I had to look at the patch text, though, before I could \nunderstand what the description wants to say. How about:\n\nWe have dedicated tests that \"abstract\" and \"final\" declarations\nare picked up as hunk context. However, the tests also use the\nkeywords \"public\" and \"protected\" that by themselves denote hunk\ncontext lines. For this reason, the tests would not fail if the\npatterns for \"abstract\" and \"final\" were to become non-functional.\nRemove the distracting keywords from the two tests.\n\n> \n> Signed-off-by: Javier Spagnoletti <phansys@gmail.com>\n> ---\n>      userdiff: php: Improved test cases used to catch \"abstract\" and \"final\"\n>      functions\n>      \n>      Since the original tests cases were using other detectable keywords\n>      (like \"public\" or \"protected\"), they are able to pass even if the\n>      keywords intended to be covered are not present. In the case of the test\n>      for \"abstract\" keyword, the method's body was removed in the fixture,\n>      since PHP doesn't allow an abstract method to have a body.\n>      \n>      Signed-off-by: Javier Spagnoletti phansys@gmail.com [phansys@gmail.com]\n> \n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-915%2Fphansys%2Fpr_864-v1\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-915/phansys/pr_864-v1\n> Pull-Request: https://github.com/git/git/pull/915\n> \n>   t/t4018/php-abstract-method | 5 ++++-\n>   t/t4018/php-final-method    | 2 +-\n>   2 files changed, 5 insertions(+), 2 deletions(-)\n> \n> diff --git a/t/t4018/php-abstract-method b/t/t4018/php-abstract-method\n> index ce215df75a..14d77e6c15 100644\n> --- a/t/t4018/php-abstract-method\n> +++ b/t/t4018/php-abstract-method\n> @@ -1,7 +1,10 @@\n>   abstract class Klass\n>   {\n> -    abstract public function RIGHT(): ?string\n> +    abstract function RIGHT(): ?string\n>       {\n> +        // PHP doesn't allow abstract methods to have a body,\n> +        // but this is here just for diff ckeck purposes.\n> +\n>           return 'ChangeMe';\n>       }\n>   }\n> diff --git a/t/t4018/php-final-method b/t/t4018/php-final-method\n> index 537fb8ad9a..f7dd2dec17 100644\n> --- a/t/t4018/php-final-method\n> +++ b/t/t4018/php-final-method\n> @@ -1,6 +1,6 @@\n>   class Klass\n>   {\n> -    final public function RIGHT(): string\n> +    final function RIGHT(): string\n>       {\n>           return 'ChangeMe';\n>       }\n> \n> base-commit: e31aba42fb12bdeb0f850829e008e1e3f43af500\n> \n\n-- Hannes\n\n"},{"id":"410045","messageId":"xmqqtutp6izn.fsf@gitster.c.googlers.com","threadId":"54644","inReplyTo":"pull.915.git.git.1605388687554.gitgitgadget@gmail.com","subject":"Re: [PATCH] userdiff: php: Improved tests catching \"abstract\" and \"final\" functions","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-11-16T22:21:16Z","receivedAt":"2020-11-16T22:21:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Javier Spagnoletti via GitGitGadget\" <gitgitgadget@gmail.com>\nwrites:\n\n> From: Javier Spagnoletti <phansys@gmail.com>\n> Subject: [PATCH] userdiff: php: Improved tests catching \"abstract\" and \"final\" functions\n\nI'd suggest using this instead:\n\nSubject: [PATCH] userdiff: improve \"abstract\" and \"final\" function tests for php\n\nI am not familiar enough with PHP to know if s/function/method/ is\nmore appropriate for certain, but I suspect that would be the case.\n\n> Since the original tests cases were using other detectable keywords (like\n> \"public\" or \"protected\"), they are able to pass even if the keywords\n> intended to be covered are not present.\n\nI think you meant that other keywords that start functions were on\nthe same line and that hides if \"abstract\" alone is recognised\nwithout these other keywords?\n\nThe patch changes \"abstract public function\" to \"abstract function\";\nthe assumption is that the presence of \"public\" alone is enough for\nsuch a line to be recognised to start a function.  \n\nBut is that assumption tested elsewhere?\n\n    ... goes and looks ...\n\n    $ ls t/t4018/php-*\n    t/t4018/php-abstract-class  t/t4018/php-function   t/t4018/php-trait\n    t/t4018/php-class\t    t/t4018/php-interface\n    t/t4018/php-final-class     t/t4018/php-method\n\n    $ git grep -e public -e protected t/t4018/php-*\n    t/t4018/php-interface:    public function foo($ChangeMe);\n    t/t4018/php-method:    public static function RIGHT()\n    t/t4018/php-trait:    public function foo($ChangeMe)\n\nYou bring up \"protected\" but I do not see it mentioned anywhere in\nyour patch or in existing tests, by the way.\n\nTaking all of the above together, perhaps\n\n\tA few tests try to see if lines with \"abstract public\n\tfunction RIGHT()\" and \"final public function RIGHT()\" on\n\tthem are recognised as starting a method, but the presense\n\tof the keyword \"public\" is enough to get them recognised;\n\tensure that these lines are still recognised as the\n\tbeginning of a function without the \"public\" keyword.\n\n\tNote that t4018/php-method already tests a line with 'public\n\tstatic function RIGHT()' on it to start a function, so we\n\tare not losing test coverage for \"public\" keyword with this\n\tchange\n\nwould make it clearer?\n\n>\n> Signed-off-by: Javier Spagnoletti <phansys@gmail.com>\n> ---\n>     userdiff: php: Improved test cases used to catch \"abstract\" and \"final\"\n>     functions\n>     \n>     Since the original tests cases were using other detectable keywords\n>     (like \"public\" or \"protected\"), they are able to pass even if the\n>     keywords intended to be covered are not present. In the case of the test\n>     for \"abstract\" keyword, the method's body was removed in the fixture,\n>     since PHP doesn't allow an abstract method to have a body.\n>     \n>     Signed-off-by: Javier Spagnoletti phansys@gmail.com [phansys@gmail.com]\n>\n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-915%2Fphansys%2Fpr_864-v1\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-915/phansys/pr_864-v1\n> Pull-Request: https://github.com/git/git/pull/915\n>\n>  t/t4018/php-abstract-method | 5 ++++-\n>  t/t4018/php-final-method    | 2 +-\n>  2 files changed, 5 insertions(+), 2 deletions(-)\n>\n> diff --git a/t/t4018/php-abstract-method b/t/t4018/php-abstract-method\n> index ce215df75a..14d77e6c15 100644\n> --- a/t/t4018/php-abstract-method\n> +++ b/t/t4018/php-abstract-method\n> @@ -1,7 +1,10 @@\n>  abstract class Klass\n>  {\n> -    abstract public function RIGHT(): ?string\n> +    abstract function RIGHT(): ?string\n>      {\n> +        // PHP doesn't allow abstract methods to have a body,\n> +        // but this is here just for diff ckeck purposes.\n> +\n>          return 'ChangeMe';\n>      }\n>  }\n> diff --git a/t/t4018/php-final-method b/t/t4018/php-final-method\n> index 537fb8ad9a..f7dd2dec17 100644\n> --- a/t/t4018/php-final-method\n> +++ b/t/t4018/php-final-method\n> @@ -1,6 +1,6 @@\n>  class Klass\n>  {\n> -    final public function RIGHT(): string\n> +    final function RIGHT(): string\n>      {\n>          return 'ChangeMe';\n>      }\n>\n> base-commit: e31aba42fb12bdeb0f850829e008e1e3f43af500\n"}]}