Skip to content

Commit

Permalink
Add unit test to cover normalisation with and without mbstring extension
Browse files Browse the repository at this point in the history
  • Loading branch information
wyrfel committed Jun 19, 2018
1 parent a7f4035 commit e9cfc5c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 6 deletions.
8 changes: 2 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="vendor/autoload.php"
<phpunit bootstrap="tests/bootstrap.php"
colors="true"
>
<logging>
<log type="coverage-html" target="./tests/coverage" lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-clover" target="./tests/coverage/coverage.xml"/>
<log type="coverage-php" target="./tests/coverage/coverage.serialized"/>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
<log type="json" target="./tests/coverage/logfile.json"/>
<log type="tap" target="./tests/coverage/logfile.tap"/>
<log type="junit" target="./tests/coverage/logfile.xml" logIncompleteSkipped="false"/>
<log type="junit" target="./tests/coverage/logfile.xml"/>
<log type="testdox-html" target="./tests/coverage/testdox.html"/>
<log type="testdox-text" target="./tests/coverage/testdox.txt"/>
</logging>
Expand All @@ -21,9 +20,6 @@
<directory suffix=".php">tests</directory>
</exclude>
</whitelist>
<blacklist>
<directory>./vendor</directory>
</blacklist>
</filter>
<testsuites>
<testsuite name="The Iconic Name Parser Test Suite">
Expand Down
57 changes: 57 additions & 0 deletions tests/Part/NormalisationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace TheIconic\NameParser\Part;

use phpmock\phpunit\PHPMock;
use PHPUnit\Framework\TestCase;

class NormalisationTest extends TestCase
{
use PHPMock;

/**
* make sure we test both with and without mb_string support
*/
public function testCamelcasingWorksWithMbString()
{
$functionExistsMock = $this->getFunctionMock(__NAMESPACE__, 'function_exists');
$functionExistsMock->expects($this->any())
->with('mb_convert_case')
->willReturn(true);

$part = new Lastname('McDonald');
$this->assertEquals('McDonald', $part->normalize());

$part = new Lastname('übel');
$this->assertEquals('Übel', $part->normalize());

$part = new Firstname('Anne-Marie');
$this->assertEquals('Anne-Marie', $part->normalize());

$part = new Firstname('etna');
$this->assertEquals('Etna', $part->normalize());
}

/**
* make sure we test both with and without mb_string support
*/
public function testCamelcasingWorksWithoutMbString()
{
$functionExistsMock = $this->getFunctionMock(__NAMESPACE__, 'function_exists');
$functionExistsMock->expects($this->any())
->with('mb_convert_case')
->willReturn(false);

$part = new Lastname('McDonald');
$this->assertEquals('McDonald', $part->normalize());

$part = new Lastname('ubel');
$this->assertEquals('Ubel', $part->normalize());

$part = new Firstname('Anne-Marie');
$this->assertEquals('Anne-Marie', $part->normalize());

$part = new Firstname('etna');
$this->assertEquals('Etna', $part->normalize());
}
}
7 changes: 7 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

use phpmock\phpunit\PHPMock;

PHPMock::defineFunctionMock('TheIconic\NameParser\Part', 'function_exists');

require dirname(__DIR__) . '/vendor/autoload.php';

0 comments on commit e9cfc5c

Please sign in to comment.