Created
October 29, 2010 17:12
-
-
Save kriswallsmith/653921 to your computer and use it in GitHub Desktop.
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
<?php | |
class Tag | |
{ | |
public function normalizeName($name) | |
{ | |
$normal = trim($name); | |
$normal = strtolower($normal); | |
return $normal; | |
} | |
} |
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
<?php | |
class TagTest extends PHPUnit_Framework_TestCase | |
{ | |
/** | |
* @covers Tag::normalizeName | |
* @dataProvider provideNormalizeName | |
*/ | |
public function testNormalizeName($input, $expected) | |
{ | |
$tag = new Tag(); | |
$this->assertEquals($expected, $tag->normalizeName($input)); | |
} | |
public function provideNormalizeName() | |
{ | |
return array( | |
array('foo', 'foo'), | |
array('FOO', 'foo'), | |
array(' foo ', 'foo'), | |
array(' FOO ', 'foo'), | |
); | |
} | |
} |
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
<?php | |
class Tag | |
{ | |
protected $normalizer; | |
public function __construct(Normalizer $normalizer) | |
{ | |
$this->normalizer = $normalizer; | |
} | |
public function normalizeName($name) | |
{ | |
return $this->normalizer->normalize($name); | |
} | |
} |
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
<?php | |
class TagTest extends PHPUnit_Framework_TestCase | |
{ | |
/** | |
* @covers Tag::normalizeName | |
*/ | |
public function testNormalizeName() | |
{ | |
$input = 'foo'; | |
$expected = 'foo'; | |
// the final "false" tells PHPUnit not to call the Normalizer | |
// constructor because it requires another dependency, which we don't | |
// care about right now | |
$normalizer = $this->getMock('Normalizer', array(), array(), '', false); | |
$normalizer | |
->expects($this->once()) | |
->method('normalize') | |
->with($input) | |
->will($this->returnValue($expected)); | |
$tag = new Tag($normalizer); | |
$this->assertEquals($expected, $tag->normalizeName($input)); | |
} | |
} |
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
<?php | |
class TagTest extends PHPUnit_Framework_TestCase | |
{ | |
/** | |
* @covers Tag::normalizeName | |
*/ | |
public function testNormalizeName() | |
{ | |
$input = 'foo'; | |
$expected = 'foo'; | |
$normalizer = $this->getMockBuilder('Normalizer') | |
->disableOriginalConstructor() | |
->getMock(); | |
$normalizer | |
->expects($this->once()) | |
->method('normalize') | |
->with($input) | |
->will($this->returnValue($expected)); | |
$tag = new Tag($normalizer); | |
$this->assertEquals($expected, $tag->normalizeName($input)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment