-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from williamcameron/master
Adding PHPUnit tests to provide 100% test coverage to package
- Loading branch information
Showing
5 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ Guidelines: | |
* Add docblocks for methods | ||
|
||
##Authors | ||
Martins Fridenbergs | ||
* Martins Fridenbergs | ||
* William Cameron |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,5 +20,8 @@ | |
"name": "Martins Fridenbergs", | ||
"email": "[email protected]" | ||
} | ||
] | ||
], | ||
"require-dev": { | ||
"phpunit/phpunit": "^8.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" | ||
backupGlobals="false" | ||
colors="true" | ||
beStrictAboutChangesToGlobalState="true" | ||
beStrictAboutOutputDuringTests="true" | ||
beStrictAboutTestsThatDoNotTestAnything="true" | ||
beStrictAboutTodoAnnotatedTests="true" | ||
verbose="true" | ||
bootstrap="vendor/autoload.php"> | ||
|
||
<testsuites> | ||
<testsuite name="functional"> | ||
<directory>test</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory>src</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
namespace Mtc\Stemmer; | ||
|
||
use Mtc\Stemmer\Cleaner; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* | ||
* @author William Cameron | ||
* @package Mtc\Stemmer | ||
*/ | ||
class CleanerTest extends TestCase | ||
{ | ||
public function testParseDoesntChangeCleanString(): void | ||
{ | ||
$result = Cleaner::parse('A clean string'); | ||
$this->assertEquals('A clean string', $result); | ||
} | ||
|
||
public function testParseRemovesAllSymbols(): void | ||
{ | ||
$result = Cleaner::parse('A string with some !"$%^&* symbols'); | ||
$this->assertEquals('A string with some symbols', $result); | ||
|
||
} | ||
public function testParseDoesntRemoveGBPSymbol(): void | ||
{ | ||
$result = Cleaner::parse('£19.99'); | ||
$this->assertEquals('£19 99', $result); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Mtc\Stemmer; | ||
|
||
use Mtc\Stemmer\Stemmer; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @author William Cameron | ||
* @package Mtc\Stemmer | ||
*/ | ||
class StemmerTest extends TestCase | ||
{ | ||
public function testTrue(){ | ||
$this->assertTrue(true); | ||
} | ||
|
||
public function testMultiStemReturnsHelloWorld() { | ||
$this->assertEquals(['hello', 'world'], Stemmer::multiStem("Hello World!")); | ||
} | ||
|
||
public function testMultiStemReturnsEmptyArrayForBlankString() { | ||
$this->assertEquals([], Stemmer::multiStem("")); | ||
} | ||
|
||
public function testMultiStemReturnsSingularOfPlurals() { | ||
$this->assertEquals(['singular', 'of', 'plural'], Stemmer::multiStem("Singulars of Plurals")); | ||
} | ||
|
||
/** | ||
* @dataProvider singularPluralMap | ||
*/ | ||
public function testStemStemsAPluralWordToSingular($singular, $plural) { | ||
$this->assertEquals($singular, Stemmer::stem($plural)); | ||
} | ||
|
||
public function testStemWithInvalidLanguagePassesWordThru() { | ||
$this->assertEquals("composers", Stemmer::stem("composers", "INVALIDLANG")); | ||
} | ||
|
||
|
||
/** | ||
* DataProvider and helper method for testing multiple | ||
* singular to plural words in tests. | ||
*/ | ||
public function singularPluralMap(){ | ||
return [ | ||
["", ""], | ||
["shoe", "shoes"], | ||
["plural", "plurals"], | ||
["window", "windows"], | ||
["item", "items"] | ||
]; | ||
} | ||
} |