Skip to content

Commit

Permalink
Merge pull request #1 from williamcameron/master
Browse files Browse the repository at this point in the history
Adding PHPUnit tests to provide 100% test coverage to package
  • Loading branch information
MaFx authored Oct 4, 2019
2 parents a52a17a + 2a6dc55 commit 5a552db
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ Guidelines:
* Add docblocks for methods

##Authors
Martins Fridenbergs
* Martins Fridenbergs
* William Cameron
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@
"name": "Martins Fridenbergs",
"email": "[email protected]"
}
]
],
"require-dev": {
"phpunit/phpunit": "^8.3"
}
}
24 changes: 24 additions & 0 deletions phpunit.xml
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>
32 changes: 32 additions & 0 deletions test/CleanerTest.php
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);

}
}
55 changes: 55 additions & 0 deletions test/StemmerTest.php
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"]
];
}
}

0 comments on commit 5a552db

Please sign in to comment.