-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
95 additions
and
3 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
namespace Nectary\Tests; | ||
|
||
use Nectary\Request; | ||
|
||
/** | ||
* @group request | ||
*/ | ||
class Request_Test extends \PHPUnit_Framework_TestCase { | ||
function test_error_callback_is_not_called_when_validation_passes() { | ||
$request = $this->getMockForAbstractClass( Request::class ); | ||
$request->expects( $this->once() ) | ||
->method( 'validation_rules' ) | ||
->will( $this->returnValue( [ 'test' => true ] ) ); | ||
|
||
|
||
$mock_function = $this->getMockBuilder( 'Object' ) | ||
->setMethods( ['no_call_function'] ) | ||
->getMock(); | ||
|
||
$mock_function->expects( $this->exactly( 0 ) ) | ||
->method( 'no_call_function' ) | ||
->will($this->returnValue( false ) ); | ||
|
||
$request->validate( array( $mock_function, 'no_call_function' ) ); | ||
} | ||
|
||
function test_error_callback_is_called_with_failures() { | ||
$request = $this->getMockForAbstractClass( Request::class ); | ||
$request->expects( $this->once() ) | ||
->method( 'validation_rules' ) | ||
->will( $this->returnValue( [ 'test' => 'my error message' ] ) ); | ||
|
||
|
||
$mock_function = $this->getMockBuilder( 'Object' ) | ||
->setMethods( ['error_function'] ) | ||
->getMock(); | ||
|
||
$mock_function->expects( $this->exactly( 1 ) ) | ||
->method( 'error_function' ) | ||
->will($this->returnValue( 'my failure object' ) ); | ||
|
||
$result = $request->validate( array( $mock_function, 'error_function' ) ); | ||
|
||
$this->assertCount( 1, $result ); | ||
$this->assertEquals( 'my failure object', $result[0] ); | ||
} | ||
|
||
function test_error_callback_is_called_with_many_failures() { | ||
$request = $this->getMockForAbstractClass( Request::class ); | ||
$request->expects( $this->once() ) | ||
->method( 'validation_rules' ) | ||
->will( $this->returnValue( | ||
array( | ||
'test' => 'my error message', | ||
'test2' => 'another error message', | ||
) | ||
) | ||
); | ||
|
||
|
||
$mock_function = $this->getMockBuilder( 'Object' ) | ||
->setMethods( ['error_function'] ) | ||
->getMock(); | ||
|
||
$mock_function->expects( $this->exactly( 2 ) ) | ||
->method( 'error_function' ) | ||
->will( | ||
$this->onConsecutiveCalls( | ||
'my failure object', | ||
'another failure object' | ||
) | ||
); | ||
|
||
$result = $request->validate( array( $mock_function, 'error_function' ) ); | ||
|
||
$this->assertCount( 2, $result ); | ||
$this->assertEquals( 'my failure object', $result[0] ); | ||
$this->assertEquals( 'another failure object', $result[1] ); | ||
} | ||
} |