Example #1
0
 /**
  * @test
  */
 public function it_does_its_job()
 {
     // Setup.
     $validator = new TestValidator(null);
     $file = $this->mockUtility("File");
     $file->shouldReceive("exists")->times(3)->andReturn(false, false, true);
     $composer = $this->mockUtility("Composer");
     $composer->shouldReceive("getDependencies")->times(3)->with(null, true)->andReturn(["weird/package", "behat/behat"], ["phpspec/phpspec"], ["phpunit/phpunit"]);
     $validator->utility("File", $file);
     $validator->utility("Composer", $composer);
     // Test.
     // 1st scenario: no testing frameworks were found in your composer.json.
     $messages = $this->runValidator($validator);
     $this->assertTrue($messages->first()->isError());
     // 2nd scenario: a testing framework is present, but no configuration file was found.
     $messages = $this->runValidator($validator);
     $this->assertTrue($messages->first()->isWarning());
     // 3rd scenario: a testing framework is present, and it is configured.
     $messages = $this->runValidator($validator);
     $this->assertTrue($messages->first()->isNormal());
 }
    }
    public function retrieveByUsernameOrEmailAddress($username)
    {
        return $this->retrieveByUsername($username) || self::$user->emailAddress == $username ? self::$user : null;
    }
}
class TestValidator extends sfGuardValidatorUser
{
    protected function getTable()
    {
        return new MockTable();
    }
}
// ->clean()
$t->diag('->clean()');
$validator = new TestValidator();
$activeUser = new MockUser();
$activeUser->active = true;
$inactiveUser = new MockUser();
$inactiveUser->active = false;
MockTable::$user = $activeUser;
try {
    $values = $validator->clean(array('username' => 'mock', 'password' => 'correct'));
    $t->pass('->clean() does not throw an error if an active user is found');
    $t->isa_ok($values['user'], 'MockUser', '->clean() adds the user object to the cleaned values');
} catch (sfValidatorErrorSchema $error) {
    $t->fail('->clean() does not throw an error if an active user is found');
    $t->skip();
}
try {
    $values = $validator->clean(array('username' => '*****@*****.**', 'password' => 'correct'));
 public function testAfterEvent()
 {
     $response = m::mock('StdClass');
     $response->shouldReceive('passes', 'setAttributeNames')->once()->andReturn(true);
     $validator = m::mock('Illuminate\\Validation\\Validator');
     $validator->shouldReceive('make')->once()->andReturn($response);
     $validator->shouldReceive('extend')->zeroOrMoreTimes();
     $testValidator = new TestValidator($this->inputs, $validator);
     $testValidator->passes();
     $rules = $testValidator->getRules();
     $this->assertNotNull($rules['event']);
     $this->assertEquals('after', $rules['event']);
 }