Location: PHPKode > scripts > Deefour SpellCheck > SpellCheck-1.0/tests/SpellCheckTest.php
<?php
use \Deefour;

require_once dirname(__FILE__) . '/../lib/SpellCheck.class.php';
require_once 'PHPUnit/Framework.php';

class SpellCheckTest extends PHPUnit_Framework_TestCase {
  
  protected function setUp(){
    $this->misspelledText = 'sme porly spellled txt';
    $this->correctText = 'some poorly spelled text';    
  }
  
  public function testSetTextConstructor(){
    $spellCheck = new \Deefour\SpellCheck($this->misspelledText);
    
    $this->assertEquals($this->misspelledText, $spellCheck->getOriginalText());    
  }
  
  public function testSetTextExplicit(){
    $spellCheck = new \Deefour\SpellCheck();
    $spellCheck->setText($this->misspelledText);
    
    $this->assertEquals($this->misspelledText, $spellCheck->getOriginalText());
    
    return $spellCheck;
  }
  
  /**
   * @depends testSetTextExplicit
   */
  public function testMagicToStringIsNull(\Deefour\Spellcheck $spellCheck){
    $this->assertSame((string)$spellCheck, '');
  }
  
  /**
   * @depends testSetTextExplicit
   */
  public function testHasChangedBeforeProcess(\Deefour\Spellcheck $spellCheck){
    $this->assertFalse($spellCheck->hasChanged());
  }
  
  /**
   * @depends testSetTextExplicit
   * @expectedException \BadMethodCallException
   */
  public function testMagicGetters(\Deefour\SpellCheck $spellCheck){
    $this->assertSame($this->misspelledText, $spellCheck->getOriginalText());
    $this->assertNull($spellCheck->getCorrectedText());
    
    // Throw the \BadMethodCallException
    $spellCheck->getFakePropertyName();
  }
  
  /**
   * @expectedException \BadMethodCallException
   */
  public function testPrematureProcess(){
    $spellCheck = new \Deefour\SpellCheck();    
    $spellCheck->process();
  }
  
  /**
   * @depends testSetTextExplicit
   */
  public function testFullPath1(\Deefour\SpellCheck $spellCheck){
    $spellCheck->process();
    
    $this->assertSame($this->misspelledText, $spellCheck->getOriginalText(), 'Assert original text is still the same after processing');
    $this->assertTrue($spellCheck->getHasProcessed(), 'Assert now that the private _hasProcessed flag has been changed');
    $this->assertThat($spellCheck->getCorrectedText(),
                      $this->logicalNot(
                        $this->isNull()
                      ), 
                      'Assert the private _correcteText has been updated with a non-null value');
    $this->assertTrue($spellCheck->hasChanged());   
    
    return $spellCheck; 
  }
  
  /**
   * @depends testFullPath1
   */
  public function testMagicToStringHasValue(\Deefour\SpellCheck $spellCheck){
    $this->assertThat((string)$spellCheck,
                      $this->logicalAnd(
                        $this->isType('string'), 
                        $this->matchesRegularExpression('/.+/')),
                      'Assert that __toString returns a string and that it is not empty anymore');
  }
  
  /**
   * @depends testFullPath1
   */
  public function testStateAfterSetTextAfterProcess(\Deefour\SpellCheck $spellCheck){
    $this->assertThat($spellCheck->process(),
                      $this->logicalNot(
                        $this->isNull()
                      ));
    $this->assertSame($spellCheck->process(), $spellCheck->getCorrectedText(), 'Assert the re-calling \Deefour\SpellCheck::process() a second time simply returns the currected text');

    $spellCheck->setText('some new badlly spled strng.');    
    
    $this->assertFalse($spellCheck->getHasProcessed());
    $this->assertNull($spellCheck->getCorrectedText());
    $this->assertFalse($spellCheck->hasChanged());
  }
  
}

Return current item: Deefour SpellCheck