Commit 4384a968 by Carsten Brandt

Merge pull request #2667 from AlexGx/tests-codestyle-fix

Tests codestyle fix
parents 94844231 183819ab
<?php <?php
namespace yiiunit; namespace yiiunit;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
/** /**
......
...@@ -48,7 +48,7 @@ class Customer extends ActiveRecord ...@@ -48,7 +48,7 @@ class Customer extends ActiveRecord
{ {
/** @var ActiveQuery $rel */ /** @var ActiveQuery $rel */
$rel = $this->hasMany(Item::className(), ['id' => 'item_id']); $rel = $this->hasMany(Item::className(), ['id' => 'item_id']);
return $rel->viaTable('tbl_order_item', ['order_id' => 'id'], function($q) { return $rel->viaTable('tbl_order_item', ['order_id' => 'id'], function ($q) {
/** @var ActiveQuery $q */ /** @var ActiveQuery $q */
$q->viaTable('tbl_order', ['customer_id' => 'id']); $q->viaTable('tbl_order', ['customer_id' => 'id']);
})->orderBy('id'); })->orderBy('id');
......
<?php <?php
namespace yiiunit\data\ar; namespace yiiunit\data\ar;
use yii\db\ActiveQuery; use yii\db\ActiveQuery;
/** /**
...@@ -13,4 +15,3 @@ class CustomerQuery extends ActiveQuery ...@@ -13,4 +15,3 @@ class CustomerQuery extends ActiveQuery
return $this; return $this;
} }
} }
\ No newline at end of file
...@@ -18,5 +18,4 @@ class Profile extends ActiveRecord ...@@ -18,5 +18,4 @@ class Profile extends ActiveRecord
{ {
return 'tbl_profile'; return 'tbl_profile';
} }
} }
...@@ -45,6 +45,7 @@ class Customer extends ActiveRecord ...@@ -45,6 +45,7 @@ class Customer extends ActiveRecord
/** /**
* sets up the index for this record * sets up the index for this record
* @param Command $command * @param Command $command
* @param boolean $statusIsBoolean
*/ */
public static function setUpMapping($command, $statusIsBoolean = false) public static function setUpMapping($command, $statusIsBoolean = false)
{ {
......
<?php <?php
namespace yiiunit\data\ar\elasticsearch; namespace yiiunit\data\ar\elasticsearch;
use yii\elasticsearch\ActiveQuery; use yii\elasticsearch\ActiveQuery;
/** /**
...@@ -13,4 +15,3 @@ class CustomerQuery extends ActiveQuery ...@@ -13,4 +15,3 @@ class CustomerQuery extends ActiveQuery
return $this; return $this;
} }
} }
\ No newline at end of file
<?php <?php
namespace yiiunit\data\ar\elasticsearch; namespace yiiunit\data\ar\elasticsearch;
use yii\elasticsearch\Command; use yii\elasticsearch\Command;
/** /**
......
<?php <?php
namespace yiiunit\data\ar\elasticsearch; namespace yiiunit\data\ar\elasticsearch;
use yii\elasticsearch\Command; use yii\elasticsearch\Command;
/** /**
......
<?php <?php
namespace yiiunit\data\ar\elasticsearch; namespace yiiunit\data\ar\elasticsearch;
use yii\elasticsearch\Command; use yii\elasticsearch\Command;
/** /**
......
<?php <?php
namespace yiiunit\data\ar\mongodb; namespace yiiunit\data\ar\mongodb;
use yii\mongodb\ActiveQuery; use yii\mongodb\ActiveQuery;
/** /**
...@@ -13,4 +15,3 @@ class CustomerQuery extends ActiveQuery ...@@ -13,4 +15,3 @@ class CustomerQuery extends ActiveQuery
return $this; return $this;
} }
} }
\ No newline at end of file
<?php <?php
namespace yiiunit\data\ar\mongodb\file; namespace yiiunit\data\ar\mongodb\file;
use yii\mongodb\file\ActiveQuery; use yii\mongodb\file\ActiveQuery;
/** /**
...@@ -13,4 +15,3 @@ class CustomerFileQuery extends ActiveQuery ...@@ -13,4 +15,3 @@ class CustomerFileQuery extends ActiveQuery
return $this; return $this;
} }
} }
\ No newline at end of file
<?php <?php
namespace yiiunit\data\ar\redis; namespace yiiunit\data\ar\redis;
use yii\redis\ActiveQuery; use yii\redis\ActiveQuery;
/** /**
...@@ -13,4 +15,3 @@ class CustomerQuery extends ActiveQuery ...@@ -13,4 +15,3 @@ class CustomerQuery extends ActiveQuery
return $this; return $this;
} }
} }
\ No newline at end of file
...@@ -22,7 +22,7 @@ class Order extends ActiveRecord ...@@ -22,7 +22,7 @@ class Order extends ActiveRecord
public function getItems() public function getItems()
{ {
return $this->hasMany(Item::className(), ['id' => 'item_id']) return $this->hasMany(Item::className(), ['id' => 'item_id'])
->via('orderItems', function($q) { ->via('orderItems', function ($q) {
// additional query configuration // additional query configuration
}); });
} }
......
<?php <?php
namespace yiiunit\data\ar\sphinx; namespace yiiunit\data\ar\sphinx;
use yii\sphinx\ActiveQuery; use yii\sphinx\ActiveQuery;
/** /**
...@@ -13,4 +15,3 @@ class ArticleIndexQuery extends ActiveQuery ...@@ -13,4 +15,3 @@ class ArticleIndexQuery extends ActiveQuery
return $this; return $this;
} }
} }
\ No newline at end of file
...@@ -100,7 +100,8 @@ class OAuth1Test extends TestCase ...@@ -100,7 +100,8 @@ class OAuth1Test extends TestCase
$this->assertEquals($expectedAuthorizationHeader, $authorizationHeader); $this->assertEquals($expectedAuthorizationHeader, $authorizationHeader);
} }
public function testBuildAuthUrl() { public function testBuildAuthUrl()
{
$oauthClient = new OAuth1(); $oauthClient = new OAuth1();
$authUrl = 'http://test.auth.url'; $authUrl = 'http://test.auth.url';
$oauthClient->authUrl = $authUrl; $oauthClient->authUrl = $authUrl;
......
...@@ -20,15 +20,45 @@ class ActiveRecordTest extends ElasticSearchTestCase ...@@ -20,15 +20,45 @@ class ActiveRecordTest extends ElasticSearchTestCase
{ {
use ActiveRecordTestTrait; use ActiveRecordTestTrait;
public function callCustomerFind($q = null) { return Customer::find($q); } public function callCustomerFind($q = null)
public function callOrderFind($q = null) { return Order::find($q); } {
public function callOrderItemFind($q = null) { return OrderItem::find($q); } return Customer::find($q);
public function callItemFind($q = null) { return Item::find($q); } }
public function callOrderFind($q = null)
{
return Order::find($q);
}
public function callOrderItemFind($q = null)
{
return OrderItem::find($q);
}
public function getCustomerClass() { return Customer::className(); } public function callItemFind($q = null)
public function getItemClass() { return Item::className(); } {
public function getOrderClass() { return Order::className(); } return Item::find($q);
public function getOrderItemClass() { return OrderItem::className(); } }
public function getCustomerClass()
{
return Customer::className();
}
public function getItemClass()
{
return Item::className();
}
public function getOrderClass()
{
return Order::className();
}
public function getOrderItemClass()
{
return OrderItem::className();
}
/** /**
* can be overridden to do things after save() * can be overridden to do things after save()
...@@ -224,7 +254,7 @@ class ActiveRecordTest extends ElasticSearchTestCase ...@@ -224,7 +254,7 @@ class ActiveRecordTest extends ElasticSearchTestCase
$records = Customer::mget([5]); $records = Customer::mget([5]);
$this->assertEquals(0, count($records)); $this->assertEquals(0, count($records));
$records = Customer::mget([1,3,5]); $records = Customer::mget([1, 3, 5]);
$this->assertEquals(2, count($records)); $this->assertEquals(2, count($records));
$this->assertInstanceOf(Customer::className(), $records[0]); $this->assertInstanceOf(Customer::className(), $records[0]);
$this->assertInstanceOf(Customer::className(), $records[1]); $this->assertInstanceOf(Customer::className(), $records[1]);
...@@ -501,7 +531,7 @@ class ActiveRecordTest extends ElasticSearchTestCase ...@@ -501,7 +531,7 @@ class ActiveRecordTest extends ElasticSearchTestCase
$customerClass = $this->getCustomerClass(); $customerClass = $this->getCustomerClass();
$afterFindCalls = []; $afterFindCalls = [];
Event::on(BaseActiveRecord::className(), BaseActiveRecord::EVENT_AFTER_FIND, function($event) use (&$afterFindCalls) { Event::on(BaseActiveRecord::className(), BaseActiveRecord::EVENT_AFTER_FIND, function ($event) use (&$afterFindCalls) {
/** @var BaseActiveRecord $ar */ /** @var BaseActiveRecord $ar */
$ar = $event->sender; $ar = $event->sender;
$afterFindCalls[] = [get_class($ar), $ar->getIsNewRecord(), $ar->getPrimaryKey(), $ar->isRelationPopulated('orders')]; $afterFindCalls[] = [get_class($ar), $ar->getIsNewRecord(), $ar->getPrimaryKey(), $ar->isRelationPopulated('orders')];
...@@ -523,6 +553,5 @@ class ActiveRecordTest extends ElasticSearchTestCase ...@@ -523,6 +553,5 @@ class ActiveRecordTest extends ElasticSearchTestCase
Event::off(BaseActiveRecord::className(), BaseActiveRecord::EVENT_AFTER_FIND); Event::off(BaseActiveRecord::className(), BaseActiveRecord::EVENT_AFTER_FIND);
} }
// TODO test AR with not mapped PK // TODO test AR with not mapped PK
} }
...@@ -24,5 +24,4 @@ class ElasticSearchConnectionTest extends ElasticSearchTestCase ...@@ -24,5 +24,4 @@ class ElasticSearchConnectionTest extends ElasticSearchTestCase
$this->assertArrayHasKey('version', reset($connection->nodes)); $this->assertArrayHasKey('version', reset($connection->nodes));
$this->assertArrayHasKey('http_address', reset($connection->nodes)); $this->assertArrayHasKey('http_address', reset($connection->nodes));
} }
} }
...@@ -74,4 +74,3 @@ class QueryBuilderTest extends ElasticSearchTestCase ...@@ -74,4 +74,3 @@ class QueryBuilderTest extends ElasticSearchTestCase
$this->assertEquals(3, $result['hits']['total']); $this->assertEquals(3, $result['hits']['total']);
} }
} }
...@@ -26,5 +26,4 @@ class ImageGdTest extends AbstractImageTest ...@@ -26,5 +26,4 @@ class ImageGdTest extends AbstractImageTest
$infos = gd_info(); $infos = gd_info();
return isset($infos['FreeType Support']) ? $infos['FreeType Support'] : false; return isset($infos['FreeType Support']) ? $infos['FreeType Support'] : false;
} }
} }
...@@ -26,5 +26,4 @@ class ImageGmagickTest extends AbstractImageTest ...@@ -26,5 +26,4 @@ class ImageGmagickTest extends AbstractImageTest
{ {
return true; return true;
} }
} }
...@@ -26,5 +26,4 @@ class ImageImagickTest extends AbstractImageTest ...@@ -26,5 +26,4 @@ class ImageImagickTest extends AbstractImageTest
{ {
return true; return true;
} }
} }
...@@ -16,15 +16,45 @@ class ActiveRecordTest extends RedisTestCase ...@@ -16,15 +16,45 @@ class ActiveRecordTest extends RedisTestCase
{ {
use ActiveRecordTestTrait; use ActiveRecordTestTrait;
public function callCustomerFind($q = null) { return Customer::find($q); } public function callCustomerFind($q = null)
public function callOrderFind($q = null) { return Order::find($q); } {
public function callOrderItemFind($q = null) { return OrderItem::find($q); } return Customer::find($q);
public function callItemFind($q = null) { return Item::find($q); } }
public function callOrderFind($q = null)
{
return Order::find($q);
}
public function callOrderItemFind($q = null)
{
return OrderItem::find($q);
}
public function callItemFind($q = null)
{
return Item::find($q);
}
public function getCustomerClass() { return Customer::className(); } public function getCustomerClass()
public function getItemClass() { return Item::className(); } {
public function getOrderClass() { return Order::className(); } return Customer::className();
public function getOrderItemClass() { return OrderItem::className(); } }
public function getItemClass()
{
return Item::className();
}
public function getOrderClass()
{
return Order::className();
}
public function getOrderItemClass()
{
return OrderItem::className();
}
public function setUp() public function setUp()
...@@ -207,7 +237,7 @@ class ActiveRecordTest extends RedisTestCase ...@@ -207,7 +237,7 @@ class ActiveRecordTest extends RedisTestCase
public function testFindColumn() public function testFindColumn()
{ {
$this->assertEquals(['user1', 'user2', 'user3'], Customer::find()->column('name')); $this->assertEquals(['user1', 'user2', 'user3'], Customer::find()->column('name'));
// TODO $this->assertEquals(['user3', 'user2', 'user1'], Customer::find()->orderBy(['name' => SORT_DESC])->column('name')); // TODO $this->assertEquals(['user3', 'user2', 'user1'], Customer::find()->orderBy(['name' => SORT_DESC])->column('name'));
} }
// TODO test serial column incr // TODO test serial column incr
......
...@@ -97,5 +97,4 @@ class RedisCacheTest extends CacheTestCase ...@@ -97,5 +97,4 @@ class RedisCacheTest extends CacheTestCase
$cache->set($key, $data); $cache->set($key, $data);
$this->assertTrue($cache->get($key) === $data); $this->assertTrue($cache->get($key) === $data);
} }
} }
...@@ -222,7 +222,7 @@ class CommandTest extends SphinxTestCase ...@@ -222,7 +222,7 @@ class CommandTest extends SphinxTestCase
$this->assertEquals(1, count($rows), 'No row inserted!'); $this->assertEquals(1, count($rows), 'No row inserted!');
$newTypeId = 5; $newTypeId = 5;
$command = $db->createCommand()->replace('yii2_test_rt_index',[ $command = $db->createCommand()->replace('yii2_test_rt_index', [
'type_id' => $newTypeId, 'type_id' => $newTypeId,
'category' => [3, 4], 'category' => [3, 4],
'id' => 1, 'id' => 1,
...@@ -272,7 +272,7 @@ class CommandTest extends SphinxTestCase ...@@ -272,7 +272,7 @@ class CommandTest extends SphinxTestCase
$this->assertEquals(2, count($rows), 'No rows inserted!'); $this->assertEquals(2, count($rows), 'No rows inserted!');
$newTypeId = 5; $newTypeId = 5;
$command = $db->createCommand()->replace('yii2_test_rt_index',[ $command = $db->createCommand()->replace('yii2_test_rt_index', [
'type_id' => $newTypeId, 'type_id' => $newTypeId,
'id' => 1, 'id' => 1,
]); ]);
......
...@@ -161,7 +161,7 @@ class QueryTest extends SphinxTestCase ...@@ -161,7 +161,7 @@ class QueryTest extends SphinxTestCase
$match = 'about'; $match = 'about';
$snippetPrefix = 'snippet#'; $snippetPrefix = 'snippet#';
$snippetCallback = function() use ($match, $snippetPrefix) { $snippetCallback = function () use ($match, $snippetPrefix) {
return [ return [
$snippetPrefix . '1: ' . $match, $snippetPrefix . '1: ' . $match,
$snippetPrefix . '2: ' . $match, $snippetPrefix . '2: ' . $match,
......
...@@ -356,11 +356,11 @@ trait ActiveRecordTestTrait ...@@ -356,11 +356,11 @@ trait ActiveRecordTestTrait
$this->assertEquals(2, $this->callCustomerFind()->where(['OR', ['name' => 'user1'], ['name' => 'user2']])->count()); $this->assertEquals(2, $this->callCustomerFind()->where(['OR', ['name' => 'user1'], ['name' => 'user2']])->count());
$this->assertEquals(2, count($this->callCustomerFind()->where(['OR', ['name' => 'user1'], ['name' => 'user2']])->all())); $this->assertEquals(2, count($this->callCustomerFind()->where(['OR', ['name' => 'user1'], ['name' => 'user2']])->all()));
$this->assertEquals(2, $this->callCustomerFind()->where(['name' => ['user1','user2']])->count()); $this->assertEquals(2, $this->callCustomerFind()->where(['name' => ['user1', 'user2']])->count());
$this->assertEquals(2, count($this->callCustomerFind()->where(['name' => ['user1','user2']])->all())); $this->assertEquals(2, count($this->callCustomerFind()->where(['name' => ['user1', 'user2']])->all()));
$this->assertEquals(1, $this->callCustomerFind()->where(['AND', ['name' => ['user2','user3']], ['BETWEEN', 'status', 2, 4]])->count()); $this->assertEquals(1, $this->callCustomerFind()->where(['AND', ['name' => ['user2', 'user3']], ['BETWEEN', 'status', 2, 4]])->count());
$this->assertEquals(1, count($this->callCustomerFind()->where(['AND', ['name' => ['user2','user3']], ['BETWEEN', 'status', 2, 4]])->all())); $this->assertEquals(1, count($this->callCustomerFind()->where(['AND', ['name' => ['user2', 'user3']], ['BETWEEN', 'status', 2, 4]])->all()));
} }
public function testFindNullValues() public function testFindNullValues()
...@@ -384,9 +384,9 @@ trait ActiveRecordTestTrait ...@@ -384,9 +384,9 @@ trait ActiveRecordTestTrait
$this->assertTrue($this->callCustomerFind()->where(['name' => 'user1'])->exists()); $this->assertTrue($this->callCustomerFind()->where(['name' => 'user1'])->exists());
$this->assertFalse($this->callCustomerFind()->where(['name' => 'user5'])->exists()); $this->assertFalse($this->callCustomerFind()->where(['name' => 'user5'])->exists());
$this->assertTrue($this->callCustomerFind()->where(['id' => [2,3]])->exists()); $this->assertTrue($this->callCustomerFind()->where(['id' => [2, 3]])->exists());
$this->assertTrue($this->callCustomerFind()->where(['id' => [2,3]])->offset(1)->exists()); $this->assertTrue($this->callCustomerFind()->where(['id' => [2, 3]])->offset(1)->exists());
$this->assertFalse($this->callCustomerFind()->where(['id' => [2,3]])->offset(2)->exists()); $this->assertFalse($this->callCustomerFind()->where(['id' => [2, 3]])->offset(2)->exists());
} }
public function testFindLazy() public function testFindLazy()
...@@ -854,7 +854,7 @@ trait ActiveRecordTestTrait ...@@ -854,7 +854,7 @@ trait ActiveRecordTestTrait
/** @var TestCase|ActiveRecordTestTrait $this */ /** @var TestCase|ActiveRecordTestTrait $this */
$afterFindCalls = []; $afterFindCalls = [];
Event::on(BaseActiveRecord::className(), BaseActiveRecord::EVENT_AFTER_FIND, function($event) use (&$afterFindCalls) { Event::on(BaseActiveRecord::className(), BaseActiveRecord::EVENT_AFTER_FIND, function ($event) use (&$afterFindCalls) {
/** @var BaseActiveRecord $ar */ /** @var BaseActiveRecord $ar */
$ar = $event->sender; $ar = $event->sender;
$afterFindCalls[] = [get_class($ar), $ar->getIsNewRecord(), $ar->getPrimaryKey(), $ar->isRelationPopulated('orders')]; $afterFindCalls[] = [get_class($ar), $ar->getIsNewRecord(), $ar->getPrimaryKey(), $ar->isRelationPopulated('orders')];
......
...@@ -102,5 +102,4 @@ class BehaviorTest extends TestCase ...@@ -102,5 +102,4 @@ class BehaviorTest extends TestCase
$bar->attachBehavior('bar', $behavior); $bar->attachBehavior('bar', $behavior);
$bar->nomagicBehaviorMethod(); $bar->nomagicBehaviorMethod();
} }
} }
...@@ -89,5 +89,4 @@ class Post extends ActiveRecord ...@@ -89,5 +89,4 @@ class Post extends ActiveRecord
class User extends ActiveRecord class User extends ActiveRecord
{ {
} }
...@@ -24,15 +24,45 @@ class ActiveRecordTest extends DatabaseTestCase ...@@ -24,15 +24,45 @@ class ActiveRecordTest extends DatabaseTestCase
ActiveRecord::$db = $this->getConnection(); ActiveRecord::$db = $this->getConnection();
} }
public function callCustomerFind($q = null) { return Customer::find($q); } public function callCustomerFind($q = null)
public function callOrderFind($q = null) { return Order::find($q); } {
public function callOrderItemFind($q = null) { return OrderItem::find($q); } return Customer::find($q);
public function callItemFind($q = null) { return Item::find($q); } }
public function getCustomerClass() { return Customer::className(); } public function callOrderFind($q = null)
public function getItemClass() { return Item::className(); } {
public function getOrderClass() { return Order::className(); } return Order::find($q);
public function getOrderItemClass() { return OrderItem::className(); } }
public function callOrderItemFind($q = null)
{
return OrderItem::find($q);
}
public function callItemFind($q = null)
{
return Item::find($q);
}
public function getCustomerClass()
{
return Customer::className();
}
public function getItemClass()
{
return Item::className();
}
public function getOrderClass()
{
return Order::className();
}
public function getOrderItemClass()
{
return OrderItem::className();
}
public function testCustomColumns() public function testCustomColumns()
{ {
......
...@@ -239,5 +239,4 @@ class QueryBuilderTest extends DatabaseTestCase ...@@ -239,5 +239,4 @@ class QueryBuilderTest extends DatabaseTestCase
list($actualQuerySql, $queryParams) = $this->getQueryBuilder()->build($query); list($actualQuerySql, $queryParams) = $this->getQueryBuilder()->build($query);
$this->assertEquals($expectedQuerySql, $actualQuerySql); $this->assertEquals($expectedQuerySql, $actualQuerySql);
}*/ }*/
} }
...@@ -79,5 +79,4 @@ class CubridQueryBuilderTest extends QueryBuilderTest ...@@ -79,5 +79,4 @@ class CubridQueryBuilderTest extends QueryBuilderTest
[Schema::TYPE_MONEY . ' NOT NULL', 'decimal(19,4) NOT NULL'], [Schema::TYPE_MONEY . ' NOT NULL', 'decimal(19,4) NOT NULL'],
]; ];
} }
} }
...@@ -13,14 +13,13 @@ class MSSQLQueryBuilderTest extends QueryBuilderTest ...@@ -13,14 +13,13 @@ class MSSQLQueryBuilderTest extends QueryBuilderTest
{ {
public $driverName = 'sqlsrv'; public $driverName = 'sqlsrv';
public function testOffsetLimit() { public function testOffsetLimit()
{
$expectedQuerySql = 'SELECT `id` FROM `exapmle` OFFSET 5 ROWS FETCH NEXT 10 ROWS ONLY'; $expectedQuerySql = 'SELECT `id` FROM `exapmle` OFFSET 5 ROWS FETCH NEXT 10 ROWS ONLY';
$expectedQueryParams = null; $expectedQueryParams = null;
$query = new Query(); $query = new Query();
$query->select('id') $query->select('id')->from('example')->limit(10)->offset(5);
->from('example')
->limit(10)->offset(5);
list($actualQuerySql, $actualQueryParams) = $this->getQueryBuilder()->build($query); list($actualQuerySql, $actualQueryParams) = $this->getQueryBuilder()->build($query);
...@@ -28,14 +27,13 @@ class MSSQLQueryBuilderTest extends QueryBuilderTest ...@@ -28,14 +27,13 @@ class MSSQLQueryBuilderTest extends QueryBuilderTest
$this->assertEquals($expectedQueryParams, $actualQueryParams); $this->assertEquals($expectedQueryParams, $actualQueryParams);
} }
public function testLimit() { public function testLimit()
{
$expectedQuerySql = 'SELECT `id` FROM `exapmle` OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY'; $expectedQuerySql = 'SELECT `id` FROM `exapmle` OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY';
$expectedQueryParams = null; $expectedQueryParams = null;
$query = new Query(); $query = new Query();
$query->select('id') $query->select('id')->from('example')->limit(10);
->from('example')
->limit(10);
list($actualQuerySql, $actualQueryParams) = $this->getQueryBuilder()->build($query); list($actualQuerySql, $actualQueryParams) = $this->getQueryBuilder()->build($query);
...@@ -43,14 +41,13 @@ class MSSQLQueryBuilderTest extends QueryBuilderTest ...@@ -43,14 +41,13 @@ class MSSQLQueryBuilderTest extends QueryBuilderTest
$this->assertEquals($expectedQueryParams, $actualQueryParams); $this->assertEquals($expectedQueryParams, $actualQueryParams);
} }
public function testOffset() { public function testOffset()
{
$expectedQuerySql = 'SELECT `id` FROM `exapmle` OFFSET 10 ROWS'; $expectedQuerySql = 'SELECT `id` FROM `exapmle` OFFSET 10 ROWS';
$expectedQueryParams = null; $expectedQueryParams = null;
$query = new Query(); $query = new Query();
$query->select('id') $query->select('id')->from('example')->offset(10);
->from('example')
->offset(10);
list($actualQuerySql, $actualQueryParams) = $this->getQueryBuilder()->build($query); list($actualQuerySql, $actualQueryParams) = $this->getQueryBuilder()->build($query);
......
...@@ -84,7 +84,7 @@ class SqliteQueryBuilderTest extends QueryBuilderTest ...@@ -84,7 +84,7 @@ class SqliteQueryBuilderTest extends QueryBuilderTest
public function testBatchInsert() public function testBatchInsert()
{ {
$sql = $this->getQueryBuilder()->batchInsert('{{tbl_customer}} t', ['t.id','t.name'], [[1,'a'], [2,'b']]); $sql = $this->getQueryBuilder()->batchInsert('{{tbl_customer}} t', ['t.id', 't.name'], [[1, 'a'], [2, 'b']]);
$this->assertEquals("INSERT INTO {{tbl_customer}} t (`t`.`id`, `t`.`name`) SELECT 1, 'a' UNION ALL 2, 'b'", $sql); $this->assertEquals("INSERT INTO {{tbl_customer}} t (`t`.`id`, `t`.`name`) SELECT 1, 'a' UNION ALL 2, 'b'", $sql);
} }
} }
...@@ -255,16 +255,20 @@ class FileHelperTest extends TestCase ...@@ -255,16 +255,20 @@ class FileHelperTest extends TestCase
{ {
$basePath = $this->testFilePath . DIRECTORY_SEPARATOR; $basePath = $this->testFilePath . DIRECTORY_SEPARATOR;
$dirs = ['', 'one', 'one' . DIRECTORY_SEPARATOR . 'two', 'three']; $dirs = ['', 'one', 'one' . DIRECTORY_SEPARATOR . 'two', 'three'];
$files = array_fill_keys(array_map(function($n){return "a.$n";}, range(1,8)), 'file contents'); $files = array_fill_keys(array_map(function ($n) {
return "a.$n";
}, range(1, 8)), 'file contents');
$tree = $files; $tree = $files;
$root = $files; $root = $files;
$flat = []; $flat = [];
foreach ($dirs as $dir) { foreach ($dirs as $dir) {
foreach ($files as $fileName => $contents) { foreach ($files as $fileName => $contents) {
$flat[] = rtrim($basePath.$dir,DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$fileName; $flat[] = rtrim($basePath . $dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $fileName;
}
if ($dir === '') {
continue;
} }
if ($dir === '') continue;
$parts = explode(DIRECTORY_SEPARATOR, $dir); $parts = explode(DIRECTORY_SEPARATOR, $dir);
$last = array_pop($parts); $last = array_pop($parts);
$parent = array_pop($parts); $parent = array_pop($parts);
...@@ -280,25 +284,31 @@ class FileHelperTest extends TestCase ...@@ -280,25 +284,31 @@ class FileHelperTest extends TestCase
// range // range
$foundFiles = FileHelper::findFiles($basePath, ['except' => ['a.[2-8]']]); $foundFiles = FileHelper::findFiles($basePath, ['except' => ['a.[2-8]']]);
sort($foundFiles); sort($foundFiles);
$expect = array_values(array_filter($flat, function($p){return substr($p, -3)==='a.1';})); $expect = array_values(array_filter($flat, function ($p) {
return substr($p, -3)==='a.1';
}));
$this->assertEquals($expect, $foundFiles); $this->assertEquals($expect, $foundFiles);
// suffix // suffix
$foundFiles = FileHelper::findFiles($basePath, ['except' => ['*.1']]); $foundFiles = FileHelper::findFiles($basePath, ['except' => ['*.1']]);
sort($foundFiles); sort($foundFiles);
$expect = array_values(array_filter($flat, function($p){return substr($p, -3)!=='a.1';})); $expect = array_values(array_filter($flat, function ($p) {
return substr($p, -3)!=='a.1';
}));
$this->assertEquals($expect, $foundFiles); $this->assertEquals($expect, $foundFiles);
// dir // dir
$foundFiles = FileHelper::findFiles($basePath, ['except' => ['/one']]); $foundFiles = FileHelper::findFiles($basePath, ['except' => ['/one']]);
sort($foundFiles); sort($foundFiles);
$expect = array_values(array_filter($flat, function($p){return strpos($p, DIRECTORY_SEPARATOR.'one')===false;})); $expect = array_values(array_filter($flat, function ($p) {
return strpos($p, DIRECTORY_SEPARATOR.'one')===false;
}));
$this->assertEquals($expect, $foundFiles); $this->assertEquals($expect, $foundFiles);
// dir contents // dir contents
$foundFiles = FileHelper::findFiles($basePath, ['except' => ['?*/a.1']]); $foundFiles = FileHelper::findFiles($basePath, ['except' => ['?*/a.1']]);
sort($foundFiles); sort($foundFiles);
$expect = array_values(array_filter($flat, function($p){ $expect = array_values(array_filter($flat, function ($p) {
return substr($p, -11, 10)==='one'.DIRECTORY_SEPARATOR.'two'.DIRECTORY_SEPARATOR.'a.' || ( return substr($p, -11, 10)==='one'.DIRECTORY_SEPARATOR.'two'.DIRECTORY_SEPARATOR.'a.' || (
substr($p, -8)!==DIRECTORY_SEPARATOR.'one'.DIRECTORY_SEPARATOR.'a.1' && substr($p, -8)!==DIRECTORY_SEPARATOR.'one'.DIRECTORY_SEPARATOR.'a.1' &&
substr($p, -10)!==DIRECTORY_SEPARATOR.'three'.DIRECTORY_SEPARATOR.'a.1' substr($p, -10)!==DIRECTORY_SEPARATOR.'three'.DIRECTORY_SEPARATOR.'a.1'
......
...@@ -213,7 +213,7 @@ class HtmlTest extends TestCase ...@@ -213,7 +213,7 @@ class HtmlTest extends TestCase
{ {
$this->assertEquals('<input type="radio" name="test" value="1">', Html::radio('test')); $this->assertEquals('<input type="radio" name="test" value="1">', Html::radio('test'));
$this->assertEquals('<input type="radio" class="a" name="test" checked>', Html::radio('test', true, ['class' => 'a', 'value' => null])); $this->assertEquals('<input type="radio" class="a" name="test" checked>', Html::radio('test', true, ['class' => 'a', 'value' => null]));
$this->assertEquals('<input type="hidden" name="test" value="0"><input type="radio" class="a" name="test" value="2" checked>', Html::radio('test', true, ['class' => 'a' , 'uncheck' => '0', 'value' => 2])); $this->assertEquals('<input type="hidden" name="test" value="0"><input type="radio" class="a" name="test" value="2" checked>', Html::radio('test', true, ['class' => 'a', 'uncheck' => '0', 'value' => 2]));
$this->assertEquals('<div class="radio"><label class="bbb"><input type="radio" class="a" name="test" checked> ccc</label></div>', Html::radio('test', true, [ $this->assertEquals('<div class="radio"><label class="bbb"><input type="radio" class="a" name="test" checked> ccc</label></div>', Html::radio('test', true, [
'class' => 'a', 'class' => 'a',
......
...@@ -105,13 +105,13 @@ class I18NTest extends TestCase ...@@ -105,13 +105,13 @@ class I18NTest extends TestCase
$this->assertEquals('Missing translation message.', $this->i18n->translate('test', 'Missing translation message.', [], 'de-DE')); $this->assertEquals('Missing translation message.', $this->i18n->translate('test', 'Missing translation message.', [], 'de-DE'));
$this->assertEquals('Hallo Welt!', $this->i18n->translate('test', 'Hello world!', [], 'de-DE')); $this->assertEquals('Hallo Welt!', $this->i18n->translate('test', 'Hello world!', [], 'de-DE'));
Event::on(PhpMessageSource::className(), PhpMessageSource::EVENT_MISSING_TRANSLATION, function($event) {}); Event::on(PhpMessageSource::className(), PhpMessageSource::EVENT_MISSING_TRANSLATION, function ($event) {});
$this->assertEquals('Hallo Welt!', $this->i18n->translate('test', 'Hello world!', [], 'de-DE')); $this->assertEquals('Hallo Welt!', $this->i18n->translate('test', 'Hello world!', [], 'de-DE'));
$this->assertEquals('Missing translation message.', $this->i18n->translate('test', 'Missing translation message.', [], 'de-DE')); $this->assertEquals('Missing translation message.', $this->i18n->translate('test', 'Missing translation message.', [], 'de-DE'));
$this->assertEquals('Hallo Welt!', $this->i18n->translate('test', 'Hello world!', [], 'de-DE')); $this->assertEquals('Hallo Welt!', $this->i18n->translate('test', 'Hello world!', [], 'de-DE'));
Event::off(PhpMessageSource::className(), PhpMessageSource::EVENT_MISSING_TRANSLATION); Event::off(PhpMessageSource::className(), PhpMessageSource::EVENT_MISSING_TRANSLATION);
Event::on(PhpMessageSource::className(), PhpMessageSource::EVENT_MISSING_TRANSLATION, function($event) { Event::on(PhpMessageSource::className(), PhpMessageSource::EVENT_MISSING_TRANSLATION, function ($event) {
if ($event->message == 'New missing translation message.') { if ($event->message == 'New missing translation message.') {
$event->translatedMessage = 'TRANSLATION MISSING HERE!'; $event->translatedMessage = 'TRANSLATION MISSING HERE!';
} }
...@@ -124,4 +124,3 @@ class I18NTest extends TestCase ...@@ -124,4 +124,3 @@ class I18NTest extends TestCase
Event::off(PhpMessageSource::className(), PhpMessageSource::EVENT_MISSING_TRANSLATION); Event::off(PhpMessageSource::className(), PhpMessageSource::EVENT_MISSING_TRANSLATION);
} }
} }
...@@ -235,12 +235,11 @@ class BaseMailerTest extends TestCase ...@@ -235,12 +235,11 @@ class BaseMailerTest extends TestCase
{ {
$message = new Message(); $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('beforeSend')->with($message)->will($this->returnValue(true));
$mailerMock->expects($this->once())->method('afterSend')->with($message,true); $mailerMock->expects($this->once())->method('afterSend')->with($message, true);
$mailerMock->send($message); $mailerMock->send($message);
} }
} }
/** /**
......
...@@ -78,39 +78,62 @@ class TestMessage extends BaseMessage ...@@ -78,39 +78,62 @@ class TestMessage extends BaseMessage
public $text; public $text;
public $html; public $html;
public function getCharset() {return '';} public function getCharset()
{
return '';
}
public function setCharset($charset) {} public function setCharset($charset) {}
public function getFrom() {return '';} public function getFrom()
{
return '';
}
public function setFrom($from) {} public function setFrom($from) {}
public function getReplyTo() {return '';} public function getReplyTo()
{
return '';
}
public function setReplyTo($replyTo) {} public function setReplyTo($replyTo) {}
public function getTo() {return '';} public function getTo()
{
return '';
}
public function setTo($to) {} public function setTo($to) {}
public function getCc() {return '';} public function getCc()
{
return '';
}
public function setCc($cc) {} public function setCc($cc) {}
public function getBcc() {return '';} public function getBcc()
{
return '';
}
public function setBcc($bcc) {} public function setBcc($bcc){}
public function getSubject() {return '';} public function getSubject()
{
return '';
}
public function setSubject($subject) {} public function setSubject($subject) {}
public function setTextBody($text) { public function setTextBody($text)
{
$this->text = $text; $this->text = $text;
} }
public function setHtmlBody($html) { public function setHtmlBody($html)
{
$this->html = $html; $this->html = $html;
} }
......
...@@ -6,8 +6,6 @@ use yii\validators\CompareValidator; ...@@ -6,8 +6,6 @@ use yii\validators\CompareValidator;
use yiiunit\data\validators\models\FakedValidationModel; use yiiunit\data\validators\models\FakedValidationModel;
use yiiunit\TestCase; use yiiunit\TestCase;
class CompareValidatorTest extends TestCase class CompareValidatorTest extends TestCase
{ {
protected function setUp() protected function setUp()
......
...@@ -7,7 +7,6 @@ use yii\validators\DateValidator; ...@@ -7,7 +7,6 @@ use yii\validators\DateValidator;
use yiiunit\data\validators\models\FakedValidationModel; use yiiunit\data\validators\models\FakedValidationModel;
use yiiunit\TestCase; use yiiunit\TestCase;
class DateValidatorTest extends TestCase class DateValidatorTest extends TestCase
{ {
protected function setUp() protected function setUp()
......
<?php <?php
namespace yiiunit\framework\validators; namespace yiiunit\framework\validators;
use yii\validators\DefaultValueValidator; use yii\validators\DefaultValueValidator;
use yiiunit\TestCase; use yiiunit\TestCase;
......
...@@ -144,7 +144,7 @@ class NumberValidatorTest extends TestCase ...@@ -144,7 +144,7 @@ class NumberValidatorTest extends TestCase
$val->validateAttribute($model, 'attr_number'); $val->validateAttribute($model, 'attr_number');
$this->assertTrue($model->hasErrors('attr_number')); $this->assertTrue($model->hasErrors('attr_number'));
$val = new NumberValidator(['min' => 1]); $val = new NumberValidator(['min' => 1]);
$model = FakedValidationModel::createWithAttributes(['attr_num' => [1,2,3]]); $model = FakedValidationModel::createWithAttributes(['attr_num' => [1, 2, 3]]);
$val->validateAttribute($model, 'attr_num'); $val->validateAttribute($model, 'attr_num');
$this->assertTrue($model->hasErrors('attr_num')); $this->assertTrue($model->hasErrors('attr_num'));
} }
......
...@@ -50,5 +50,4 @@ class RegularExpressionValidatorTest extends TestCase ...@@ -50,5 +50,4 @@ class RegularExpressionValidatorTest extends TestCase
$val = new RegularExpressionValidator(); $val = new RegularExpressionValidator();
$val->validate('abc'); $val->validate('abc');
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment