diff --git a/tests/Peru/Sunat/Async/HttpClientStub.php b/tests/Peru/Sunat/Async/HttpClientStub.php new file mode 100644 index 0000000..dd033b6 --- /dev/null +++ b/tests/Peru/Sunat/Async/HttpClientStub.php @@ -0,0 +1,39 @@ +client = $client; + } + + /** + * Make GET Request. + * + * @param string $url + * @param array $headers + * + * @return PromiseInterface + */ + public function getAsync(string $url, array $headers = []): PromiseInterface + { + return $this->client->getAsync(ClientStubDecorator::getNewUrl($url), $headers); + } +} \ No newline at end of file diff --git a/tests/Peru/Sunat/Async/RucTest.php b/tests/Peru/Sunat/Async/RucTest.php index 452be80..c8351fc 100644 --- a/tests/Peru/Sunat/Async/RucTest.php +++ b/tests/Peru/Sunat/Async/RucTest.php @@ -6,10 +6,7 @@ use function Clue\React\Block\await; use Peru\Http\Async\HttpClient; -use Peru\Sunat\Async\Ruc; -use Peru\Sunat\Company; -use Peru\Sunat\HtmlParser; -use Peru\Sunat\RucParser; +use Peru\Sunat\{Async\Ruc, Company, HtmlParser, RucParser}; use PHPUnit\Framework\TestCase; use React\EventLoop\Factory; @@ -21,7 +18,7 @@ class RucTest extends TestCase public function testGetRuc() { $loop = Factory::create(); - $cs = new Ruc(new HttpClient($loop), new RucParser(new HtmlParser())); + $cs = new Ruc(new HttpClientStub(new HttpClient($loop)), new RucParser(new HtmlParser())); $promise = $cs->get('10401510465'); /**@var $company Company */ $company = await($promise, $loop); diff --git a/tests/Peru/Sunat/ClientStubDecorator.php b/tests/Peru/Sunat/ClientStubDecorator.php index 115ab39..6df2042 100644 --- a/tests/Peru/Sunat/ClientStubDecorator.php +++ b/tests/Peru/Sunat/ClientStubDecorator.php @@ -38,7 +38,7 @@ public function __construct(ClientInterface $client) */ public function get(string $url, array $headers = []) { - return $this->client->get($this->getNewUrl($url), $headers); + return $this->client->get(self::getNewUrl($url), $headers); } /** @@ -52,10 +52,10 @@ public function get(string $url, array $headers = []) */ public function post(string $url, $data, array $headers = []) { - return $this->client->post($this->getNewUrl($url), $data, $headers); + return $this->client->post(self::getNewUrl($url), $data, $headers); } - private function getNewUrl($url) + public static function getNewUrl($url) { $urlBase = getenv('MOCK_URL'); $u = parse_url($url);