Browse Source

compatibility with PHPUnit 6.x added

tags/2.0.12
Klimov Paul 8 years ago
parent
commit
dee88787fc
  1. 18
      tests/compatibility.php
  2. 4
      tests/framework/BaseYiiTest.php
  3. 2
      tests/framework/base/BehaviorTest.php
  4. 22
      tests/framework/base/ComponentTest.php
  5. 2
      tests/framework/base/DynamicModelTest.php
  6. 4
      tests/framework/base/ModelTest.php
  7. 16
      tests/framework/base/ObjectTest.php
  8. 9
      tests/framework/base/SecurityTest.php
  9. 3
      tests/framework/console/ControllerTest.php
  10. 3
      tests/framework/console/RequestTest.php
  11. 8
      tests/framework/console/controllers/AssetControllerTest.php
  12. 7
      tests/framework/console/controllers/BaseMessageControllerTest.php
  13. 5
      tests/framework/console/controllers/HelpControllerTest.php
  14. 5
      tests/framework/console/controllers/MigrateControllerTestTrait.php
  15. 2
      tests/framework/db/ActiveRecordTest.php
  16. 6
      tests/framework/db/CommandTest.php
  17. 2
      tests/framework/db/ConnectionTest.php
  18. 15
      tests/framework/di/InstanceTest.php
  19. 4
      tests/framework/filters/AccessRuleTest.php
  20. 3
      tests/framework/filters/HostControlTest.php
  21. 6
      tests/framework/filters/auth/AuthMethodTest.php
  22. 4
      tests/framework/helpers/FileHelperTest.php
  23. 4
      tests/framework/helpers/HtmlTest.php
  24. 2
      tests/framework/helpers/JsonTest.php
  25. 4
      tests/framework/helpers/UrlTest.php
  26. 4
      tests/framework/i18n/FallbackMessageFormatterTest.php
  27. 2
      tests/framework/i18n/FormatterDateTest.php
  28. 2
      tests/framework/i18n/FormatterTest.php
  29. 36
      tests/framework/log/EmailTargetTest.php
  30. 38
      tests/framework/log/LoggerTest.php
  31. 9
      tests/framework/log/SyslogTargetTest.php
  32. 6
      tests/framework/log/TargetTest.php
  33. 4
      tests/framework/mail/BaseMailerTest.php
  34. 2
      tests/framework/validators/CompareValidatorTest.php
  35. 2
      tests/framework/validators/FilterValidatorTest.php
  36. 4
      tests/framework/validators/IpValidatorTest.php
  37. 3
      tests/framework/validators/RangeValidatorTest.php
  38. 2
      tests/framework/validators/RegularExpressionValidatorTest.php
  39. 2
      tests/framework/validators/UniqueValidatorTest.php
  40. 6
      tests/framework/validators/ValidatorTest.php
  41. 4
      tests/framework/web/AssetBundleTest.php
  42. 2
      tests/framework/web/CacheSessionTest.php
  43. 2
      tests/framework/web/ResponseTest.php
  44. 4
      tests/framework/web/UserTest.php
  45. 2
      tests/framework/widgets/BreadcrumbsTest.php

18
tests/compatibility.php

@ -11,6 +11,22 @@ namespace PHPUnit\Framework\Constraint {
namespace PHPUnit\Framework {
if (!class_exists('PHPUnit\Framework\TestCase') && class_exists('PHPUnit_Framework_TestCase')) {
abstract class TestCase extends \PHPUnit_Framework_TestCase {}
abstract class TestCase extends \PHPUnit_Framework_TestCase {
/**
* @param string $exception
*/
public function expectException($exception)
{
$this->setExpectedException($exception);
}
/**
* @param string $message
*/
public function expectExceptionMessage($message)
{
$this->setExpectedException($this->getExpectedException(), $message);
}
}
}
}

4
tests/framework/BaseYiiTest.php

@ -113,7 +113,9 @@ class BaseYiiTest extends TestCase
*/
public function testLog()
{
$logger = $this->getMock('yii\\log\\Logger', ['log']);
$logger = $this->getMockBuilder('yii\\log\\Logger')
->setMethods(['log'])
->getMock();
BaseYii::setLogger($logger);
$logger->expects($this->exactly(6))

2
tests/framework/base/BehaviorTest.php

@ -141,7 +141,7 @@ class BehaviorTest extends TestCase
{
$bar = new BarClass();
$behavior = new BarBehavior();
$this->setExpectedException('yii\base\UnknownMethodException');
$this->expectException('yii\base\UnknownMethodException');
$this->assertFalse($bar->hasMethod('nomagicBehaviorMethod'));
$bar->attachBehavior('bar', $behavior);

22
tests/framework/base/ComponentTest.php

@ -96,7 +96,7 @@ class ComponentTest extends TestCase
public function testGetProperty()
{
$this->assertSame('default', $this->component->Text);
$this->setExpectedException('yii\base\UnknownPropertyException');
$this->expectException('yii\base\UnknownPropertyException');
$value2 = $this->component->Caption;
}
@ -105,7 +105,7 @@ class ComponentTest extends TestCase
$value = 'new value';
$this->component->Text = $value;
$this->assertEquals($value, $this->component->Text);
$this->setExpectedException('yii\base\UnknownPropertyException');
$this->expectException('yii\base\UnknownPropertyException');
$this->component->NewMember = $value;
}
@ -130,7 +130,7 @@ class ComponentTest extends TestCase
public function testCallUnknownMethod()
{
$this->setExpectedException('yii\base\UnknownMethodException');
$this->expectException('yii\base\UnknownMethodException');
$this->component->unknownMethod();
}
@ -150,7 +150,7 @@ class ComponentTest extends TestCase
public function testUnsetReadonly()
{
$this->setExpectedException('yii\base\InvalidCallException');
$this->expectException('yii\base\InvalidCallException');
unset($this->component->object);
}
@ -244,7 +244,7 @@ class ComponentTest extends TestCase
$this->assertSame($behavior, $component->detachBehavior('a'));
$this->assertFalse($component->hasProperty('p'));
$this->setExpectedException('yii\base\UnknownMethodException');
$this->expectException('yii\base\UnknownMethodException');
$component->test();
$p = 'as b';
@ -305,10 +305,8 @@ class ComponentTest extends TestCase
public function testSetReadOnlyProperty()
{
$this->setExpectedException(
'\yii\base\InvalidCallException',
'Setting read-only property: yiiunit\framework\base\NewComponent::object'
);
$this->expectException('\yii\base\InvalidCallException');
$this->expectExceptionMessage('Setting read-only property: yiiunit\framework\base\NewComponent::object');
$this->component->object = 'z';
}
@ -336,10 +334,8 @@ class ComponentTest extends TestCase
public function testWriteOnlyProperty()
{
$this->setExpectedException(
'\yii\base\InvalidCallException',
'Getting write-only property: yiiunit\framework\base\NewComponent::writeOnly'
);
$this->expectException('\yii\base\InvalidCallException');
$this->expectExceptionMessage('Getting write-only property: yiiunit\framework\base\NewComponent::writeOnly');
$this->component->writeOnly;
}

2
tests/framework/base/DynamicModelTest.php

@ -72,7 +72,7 @@ class DynamicModelTest extends TestCase
$model = new DynamicModel(compact('name', 'email'));
$this->assertEquals($email, $model->email);
$this->assertEquals($name, $model->name);
$this->setExpectedException('yii\base\UnknownPropertyException');
$this->expectException('yii\base\UnknownPropertyException');
$age = $model->age;
}

4
tests/framework/base/ModelTest.php

@ -427,8 +427,8 @@ class ModelTest extends TestCase
public function testCreateValidators()
{
$this->setExpectedException('yii\base\InvalidConfigException',
'Invalid validation rule: a rule must specify both attribute names and validator type.');
$this->expectException('yii\base\InvalidConfigException');
$this->expectExceptionMessage('Invalid validation rule: a rule must specify both attribute names and validator type.');
$invalid = new InvalidRulesModel();
$invalid->createValidators();

16
tests/framework/base/ObjectTest.php

@ -61,7 +61,7 @@ class ObjectTest extends TestCase
public function testGetProperty()
{
$this->assertSame('default', $this->object->Text);
$this->setExpectedException('yii\base\UnknownPropertyException');
$this->expectException('yii\base\UnknownPropertyException');
$value2 = $this->object->Caption;
}
@ -70,13 +70,13 @@ class ObjectTest extends TestCase
$value = 'new value';
$this->object->Text = $value;
$this->assertEquals($value, $this->object->Text);
$this->setExpectedException('yii\base\UnknownPropertyException');
$this->expectException('yii\base\UnknownPropertyException');
$this->object->NewMember = $value;
}
public function testSetReadOnlyProperty()
{
$this->setExpectedException('yii\base\InvalidCallException');
$this->expectException('yii\base\InvalidCallException');
$this->object->object = 'test';
}
@ -106,13 +106,13 @@ class ObjectTest extends TestCase
public function testUnsetReadOnlyProperty()
{
$this->setExpectedException('yii\base\InvalidCallException');
$this->expectException('yii\base\InvalidCallException');
unset($this->object->object);
}
public function testCallUnknownMethod()
{
$this->setExpectedException('yii\base\UnknownMethodException');
$this->expectException('yii\base\UnknownMethodException');
$this->object->unknownMethod();
}
@ -148,10 +148,8 @@ class ObjectTest extends TestCase
public function testReadingWriteOnlyProperty()
{
$this->setExpectedException(
'yii\base\InvalidCallException',
'Getting write-only property: yiiunit\framework\base\NewObject::writeOnly'
);
$this->expectException('yii\base\InvalidCallException');
$this->expectExceptionMessage('Getting write-only property: yiiunit\framework\base\NewObject::writeOnly');
$this->object->writeOnly;
}
}

9
tests/framework/base/SecurityTest.php

@ -887,7 +887,8 @@ TEXT;
{
static::$functions = ['random_bytes' => false, 'openssl_random_pseudo_bytes' => false, 'mcrypt_create_iv' => false ];
static::$fopen = false;
$this->setExpectedException('yii\base\Exception', 'Unable to generate a random key');
$this->expectException('yii\base\Exception');
$this->expectExceptionMessage('Unable to generate a random key');
$this->security->generateRandomKey(42);
}
@ -899,7 +900,8 @@ TEXT;
{
static::$functions = ['random_bytes' => false, 'openssl_random_pseudo_bytes' => false, 'mcrypt_create_iv' => false ];
static::$fread = false;
$this->setExpectedException('yii\base\Exception', 'Unable to generate a random key');
$this->expectException('yii\base\Exception');
$this->expectExceptionMessage('Unable to generate a random key');
$this->security->generateRandomKey(42);
}
@ -933,7 +935,8 @@ TEXT;
}
// there is no /dev/urandom on windows so we expect this to fail
if (DIRECTORY_SEPARATOR === '\\' && $functions['random_bytes'] === false && $functions['openssl_random_pseudo_bytes'] === false && $functions['mcrypt_create_iv'] === false ) {
$this->setExpectedException('yii\base\Exception', 'Unable to generate a random key');
$this->expectException('yii\base\Exception');
$this->expectExceptionMessage('Unable to generate a random key');
}
// Function mcrypt_create_iv() is deprecated since PHP 7.1
if (version_compare(PHP_VERSION, '7.1.0alpha', '>=') && $functions['random_bytes'] === false && $functions['mcrypt_create_iv'] === true) {

3
tests/framework/console/ControllerTest.php

@ -61,7 +61,8 @@ class ControllerTest extends TestCase
$params = ['avaliable'];
$message = Yii::t('yii', 'Missing required arguments: {params}', ['params' => implode(', ', ['missing'])]);
$this->setExpectedException('yii\console\Exception', $message);
$this->expectException('yii\console\Exception');
$this->expectExceptionMessage($message);
$result = $controller->runAction('aksi3', $params);
}

3
tests/framework/console/RequestTest.php

@ -140,7 +140,8 @@ class RequestTest extends TestCase
public function testResolve($params, $expected, $expectedException = null)
{
if (isset($expectedException)) {
$this->setExpectedException($expectedException[0], $expectedException[1]);
$this->expectException($expectedException[0]);
$this->expectExceptionMessage($expectedException[1]);
}
$request = new Request();

8
tests/framework/console/controllers/AssetControllerTest.php

@ -67,7 +67,10 @@ class AssetControllerTest extends TestCase
*/
protected function createAssetController()
{
$module = $this->getMock('yii\\base\\Module', ['fake'], ['console']);
$module = $this->getMockBuilder('yii\\base\\Module')
->setMethods(['fake'])
->setConstructorArgs(['console'])
->getMock();
$assetController = new AssetControllerMock('asset', $module);
$assetController->interactive = false;
$assetController->jsCompressor = 'cp {from} {to}';
@ -436,7 +439,8 @@ EOL;
// Assert :
$expectedExceptionMessage = ": {$namespace}\AssetA -> {$namespace}\AssetB -> {$namespace}\AssetC -> {$namespace}\AssetA";
$this->setExpectedException('yii\console\Exception', $expectedExceptionMessage);
$this->expectException('yii\console\Exception');
$this->expectExceptionMessage($expectedExceptionMessage);
// When :
$this->runAssetControllerAction('compress', [$configFile, $bundleFile]);

7
tests/framework/console/controllers/BaseMessageControllerTest.php

@ -55,7 +55,10 @@ abstract class BaseMessageControllerTest extends TestCase
*/
protected function createMessageController()
{
$module = $this->getMock('yii\\base\\Module', ['fake'], ['console']);
$module = $this->getMockBuilder('yii\\base\\Module')
->setMethods(['fake'])
->setConstructorArgs(['console'])
->getMock();
$messageController = new MessageControllerMock('message', $module);
$messageController->interactive = false;
@ -146,7 +149,7 @@ abstract class BaseMessageControllerTest extends TestCase
public function testConfigFileNotExist()
{
$this->setExpectedException('yii\\console\\Exception');
$this->expectException('yii\\console\\Exception');
$this->runMessageControllerAction('extract', ['not_existing_file.php']);
}

5
tests/framework/console/controllers/HelpControllerTest.php

@ -27,7 +27,10 @@ class HelpControllerTest extends TestCase
*/
protected function createController()
{
$module = $this->getMock('yii\\base\\Module', ['fake'], ['console']);
$module = $this->getMockBuilder('yii\\base\\Module')
->setMethods(['fake'])
->setConstructorArgs(['console'])
->getMock();
return new BufferedHelpController('help', $module);
}

5
tests/framework/console/controllers/MigrateControllerTestTrait.php

@ -60,7 +60,10 @@ trait MigrateControllerTestTrait
*/
protected function createMigrateController(array $config = [])
{
$module = $this->getMock('yii\\base\\Module', ['fake'], ['console']);
$module = $this->getMockBuilder('yii\\base\\Module')
->setMethods(['fake'])
->setConstructorArgs(['console'])
->getMock();
$class = $this->migrateControllerClass;
$migrateController = new $class('migrate', $module);
$migrateController->interactive = false;

2
tests/framework/db/ActiveRecordTest.php

@ -1172,7 +1172,7 @@ abstract class ActiveRecordTest extends DatabaseTestCase
$record = Document::findOne(1);
$record->content = 'Rewrite attempt content';
$record->version = 0;
$this->setExpectedException('yii\db\StaleObjectException');
$this->expectException('yii\db\StaleObjectException');
$record->save(false);
}

6
tests/framework/db/CommandTest.php

@ -71,7 +71,7 @@ abstract class CommandTest extends DatabaseTestCase
$this->assertEquals(1, $command->queryScalar());
$command = $db->createCommand('bad SQL');
$this->setExpectedException('\yii\db\Exception');
$this->expectException('\yii\db\Exception');
$command->execute();
}
@ -132,7 +132,7 @@ abstract class CommandTest extends DatabaseTestCase
$this->assertFalse($command->queryScalar());
$command = $db->createCommand('bad SQL');
$this->setExpectedException('\yii\db\Exception');
$this->expectException('\yii\db\Exception');
$command->query();
}
@ -649,7 +649,7 @@ SQL;
public function testIntegrityViolation()
{
$this->setExpectedException('\yii\db\IntegrityException');
$this->expectException('\yii\db\IntegrityException');
$db = $this->getConnection();

2
tests/framework/db/ConnectionTest.php

@ -35,7 +35,7 @@ abstract class ConnectionTest extends DatabaseTestCase
$connection = new Connection;
$connection->dsn = 'unknown::memory:';
$this->setExpectedException('yii\db\Exception');
$this->expectException('yii\db\Exception');
$connection->open();
}

15
tests/framework/di/InstanceTest.php

@ -100,7 +100,8 @@ class InstanceTest extends TestCase
'dsn' => 'test',
]);
$this->setExpectedException('yii\base\InvalidConfigException', '"db" refers to a yii\db\Connection component. yii\base\Widget is expected.');
$this->expectException('yii\base\InvalidConfigException');
$this->expectExceptionMessage('"db" refers to a yii\db\Connection component. yii\base\Widget is expected.');
Instance::ensure('db', 'yii\base\Widget', $container);
Instance::ensure(['class' => 'yii\db\Connection', 'dsn' => 'test'], 'yii\base\Widget', $container);
@ -108,13 +109,15 @@ class InstanceTest extends TestCase
public function testExceptionInvalidDataType()
{
$this->setExpectedException('yii\base\InvalidConfigException', 'Invalid data type: yii\db\Connection. yii\base\Widget is expected.');
$this->expectException('yii\base\InvalidConfigException');
$this->expectExceptionMessage('Invalid data type: yii\db\Connection. yii\base\Widget is expected.');
Instance::ensure(new Connection, 'yii\base\Widget');
}
public function testExceptionComponentIsNotSpecified()
{
$this->setExpectedException('yii\base\InvalidConfigException', 'The required component is not specified.');
$this->expectException('yii\base\InvalidConfigException');
$this->expectExceptionMessage('The required component is not specified.');
Instance::ensure('');
}
@ -175,10 +178,8 @@ PHP
public function testRestoreAfterVarExportRequiresId()
{
$this->setExpectedException(
'yii\base\InvalidConfigException',
'Failed to instantiate class "Instance". Required parameter "id" is missing'
);
$this->expectException('yii\base\InvalidConfigException');
$this->expectExceptionMessage('Failed to instantiate class "Instance". Required parameter "id" is missing');
Instance::__set_state([]);
}

4
tests/framework/filters/AccessRuleTest.php

@ -34,7 +34,9 @@ class AccessRuleTest extends \yiiunit\TestCase
protected function mockRequest($method = 'GET')
{
/** @var Request $request */
$request = $this->getMockBuilder('\yii\web\Request')->setMethods(['getMethod'])->getMock();
$request = $this->getMockBuilder('\yii\web\Request')
->setMethods(['getMethod'])
->getMock();
$request->method('getMethod')->willReturn($method);
return $request;
}

3
tests/framework/filters/HostControlTest.php

@ -148,7 +148,8 @@ class HostControlTest extends TestCase
public function testErrorHandlerWithDefaultHost()
{
$this->setExpectedException('yii\web\NotFoundHttpException', 'Page not found.');
$this->expectException('yii\web\NotFoundHttpException');
$this->expectExceptionMessage('Page not found.');
$filter = new HostControl();
$filter->allowedHosts = ['example.com'];

6
tests/framework/filters/auth/AuthMethodTest.php

@ -31,7 +31,9 @@ class AuthMethodTest extends TestCase
*/
protected function createFilter($authenticateCallback)
{
$filter = $this->getMock(AuthMethod::className(), ['authenticate']);
$filter = $this->getMockBuilder(AuthMethod::className())
->setMethods(['authenticate'])
->getMock();
$filter->method('authenticate')->willReturnCallback($authenticateCallback);
return $filter;
@ -58,7 +60,7 @@ class AuthMethodTest extends TestCase
$this->assertTrue($filter->beforeAction($action));
$filter = $this->createFilter(function () {return null;});
$this->setExpectedException('yii\web\UnauthorizedHttpException');
$this->expectException('yii\web\UnauthorizedHttpException');
$this->assertTrue($filter->beforeAction($action));
}

4
tests/framework/helpers/FileHelperTest.php

@ -293,7 +293,7 @@ class FileHelperTest extends TestCase
$dirName => [],
]);
$this->setExpectedException('yii\base\InvalidParamException');
$this->expectException('yii\base\InvalidParamException');
$dirName = $this->testFilePath . DIRECTORY_SEPARATOR . 'test_dir';
FileHelper::copyDirectory($dirName, $dirName);
@ -309,7 +309,7 @@ class FileHelperTest extends TestCase
'backup' => ['data' => []]
]);
$this->setExpectedException('yii\base\InvalidParamException');
$this->expectException('yii\base\InvalidParamException');
FileHelper::copyDirectory(
$this->testFilePath . DIRECTORY_SEPARATOR . 'backup',

4
tests/framework/helpers/HtmlTest.php

@ -1309,7 +1309,7 @@ EOD;
public function testAttributeNameValidation($name, $expected)
{
if (!isset($expected)) {
$this->setExpectedException('yii\base\InvalidParamException');
$this->expectException('yii\base\InvalidParamException');
Html::getAttributeName($name);
} else {
$this->assertEquals($expected, Html::getAttributeName($name));
@ -1323,7 +1323,7 @@ EOD;
*/
public function testAttributeNameException($name)
{
$this->setExpectedException('yii\base\InvalidParamException');
$this->expectException('yii\base\InvalidParamException');
Html::getAttributeName($name);
}
}

2
tests/framework/helpers/JsonTest.php

@ -147,7 +147,7 @@ class JsonTest extends TestCase
// exception
$json = '{"a":1,"b":2';
$this->setExpectedException('yii\base\InvalidParamException');
$this->expectException('yii\base\InvalidParamException');
Json::decode($json);
}

4
tests/framework/helpers/UrlTest.php

@ -108,7 +108,7 @@ class UrlTest extends TestCase
// In case there is no controller, an exception should be thrown for relative route
$this->removeMockedAction();
$this->setExpectedException('yii\base\InvalidParamException');
$this->expectException('yii\base\InvalidParamException');
Url::toRoute('site/view');
}
@ -217,7 +217,7 @@ class UrlTest extends TestCase
//In case there is no controller, throw an exception
$this->removeMockedAction();
$this->setExpectedException('yii\base\InvalidParamException');
$this->expectException('yii\base\InvalidParamException');
Url::to(['site/view']);
}

4
tests/framework/i18n/FallbackMessageFormatterTest.php

@ -219,7 +219,7 @@ _MSG_
{
$pattern = 'Number {'.self::N.', number, percent}';
$formatter = new FallbackMessageFormatter();
$this->setExpectedException('yii\base\NotSupportedException');
$this->expectException('yii\base\NotSupportedException');
$formatter->fallbackFormat($pattern, [self::N => self::N_VALUE], 'en-US');
}
@ -227,7 +227,7 @@ _MSG_
{
$pattern = 'Number {'.self::N.', number, currency}';
$formatter = new FallbackMessageFormatter();
$this->setExpectedException('yii\base\NotSupportedException');
$this->expectException('yii\base\NotSupportedException');
$formatter->fallbackFormat($pattern, [self::N => self::N_VALUE], 'en-US');
}
}

2
tests/framework/i18n/FormatterDateTest.php

@ -44,7 +44,7 @@ class FormatterDateTest extends TestCase
$this->assertSame(date('M j, Y', $value), $this->formatter->format($value, 'date'));
$this->assertSame(date('M j, Y', $value), $this->formatter->format($value, 'DATE'));
$this->assertSame(date('Y/m/d', $value), $this->formatter->format($value, ['date', 'php:Y/m/d']));
$this->setExpectedException('\yii\base\InvalidParamException');
$this->expectException('\yii\base\InvalidParamException');
$this->assertSame(date('Y-m-d', $value), $this->formatter->format($value, 'data'));
}

2
tests/framework/i18n/FormatterTest.php

@ -47,7 +47,7 @@ class FormatterTest extends TestCase
$this->assertSame(date('M j, Y', $value), $this->formatter->format($value, 'date'));
$this->assertSame(date('M j, Y', $value), $this->formatter->format($value, 'DATE'));
$this->assertSame(date('Y/m/d', $value), $this->formatter->format($value, ['date', 'php:Y/m/d']));
$this->setExpectedException('\yii\base\InvalidParamException');
$this->expectException('\yii\base\InvalidParamException');
$this->assertSame(date('Y-m-d', $value), $this->formatter->format($value, 'data'));
}

36
tests/framework/log/EmailTargetTest.php

@ -70,15 +70,18 @@ class EmailTargetTest extends TestCase
$message->expects($this->once())->method('send')->with($this->equalTo($this->mailer));
$message->expects($this->once())->method('setSubject')->with($this->equalTo('Hello world'));
$mailTarget = $this->getMock('yii\\log\\EmailTarget', ['formatMessage'], [
[
'mailer' => $this->mailer,
'message'=> [
'to' => 'developer@example.com',
'subject' => 'Hello world'
$mailTarget = $this->getMockBuilder('yii\\log\\EmailTarget')
->setMethods(['formatMessage'])
->setConstructorArgs([
[
'mailer' => $this->mailer,
'message'=> [
'to' => 'developer@example.com',
'subject' => 'Hello world'
]
]
]
]);
])
->getMock();
$mailTarget->messages = $messages;
$mailTarget->expects($this->exactly(2))->method('formatMessage')->willReturnMap(
@ -111,14 +114,17 @@ class EmailTargetTest extends TestCase
$message->expects($this->once())->method('send')->with($this->equalTo($this->mailer));
$message->expects($this->once())->method('setSubject')->with($this->equalTo('Application Log'));
$mailTarget = $this->getMock('yii\\log\\EmailTarget', ['formatMessage'], [
[
'mailer' => $this->mailer,
'message'=> [
'to' => 'developer@example.com',
$mailTarget = $this->getMockBuilder('yii\\log\\EmailTarget')
->setMethods(['formatMessage'])
->setConstructorArgs([
[
'mailer' => $this->mailer,
'message'=> [
'to' => 'developer@example.com',
]
]
]
]);
])
->getMock();
$mailTarget->messages = $messages;
$mailTarget->expects($this->exactly(2))->method('formatMessage')->willReturnMap(

38
tests/framework/log/LoggerTest.php

@ -26,7 +26,9 @@ class LoggerTest extends TestCase
protected function setUp()
{
$this->logger = new Logger();
$this->dispatcher = $this->getMock('yii\\log\\Dispatcher', ['dispatch']);
$this->dispatcher = $this->getMockBuilder('yii\\log\\Dispatcher')
->setMethods(['dispatch'])
->getMock();
}
/**
@ -80,7 +82,9 @@ class LoggerTest extends TestCase
*/
public function testLogWithFlush()
{
$logger = $this->getMock('yii\\log\\Logger', ['flush']);
$logger = $this->getMockBuilder('yii\\log\\Logger')
->setMethods(['flush'])
->getMock();
$logger->flushInterval = 1;
$logger->expects($this->exactly(1))->method('flush');
$logger->log('test1', Logger::LEVEL_INFO);
@ -91,7 +95,7 @@ class LoggerTest extends TestCase
*/
public function testFlushWithoutDispatcher()
{
$dispatcher = $this->getMock('\stdClass');
$dispatcher = $this->getMockBuilder('\stdClass')->getMock();
$dispatcher->expects($this->never())->method($this->anything());
$this->logger->messages = ['anything'];
@ -141,7 +145,9 @@ class LoggerTest extends TestCase
['duration' => 30],
];
$logger = $this->getMock('yii\\log\\Logger', ['getProfiling']);
$logger = $this->getMockBuilder('yii\\log\\Logger')
->setMethods(['getProfiling'])
->getMock();
$logger->method('getProfiling')->willReturn($timings);
$logger->expects($this->once())
->method('getProfiling')
@ -271,7 +277,9 @@ class LoggerTest extends TestCase
{
$messages = ['anyData'];
$returnValue = 'return value';
$logger = $this->getMock('yii\\log\\Logger', ['calculateTimings']);
$logger = $this->getMockBuilder('yii\\log\\Logger')
->setMethods(['calculateTimings'])
->getMock();
$logger->messages = $messages;
$logger->method('calculateTimings')->willReturn($returnValue);
@ -295,7 +303,9 @@ class LoggerTest extends TestCase
'duration' => 5,
]
];
$logger = $this->getMock('yii\\log\\Logger', ['calculateTimings']);
$logger = $this->getMockBuilder('yii\\log\\Logger')
->setMethods(['calculateTimings'])
->getMock();
$logger->messages = $messages;
$logger->method('calculateTimings')->willReturn($returnValue);
@ -332,7 +342,9 @@ class LoggerTest extends TestCase
/**
* Matched by category name
*/
$logger = $this->getMock('yii\\log\\Logger', ['calculateTimings']);
$logger = $this->getMockBuilder('yii\\log\\Logger')
->setMethods(['calculateTimings'])
->getMock();
$logger->messages = $messages;
$logger->method('calculateTimings')->willReturn($returnValue);
@ -342,7 +354,9 @@ class LoggerTest extends TestCase
/**
* Matched by prefix
*/
$logger = $this->getMock('yii\\log\\Logger', ['calculateTimings']);
$logger = $this->getMockBuilder('yii\\log\\Logger')
->setMethods(['calculateTimings'])
->getMock();
$logger->messages = $messages;
$logger->method('calculateTimings')->willReturn($returnValue);
@ -388,7 +402,9 @@ class LoggerTest extends TestCase
/**
* Exclude by category name
*/
$logger = $this->getMock('yii\\log\\Logger', ['calculateTimings']);
$logger = $this->getMockBuilder('yii\\log\\Logger')
->setMethods(['calculateTimings'])
->getMock();
$logger->messages = $messages;
$logger->method('calculateTimings')->willReturn($returnValue);
@ -398,7 +414,9 @@ class LoggerTest extends TestCase
/**
* Exclude by category prefix
*/
$logger = $this->getMock('yii\\log\\Logger', ['calculateTimings']);
$logger = $this->getMockBuilder('yii\\log\\Logger')
->setMethods(['calculateTimings'])
->getMock();
$logger->messages = $messages;
$logger->method('calculateTimings')->willReturn($returnValue);

9
tests/framework/log/SyslogTargetTest.php

@ -50,7 +50,9 @@ namespace yiiunit\framework\log {
*/
protected function setUp()
{
$this->syslogTarget = $this->getMock('yii\\log\\SyslogTarget', ['getMessagePrefix']);
$this->syslogTarget = $this->getMockBuilder('yii\\log\\SyslogTarget')
->setMethods(['getMessagePrefix'])
->getMock();
}
/**
@ -70,8 +72,9 @@ namespace yiiunit\framework\log {
['profile begin message', Logger::LEVEL_PROFILE_BEGIN],
['profile end message', Logger::LEVEL_PROFILE_END],
];
$syslogTarget = $this
->getMock('yii\\log\\SyslogTarget', ['openlog', 'syslog', 'formatMessage', 'closelog']);
$syslogTarget = $this->getMockBuilder('yii\\log\\SyslogTarget')
->setMethods(['openlog', 'syslog', 'formatMessage', 'closelog'])
->getMock();
$syslogTarget->identity = $identity;
$syslogTarget->options = $options;

6
tests/framework/log/TargetTest.php

@ -138,7 +138,8 @@ class TargetTest extends TestCase
$target->setLevels(['trace']);
$this->assertEquals(Logger::LEVEL_TRACE, $target->getLevels());
$this->setExpectedException('yii\\base\\InvalidConfigException', 'Unrecognized level: unknown level');
$this->expectException('yii\\base\\InvalidConfigException');
$this->expectExceptionMessage('Unrecognized level: unknown level');
$target->setLevels(['info', 'unknown level']);
}
@ -156,7 +157,8 @@ class TargetTest extends TestCase
$target->setLevels(Logger::LEVEL_TRACE);
$this->assertEquals(Logger::LEVEL_TRACE, $target->getLevels());
$this->setExpectedException('yii\\base\\InvalidConfigException', 'Incorrect 128 value');
$this->expectException('yii\\base\\InvalidConfigException');
$this->expectExceptionMessage('Incorrect 128 value');
$target->setLevels(128);
}
}

4
tests/framework/mail/BaseMailerTest.php

@ -292,7 +292,9 @@ TEXT
{
$message = new Message();
$mailerMock = $this->getMockBuilder('yiiunit\framework\mail\Mailer')->setMethods(['beforeSend', 'afterSend'])->getMock();
$mailerMock = $this->getMockBuilder('yiiunit\framework\mail\Mailer')
->setMethods(['beforeSend', 'afterSend'])
->getMock();
$mailerMock->expects($this->once())->method('beforeSend')->with($message)->will($this->returnValue(true));
$mailerMock->expects($this->once())->method('afterSend')->with($message, true);
$mailerMock->send($message);

2
tests/framework/validators/CompareValidatorTest.php

@ -19,7 +19,7 @@ class CompareValidatorTest extends TestCase
public function testValidateValueException()
{
$this->setExpectedException('yii\base\InvalidConfigException');
$this->expectException('yii\base\InvalidConfigException');
$val = new CompareValidator;
$val->validate('val');
}

2
tests/framework/validators/FilterValidatorTest.php

@ -19,7 +19,7 @@ class FilterValidatorTest extends TestCase
public function testAssureExceptionOnInit()
{
$this->setExpectedException('yii\base\InvalidConfigException');
$this->expectException('yii\base\InvalidConfigException');
new FilterValidator();
}

4
tests/framework/validators/IpValidatorTest.php

@ -23,8 +23,8 @@ class IpValidatorTest extends TestCase
public function testInitException()
{
$this->setExpectedException('yii\base\InvalidConfigException',
'Both IPv4 and IPv6 checks can not be disabled at the same time');
$this->expectException('yii\base\InvalidConfigException');
$this->expectExceptionMessage('Both IPv4 and IPv6 checks can not be disabled at the same time');
new IpValidator(['ipv4' => false, 'ipv6' => false]);
}

3
tests/framework/validators/RangeValidatorTest.php

@ -19,7 +19,8 @@ class RangeValidatorTest extends TestCase
public function testInitException()
{
$this->setExpectedException('yii\base\InvalidConfigException', 'The "range" property must be set.');
$this->expectException('yii\base\InvalidConfigException');
$this->expectExceptionMessage('The "range" property must be set.');
new RangeValidator(['range' => 'not an array']);
}

2
tests/framework/validators/RegularExpressionValidatorTest.php

@ -48,7 +48,7 @@ class RegularExpressionValidatorTest extends TestCase
public function testInitException()
{
$this->setExpectedException('yii\base\InvalidConfigException');
$this->expectException('yii\base\InvalidConfigException');
$val = new RegularExpressionValidator();
$val->validate('abc');
}

2
tests/framework/validators/UniqueValidatorTest.php

@ -139,7 +139,7 @@ abstract class UniqueValidatorTest extends DatabaseTestCase
public function testValidateAttributeAttributeNotInTableException()
{
$this->setExpectedException('yii\db\Exception');
$this->expectException('yii\db\Exception');
$val = new UniqueValidator();
$m = new ValidatorTestMainModel();
$val->validateAttribute($m, 'testMainVal');

6
tests/framework/validators/ValidatorTest.php

@ -168,10 +168,8 @@ class ValidatorTest extends TestCase
public function testValidateValue()
{
$this->setExpectedException(
'yii\base\NotSupportedException',
TestValidator::className() . ' does not support validateValue().'
);
$this->expectException('yii\base\NotSupportedException');
$this->expectExceptionMessage(TestValidator::className() . ' does not support validateValue().');
$val = new TestValidator();
$val->validate('abc');
}

4
tests/framework/web/AssetBundleTest.php

@ -299,13 +299,13 @@ EOF;
if ($jqAlreadyRegistered) {
TestJqueryAsset::register($view);
}
$this->setExpectedException('yii\\base\\InvalidConfigException');
$this->expectException('yii\\base\\InvalidConfigException');
TestAssetBundle::register($view);
}
public function testCircularDependency()
{
$this->setExpectedException('yii\\base\\InvalidConfigException');
$this->expectException('yii\\base\\InvalidConfigException');
TestAssetCircleA::register($this->getView());
}

2
tests/framework/web/CacheSessionTest.php

@ -30,7 +30,7 @@ class CacheSessionTest extends \yiiunit\TestCase
public function testInvalidCache()
{
$this->setExpectedException('\Exception');
$this->expectException('\Exception');
new CacheSession(['cache' => 'invalid']);
}

2
tests/framework/web/ResponseTest.php

@ -75,7 +75,7 @@ class ResponseTest extends \yiiunit\TestCase
*/
public function testSendFileWrongRanges($rangeHeader)
{
$this->setExpectedException('yii\web\RangeNotSatisfiableHttpException');
$this->expectException('yii\web\RangeNotSatisfiableHttpException');
$dataFile = \Yii::getAlias('@yiiunit/data/web/data.txt');
$_SERVER['HTTP_RANGE'] = 'bytes=' . $rangeHeader;

4
tests/framework/web/UserTest.php

@ -268,7 +268,7 @@ class UserTest extends TestCase
$this->reset();
$_SERVER['HTTP_ACCEPT'] = 'text/json;q=0.1';
$this->setExpectedException('yii\\web\\ForbiddenHttpException');
$this->expectException('yii\\web\\ForbiddenHttpException');
$user->loginRequired();
}
@ -291,7 +291,7 @@ class UserTest extends TestCase
$this->mockWebApplication($appConfig);
$this->reset();
$_SERVER['HTTP_ACCEPT'] = 'text/json,q=0.1';
$this->setExpectedException('yii\\web\\ForbiddenHttpException');
$this->expectException('yii\\web\\ForbiddenHttpException');
Yii::$app->user->loginRequired();
}

2
tests/framework/widgets/BreadcrumbsTest.php

@ -88,7 +88,7 @@ class BreadcrumbsTest extends \yiiunit\TestCase
{
$link = ['url' => 'http://localhost/yii2'];
$method = $this->reflectMethod();
$this->setExpectedException('yii\base\InvalidConfigException');
$this->expectException('yii\base\InvalidConfigException');
$method->invoke($this->breadcrumbs, $link, $this->breadcrumbs->itemTemplate);
}

Loading…
Cancel
Save