mirror of
https://github.com/Respect/Validation.git
synced 2026-03-16 07:15:45 +01:00
85 lines
2.4 KiB
PHP
85 lines
2.4 KiB
PHP
<?php
|
|
namespace Respect\Validation\Rules\Locale;
|
|
|
|
use malkusch\bav\BAV;
|
|
|
|
/**
|
|
* @covers Respect\Validation\Rules\Locale\GermanBankAccount
|
|
* @covers Respect\Validation\Exceptions\Locale\GermanBankAccountException
|
|
*/
|
|
class GermanBankAccountTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
public function testShouldAcceptBankOnConstructor()
|
|
{
|
|
$bank = '10000000';
|
|
$rule = new GermanBankAccount($bank);
|
|
|
|
$this->assertSame($bank, $rule->bank);
|
|
}
|
|
|
|
public function testShouldAcceptBAVInstanceOnConstructor()
|
|
{
|
|
$bank = '10000000';
|
|
$bav = new BAV();
|
|
$rule = new GermanBankAccount($bank, $bav);
|
|
|
|
$this->assertSame($bav, $rule->bav);
|
|
}
|
|
|
|
public function testShouldHaveAnInstanceOfBAVByDefault()
|
|
{
|
|
$bank = '10000000';
|
|
$rule = new GermanBankAccount($bank);
|
|
|
|
$this->assertInstanceOf('malkusch\bav\BAV', $rule->bav);
|
|
}
|
|
|
|
public function testShouldUseBAVInstanceToValidate()
|
|
{
|
|
$bank = '10000000';
|
|
$input = '67067';
|
|
$bav = $this->getMock('malkusch\bav\BAV');
|
|
$rule = new GermanBankAccount($bank, $bav);
|
|
|
|
$bav->expects($this->once())
|
|
->method('isValidBankAccount')
|
|
->with($bank, $input)
|
|
->will($this->returnValue(true));
|
|
|
|
$rule->validate($input);
|
|
}
|
|
|
|
public function testShouldReturnBAVInstanceResulteWhenValidating()
|
|
{
|
|
$bank = '10000000';
|
|
$input = '67067';
|
|
$bav = $this->getMock('malkusch\bav\BAV');
|
|
$rule = new GermanBankAccount($bank, $bav);
|
|
|
|
$bav->expects($this->any())
|
|
->method('isValidBankAccount')
|
|
->with($bank, $input)
|
|
->will($this->returnValue(true));
|
|
|
|
$this->assertTrue($rule->validate($input));
|
|
}
|
|
|
|
/**
|
|
* @expectedException Respect\Validation\Exceptions\Locale\GermanBankAccountException
|
|
* @expectedExceptionMessage "67067" must be a german bank account
|
|
*/
|
|
public function testShouldThowsTheRightExceptionWhenChecking()
|
|
{
|
|
$bank = '10000000';
|
|
$input = '67067';
|
|
$bav = $this->getMock('malkusch\bav\BAV');
|
|
$rule = new GermanBankAccount($bank, $bav);
|
|
|
|
$bav->expects($this->any())
|
|
->method('isValidBankAccount')
|
|
->with($bank, $input)
|
|
->will($this->returnValue(false));
|
|
|
|
$rule->check($input);
|
|
}
|
|
}
|