/** * Test total word count from text reader. * * @return void */ public function testWordCount() { $reader = new BuzzwordReader(); $reader->readTextContent("win-win, synergy, agile, test some more"); $wordCount = $reader->getTotalWordCount(); $this->assertEquals(6, $wordCount); }
} else { $buzzwordText = (string) isset($argv[1]) ? $argv[1] : false; if ($buzzwordText) { $buzzwords = $buzzwordReader->readTextContent($buzzwordText); } } $help = (bool) isset($options['h']) ? true : false; if ($help || count($buzzwords) < 1) { echo <<<HELP Usage: \$ php buzzwords.php <text> \$ php buzzwords.php --file[=<file>] \$ php buzzwords.php --url[=<url>] -h Help --file=<file> Parse file as having a box dimension on each line --url=<url> Parse file as having a box dimension on each line HELP; } $totalWords = $buzzwordReader->getTotalWordCount(); if ($totalWords > 0) { echo "Total Words: {$totalWords}\n"; foreach ($buzzwords as $word => $count) { // Make sure to adjust the percentage to include how many words are in each phrase. $adjCount = $count * str_word_count($word); $percent = round($adjCount / $totalWords, 2) * 100 . "%"; echo "{$word}: ({$count} - {$percent})\n"; } }