Skip to content

Commit 5604802

Browse files
committed
Avoid printing a php notice for each issue
The interpreter wants us to do this `end` shenanigan. Getting this method under test actually _required_ us to avoid the notice, which is kind of cool.
1 parent f8852f0 commit 5604802

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

Category.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ public static function categoryFor($checkName)
6666

6767
public static function documentationFor($checkName)
6868
{
69-
$rule = array_pop(
70-
explode("/", $checkName)
71-
);
69+
$checkNameParts = explode("/", $checkName);
70+
end($checkNameParts);
71+
$rule = array_pop($checkNameParts);
7272

7373
$filePath = dirname(__FILE__) . "/content/" . strtolower($rule) . ".txt";
7474

tests/CategoryTest.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace PHPMD\Tests;
4+
5+
use PHPMD\Category\Category;
6+
7+
class CategoryTest extends \PHPUnit_Framework_TestCase
8+
{
9+
10+
public function testCategoryFor()
11+
{
12+
$category = Category::categoryFor("Design/EvalExpression");
13+
$this->assertEquals("Security", $category);
14+
}
15+
16+
public function testDocumentationFor()
17+
{
18+
$documentation = Category::documentationFor("Design/EvalExpression");
19+
$this->assertContains("An eval-expression is untestable", $documentation);
20+
}
21+
}

0 commit comments

Comments
 (0)