Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
himiklab committed May 12, 2019
1 parent 48e3ef8 commit 8e73cee
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions tests/ReCaptchaValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testValidateValueSuccess()
$this->validatorClass
->expects($this->once())
->method('getResponse')
->willReturn(['success' => true]);
->willReturn(['success' => true, 'hostname' => 'localhost']);

$this->assertNull($this->validatorMethod->invoke($this->validatorClass, 'test'));
$this->assertNull($this->validatorMethod->invoke($this->validatorClass, 'test'));
Expand All @@ -30,7 +30,7 @@ public function testValidateValueFailure()
$this->validatorClass
->expects($this->once())
->method('getResponse')
->willReturn(['success' => false]);
->willReturn(['success' => false, 'hostname' => 'localhost']);

$this->assertNotNull($this->validatorMethod->invoke($this->validatorClass, 'test'));
$this->assertNotNull($this->validatorMethod->invoke($this->validatorClass, 'test'));
Expand All @@ -47,12 +47,43 @@ public function testValidateValueException()
$this->validatorMethod->invoke($this->validatorClass, 'test');
}

public function testHostNameValidateFailure()
{
$this->validatorClass
->expects($this->once())
->method('getResponse')
->willReturn(['success' => false, 'hostname' => 'localhost']);
$this->validatorClass
->expects($this->once())
->method('getHostName')
->willReturn('test');
$this->validatorClass->checkHostName = true;

$this->setExpectedException('yii\base\Exception');
$this->validatorMethod->invoke($this->validatorClass, 'test');
}

public function testHostNameValidateSuccess()
{
$this->validatorClass
->expects($this->once())
->method('getResponse')
->willReturn(['success' => false, 'hostname' => 'localhost']);
$this->validatorClass
->expects($this->once())
->method('getHostName')
->willReturn('localhost');
$this->validatorClass->checkHostName = true;

$this->validatorMethod->invoke($this->validatorClass, 'test');
}

public function setUp()
{
parent::setUp();
$this->validatorClass = $this->getMockBuilder(ReCaptchaValidator::className())
->disableOriginalConstructor()
->setMethods(['getResponse'])
->setMethods(['getResponse', 'getHostName'])
->getMock();

$this->validatorMethod = (new ReflectionClass(ReCaptchaValidator::className()))->getMethod('validateValue');
Expand Down

0 comments on commit 8e73cee

Please sign in to comment.