Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
crazyfactory/validation / tests / unit / EoriValidatorTest.php
Size: Mime:
<?php

namespace CrazyFactory\Validation\Tests\unit;

use Codeception\Util\Stub;
use CrazyFactory\Validation\Eori\EoriValidator;

class EoriValidatorTest extends \Codeception\Test\Unit
{
    public function testValidate()
    {
        $response = new \stdClass();
        $response->return = new \stdClass();
        $response->return->result = new \stdClass();

        // Success
        $response->return->result->status = 0;
        $soapClient = Stub::makeEmpty(\SoapClient::class, [
            '__soapCall' => $response
        ]);
        $validator = new EoriValidator($soapClient);
        $result = $validator->validate('IE7761569R');
        $this->assertTrue($result);


        // Failed
        $response->return->result->status = 1;
        $soapClient = Stub::makeEmpty(\SoapClient::class, [
            '__soapCall' => $response
        ]);
        $validator = new EoriValidator($soapClient);
        $result = $validator->validate('IE7761569R');
        $this->assertFalse($result);
    }

    public function testValidateWhenWsdlCannotBeLoaded()
    {
        $response = new \stdClass();
        $response->return = new \stdClass();
        $response->return->result = new \stdClass();
        // Failed
        $response->return->result->status = 1;
        $soapClient = Stub::makeEmpty(\SoapClient::class, [
            '__soapCall' => function () {
                throw new \SoapFault('WSDL', 'wsdl error');
            }
        ]);
        $validator = new EoriValidator($soapClient);
        $result = $validator->validate('IE7761569R');
        $this->assertTrue($result);
    }

    public function testValidateWithServerError()
    {
        $response = new \stdClass();
        $response->return = new \stdClass();
        $response->return->result = new \stdClass();
        // Failed
        $response->return->result->status = 1;
        $soapClient = Stub::makeEmpty(\SoapClient::class, [
            '__soapCall' => function () {
                throw new \SoapFault('soap:Server', 'remote server error');
            }
        ]);
        $validator = new EoriValidator($soapClient);
        $result = $validator->validate('IE7761569R');
        $this->assertFalse($result);
    }

    public function testValidateWhenFaultCodeNotMatchAnySetting()
    {
        $response = new \stdClass();
        $response->return = new \stdClass();
        $response->return->result = new \stdClass();
        // Failed
        $response->return->result->status = 1;
        $soapClient = Stub::makeEmpty(\SoapClient::class, [
            '__soapCall' => function () {
                throw new \SoapFault('Client', 'remote server error');
            }
        ]);
        $validator = new EoriValidator($soapClient);
        $result = $validator->validate('IE7761569R');
        $this->assertFalse($result);
    }

    public function testValidateWhenLocalRegexNotMatch()
    {
        $validator = new EoriValidator();
        $result = $validator->validate('x');
        $this->assertFalse($result);
    }
}