Fix tests

This commit is contained in:
ErickSkrauch
2019-12-15 00:49:54 +03:00
parent e8b71d33d0
commit 04e399c726
6 changed files with 88 additions and 18 deletions

View File

@@ -1,10 +1,6 @@
<?php
Codeception\PHPUnit\Init::init();
defined('YII_DEBUG') || define('YII_DEBUG', true);
defined('YII_ENV') || define('YII_ENV', 'test');
defined('YII_APP_BASE_PATH') || define('YII_APP_BASE_PATH', __DIR__ . '/../../');
require_once YII_APP_BASE_PATH . '/vendor/autoload.php';

View File

@@ -8,8 +8,6 @@ use api\tests\unit\TestCase;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Psr7\Response;
use phpmock\mockery\PHPMockery;
use ReflectionClass;
class ValidatorTest extends TestCase {
@@ -44,7 +42,7 @@ class ValidatorTest extends TestCase {
],
])))
);
PHPMockery::mock($this->getClassNamespace(Validator::class), 'sleep')->once();
$this->getFunctionMock(Validator::class, 'sleep')->expects($this->once());
$validator = new Validator($mockClient);
$this->assertTrue($validator->validate('12341234', $error));
@@ -54,7 +52,7 @@ class ValidatorTest extends TestCase {
public function testValidateWithHugeNetworkTroubles() {
$mockClient = $this->createMock(ClientInterface::class);
$mockClient->expects($this->exactly(3))->method('request')->willThrowException($this->createMock(ConnectException::class));
PHPMockery::mock($this->getClassNamespace(Validator::class), 'sleep')->times(2);
$this->getFunctionMock(Validator::class, 'sleep')->expects($this->exactly(2));
$validator = new Validator($mockClient);
$this->expectException(ConnectException::class);
@@ -71,8 +69,4 @@ class ValidatorTest extends TestCase {
$this->assertNull($error);
}
private function getClassNamespace(string $className): string {
return (new ReflectionClass($className))->getNamespaceName();
}
}