Commit 0702a091 by JacekK

Merge branch 'master' of git://github.com/yiisoft/yii2 into guide-not-found-links

parents edc3d2b1 f7a5c29e
......@@ -31,7 +31,16 @@ install:
- composer install --dev --prefer-dist -d apps/basic
- cd apps/basic && composer require --dev codeception/codeception:1.8.*@dev codeception/specify:* codeception/verify:*
- php vendor/bin/codecept build && cd ../..
- cd apps && php -S localhost:8080 &
# advanced application:
- composer install --dev --prefer-dist -d apps/advanced
- cd apps/advanced && composer require --dev codeception/codeception:1.8.*@dev codeception/specify:* codeception/verify:*
- ./init --env=Development
- sed -i s/root/travis/ common/config/main-local.php
- cd backend && php ../vendor/bin/codecept build
- cd ../common && php ../vendor/bin/codecept build
- cd ../frontend && php ../vendor/bin/codecept build && cd ../../..
# boot server
- cd apps && php -S localhost:8080 > /dev/null 2>&1 &
before_script:
- echo 'elasticsearch version ' && curl http://localhost:9200/
......@@ -39,13 +48,21 @@ before_script:
- psql -U postgres -c 'CREATE DATABASE yiitest;';
- tests/unit/data/travis/sphinx-setup.sh
- mongo yii2test --eval 'db.addUser("travis", "test");'
- mysql -e 'CREATE DATABASE yii2_advanced_acceptance;';
- mysql -e 'CREATE DATABASE yii2_advanced_functional;';
- mysql -e 'CREATE DATABASE yii2_advanced_unit;';
- cd apps/advanced/frontend/tests/acceptance && php yii migrate --interactive=0
- cd ../functional && php yii migrate --interactive=0
- cd ../unit && php yii migrate --interactive=0 && cd ../../../../..
script:
- vendor/bin/phpunit --verbose --coverage-clover=coverage.clover --exclude-group mssql,oci,wincache,xcache,zenddata
- cd apps/basic && php vendor/bin/codecept run
- cd ../advanced/backend && ../vendor/bin/codecept run
- cd ../common && ../vendor/bin/codecept run
- cd ../frontend && ../vendor/bin/codecept run
after_script:
- cd ../..
- pwd
- cd ../../..
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
......@@ -111,8 +111,9 @@ To make your database up to date, you can run in needed test folder `yii migrate
if you are starting from `frontend` tests then you should run `yii migrate` in each suite folder `acceptance`, `functional`, `unit`
it will upgrade your database to the last state according migrations.
To be able to run acceptance tests you should configure your server to point doc_root to your new created application. For example if we
use php builtin server, then all that is needed to do is run `php -S 127.0.0.1:8080` in main project directory - directory that contains `frontend`, `backend`, `common`, `console` directories.
To be able to run acceptance tests you need a running webserver. For this you can use the php bultin server and run it in the directory where your main project folder is located. For example if your application is located in `/www/advanced` all you need to is:
`cd /www` and then `php -S 127.0.0.1:8080` because the default configuration of acceptance tests expects the url of the application to be `/advanced/`.
If you already have a server configured or your application is not located in a folder called `advanced`, you may need to adjust the `TEST_ENTRY_URL` in `frontend/tests/_bootstrap.php` and `backend/tests/_bootstrap.php`.
After that is done you should be able to run your tests, for example to run `frontend` tests do:
......
......@@ -2,7 +2,7 @@
// the entry script URL (without host info) for functional and acceptance tests
// PLEASE ADJUST IT TO THE ACTUAL ENTRY SCRIPT URL
defined('TEST_ENTRY_URL') or define('TEST_ENTRY_URL', '/backend/web/index-test.php');
defined('TEST_ENTRY_URL') or define('TEST_ENTRY_URL', '/advanced/backend/web/index-test.php');
// the entry script file path for functional and acceptance tests
defined('TEST_ENTRY_FILE') or define('TEST_ENTRY_FILE', dirname(__DIR__) . '/web/index-test.php');
......
......@@ -2,7 +2,7 @@
// the entry script URL (without host info) for functional and acceptance tests
// PLEASE ADJUST IT TO THE ACTUAL ENTRY SCRIPT URL
defined('TEST_ENTRY_URL') or define('TEST_ENTRY_URL', '/frontend/web/index-test.php');
defined('TEST_ENTRY_URL') or define('TEST_ENTRY_URL', '/advanced/frontend/web/index-test.php');
// the entry script file path for functional and acceptance tests
defined('TEST_ENTRY_FILE') or define('TEST_ENTRY_FILE', dirname(__DIR__) . '/web/index-test.php');
......
......@@ -136,5 +136,23 @@ class ExampleController extends \yii\console\Controller
### Exit Code
Using return codes is the best practice of console application development. If command returns `0` it means everything
is OK. If it is a number more than zero, we have an error and integer returned is the error code.
Using exit codes is the best practice of console application development. If a command returns `0` it means
everything is OK. If it is a number greater than zero, we have an error and the number returned is the error
code that may be interpreted to find out details about the error.
For example `1` could stand generally for an unknown error and all codes above are declared for specific cases
such as input errors, missing files, and so forth.
To have your console command return with an exit code you simply return an integer in the controller action
method:
```php
public function actionIndex()
{
if (/* some problem */) {
echo "A problem occured!\n";
return 1;
}
// do something
return 0;
}
```
......@@ -12,7 +12,7 @@ Grid view supports both sorting and pagination of the data items. The sorting an
or normal page request. A benefit of using GridView is that when the user disables JavaScript, the sorting and pagination
automatically degrade to normal page requests and are still functioning as expected.
The minimal code needed to use CGridView is as follows:
The minimal code needed to use GridView is as follows:
```php
use yii\data\GridView;
......@@ -185,11 +185,6 @@ echo GridView::widget([
['class' => 'yii\grid\SerialColumn'], // <-- here
```
TODO: rewrite these:
- https://github.com/samdark/a-guide-to-yii-grids-lists-and-data-providers/blob/master/grid-columns.md
- https://github.com/samdark/a-guide-to-yii-grids-lists-and-data-providers/pull/1
Sorting data
------------
......
......@@ -164,7 +164,7 @@ fixtures that are applied to ALL or many test cases. An example is [[yii\test\In
two things:
* Perform some common initialization tasks by executing a script located at `@app/tests/fixtures/initdb.php`;
* Disable the database integrity check before loading other DB fixtures, and re-enable it after other DB fixtures are unloead.
* Disable the database integrity check before loading other DB fixtures, and re-enable it after other DB fixtures are unloaded.
Using global fixtures is similar to using non-global ones. The only difference is that you declare these fixtures
in [[yii\codeception\TestCase::globalFixtures()]] instead of `fixtures()`. When a test case loads fixtures, it will
......
......@@ -113,7 +113,7 @@ abstract class BaseController extends Controller
}
/**
* @inheritdoc
* @param string $template
* @return BaseRenderer
*/
protected abstract function findRenderer($template);
......
......@@ -95,17 +95,17 @@ class BaseDoc extends Object
}
}
// TODO
public function loadSource($reflection)
{
$this->sourcePath = str_replace('\\', '/', str_replace(YII_PATH, '', $reflection->getFileName()));
$this->startLine = $reflection->getStartLine();
$this->endLine = $reflection->getEndLine();
}
public function getSourceCode()
{
$lines = file(YII_PATH . $this->sourcePath);
return implode("", array_slice($lines, $this->startLine - 1, $this->endLine - $this->startLine + 1));
}
// TODO implement
// public function loadSource($reflection)
// {
// $this->sourceFile;
// $this->startLine;
// $this->endLine;
// }
//
// public function getSourceCode()
// {
// $lines = file(YII_PATH . $this->sourcePath);
// return implode("", array_slice($lines, $this->startLine - 1, $this->endLine - $this->startLine + 1));
// }
}
......@@ -299,7 +299,8 @@ class Context extends Component
/**
* @param ClassDoc $classA
* @param ClassDoc $classB
* @param ClassDoc|string $classB
* @return boolean
*/
protected function isSubclassOf($classA, $classB)
{
......
......@@ -118,7 +118,7 @@ class SideNavWidget extends \yii\bootstrap\Widget
/**
* Renders a widget's item.
* @param string|array $item the item to render.
* @param bool $collapsed whether to collapse item if not active
* @param boolean $collapsed whether to collapse item if not active
* @throws \yii\base\InvalidConfigException
* @return string the rendering result.
* @throws InvalidConfigException if label is not defined
......
<?php
namespace yiiunit;
use yii\helpers\ArrayHelper;
/**
......
......@@ -48,7 +48,7 @@ class Customer extends ActiveRecord
{
/** @var ActiveQuery $rel */
$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 */
$q->viaTable('tbl_order', ['customer_id' => 'id']);
})->orderBy('id');
......
<?php
namespace yiiunit\data\ar;
use yii\db\ActiveQuery;
/**
......@@ -13,4 +15,3 @@ class CustomerQuery extends ActiveQuery
return $this;
}
}
\ No newline at end of file
......@@ -18,5 +18,4 @@ class Profile extends ActiveRecord
{
return 'tbl_profile';
}
}
......@@ -45,6 +45,7 @@ class Customer extends ActiveRecord
/**
* sets up the index for this record
* @param Command $command
* @param boolean $statusIsBoolean
*/
public static function setUpMapping($command, $statusIsBoolean = false)
{
......
<?php
namespace yiiunit\data\ar\elasticsearch;
use yii\elasticsearch\ActiveQuery;
/**
......@@ -13,4 +15,3 @@ class CustomerQuery extends ActiveQuery
return $this;
}
}
\ No newline at end of file
<?php
namespace yiiunit\data\ar\elasticsearch;
use yii\elasticsearch\Command;
/**
......
<?php
namespace yiiunit\data\ar\elasticsearch;
use yii\elasticsearch\Command;
/**
......
<?php
namespace yiiunit\data\ar\elasticsearch;
use yii\elasticsearch\Command;
/**
......
<?php
namespace yiiunit\data\ar\mongodb;
use yii\mongodb\ActiveQuery;
/**
......@@ -13,4 +15,3 @@ class CustomerQuery extends ActiveQuery
return $this;
}
}
\ No newline at end of file
<?php
namespace yiiunit\data\ar\mongodb\file;
use yii\mongodb\file\ActiveQuery;
/**
......@@ -13,4 +15,3 @@ class CustomerFileQuery extends ActiveQuery
return $this;
}
}
\ No newline at end of file
<?php
namespace yiiunit\data\ar\redis;
use yii\redis\ActiveQuery;
/**
......@@ -13,4 +15,3 @@ class CustomerQuery extends ActiveQuery
return $this;
}
}
\ No newline at end of file
......@@ -22,7 +22,7 @@ class Order extends ActiveRecord
public function getItems()
{
return $this->hasMany(Item::className(), ['id' => 'item_id'])
->via('orderItems', function($q) {
->via('orderItems', function ($q) {
// additional query configuration
});
}
......
<?php
namespace yiiunit\data\ar\sphinx;
use yii\sphinx\ActiveQuery;
/**
......@@ -13,4 +15,3 @@ class ArticleIndexQuery extends ActiveQuery
return $this;
}
}
\ No newline at end of file
......@@ -100,7 +100,8 @@ class OAuth1Test extends TestCase
$this->assertEquals($expectedAuthorizationHeader, $authorizationHeader);
}
public function testBuildAuthUrl() {
public function testBuildAuthUrl()
{
$oauthClient = new OAuth1();
$authUrl = 'http://test.auth.url';
$oauthClient->authUrl = $authUrl;
......
......@@ -20,15 +20,45 @@ class ActiveRecordTest extends ElasticSearchTestCase
{
use ActiveRecordTestTrait;
public function callCustomerFind($q = null) { return Customer::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 callCustomerFind($q = null)
{
return Customer::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 getItemClass() { return Item::className(); }
public function getOrderClass() { return Order::className(); }
public function getOrderItemClass() { return OrderItem::className(); }
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();
}
/**
* can be overridden to do things after save()
......@@ -224,7 +254,7 @@ class ActiveRecordTest extends ElasticSearchTestCase
$records = Customer::mget([5]);
$this->assertEquals(0, count($records));
$records = Customer::mget([1,3,5]);
$records = Customer::mget([1, 3, 5]);
$this->assertEquals(2, count($records));
$this->assertInstanceOf(Customer::className(), $records[0]);
$this->assertInstanceOf(Customer::className(), $records[1]);
......@@ -501,7 +531,7 @@ class ActiveRecordTest extends ElasticSearchTestCase
$customerClass = $this->getCustomerClass();
$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 */
$ar = $event->sender;
$afterFindCalls[] = [get_class($ar), $ar->getIsNewRecord(), $ar->getPrimaryKey(), $ar->isRelationPopulated('orders')];
......@@ -523,6 +553,5 @@ class ActiveRecordTest extends ElasticSearchTestCase
Event::off(BaseActiveRecord::className(), BaseActiveRecord::EVENT_AFTER_FIND);
}
// TODO test AR with not mapped PK
}
......@@ -24,5 +24,4 @@ class ElasticSearchConnectionTest extends ElasticSearchTestCase
$this->assertArrayHasKey('version', reset($connection->nodes));
$this->assertArrayHasKey('http_address', reset($connection->nodes));
}
}
......@@ -74,4 +74,3 @@ class QueryBuilderTest extends ElasticSearchTestCase
$this->assertEquals(3, $result['hits']['total']);
}
}
......@@ -26,5 +26,4 @@ class ImageGdTest extends AbstractImageTest
$infos = gd_info();
return isset($infos['FreeType Support']) ? $infos['FreeType Support'] : false;
}
}
......@@ -26,5 +26,4 @@ class ImageGmagickTest extends AbstractImageTest
{
return true;
}
}
......@@ -26,5 +26,4 @@ class ImageImagickTest extends AbstractImageTest
{
return true;
}
}
......@@ -16,15 +16,45 @@ class ActiveRecordTest extends RedisTestCase
{
use ActiveRecordTestTrait;
public function callCustomerFind($q = null) { return Customer::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 callCustomerFind($q = null)
{
return Customer::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 getItemClass() { return Item::className(); }
public function getOrderClass() { return Order::className(); }
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();
}
public function setUp()
......@@ -207,7 +237,7 @@ class ActiveRecordTest extends RedisTestCase
public function testFindColumn()
{
$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
......
......@@ -97,5 +97,4 @@ class RedisCacheTest extends CacheTestCase
$cache->set($key, $data);
$this->assertTrue($cache->get($key) === $data);
}
}
......@@ -222,7 +222,7 @@ class CommandTest extends SphinxTestCase
$this->assertEquals(1, count($rows), 'No row inserted!');
$newTypeId = 5;
$command = $db->createCommand()->replace('yii2_test_rt_index',[
$command = $db->createCommand()->replace('yii2_test_rt_index', [
'type_id' => $newTypeId,
'category' => [3, 4],
'id' => 1,
......@@ -272,7 +272,7 @@ class CommandTest extends SphinxTestCase
$this->assertEquals(2, count($rows), 'No rows inserted!');
$newTypeId = 5;
$command = $db->createCommand()->replace('yii2_test_rt_index',[
$command = $db->createCommand()->replace('yii2_test_rt_index', [
'type_id' => $newTypeId,
'id' => 1,
]);
......
......@@ -161,7 +161,7 @@ class QueryTest extends SphinxTestCase
$match = 'about';
$snippetPrefix = 'snippet#';
$snippetCallback = function() use ($match, $snippetPrefix) {
$snippetCallback = function () use ($match, $snippetPrefix) {
return [
$snippetPrefix . '1: ' . $match,
$snippetPrefix . '2: ' . $match,
......
......@@ -356,11 +356,11 @@ trait ActiveRecordTestTrait
$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, $this->callCustomerFind()->where(['name' => ['user1','user2']])->count());
$this->assertEquals(2, count($this->callCustomerFind()->where(['name' => ['user1','user2']])->all()));
$this->assertEquals(2, $this->callCustomerFind()->where(['name' => ['user1', 'user2']])->count());
$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, count($this->callCustomerFind()->where(['AND', ['name' => ['user2','user3']], ['BETWEEN', 'status', 2, 4]])->all()));
$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()));
}
public function testFindNullValues()
......@@ -384,9 +384,9 @@ trait ActiveRecordTestTrait
$this->assertTrue($this->callCustomerFind()->where(['name' => 'user1'])->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]])->offset(1)->exists());
$this->assertFalse($this->callCustomerFind()->where(['id' => [2,3]])->offset(2)->exists());
$this->assertTrue($this->callCustomerFind()->where(['id' => [2, 3]])->exists());
$this->assertTrue($this->callCustomerFind()->where(['id' => [2, 3]])->offset(1)->exists());
$this->assertFalse($this->callCustomerFind()->where(['id' => [2, 3]])->offset(2)->exists());
}
public function testFindLazy()
......@@ -854,7 +854,7 @@ trait ActiveRecordTestTrait
/** @var TestCase|ActiveRecordTestTrait $this */
$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 */
$ar = $event->sender;
$afterFindCalls[] = [get_class($ar), $ar->getIsNewRecord(), $ar->getPrimaryKey(), $ar->isRelationPopulated('orders')];
......
......@@ -102,5 +102,4 @@ class BehaviorTest extends TestCase
$bar->attachBehavior('bar', $behavior);
$bar->nomagicBehaviorMethod();
}
}
......@@ -89,5 +89,4 @@ class Post extends ActiveRecord
class User extends ActiveRecord
{
}
......@@ -24,15 +24,45 @@ class ActiveRecordTest extends DatabaseTestCase
ActiveRecord::$db = $this->getConnection();
}
public function callCustomerFind($q = null) { return Customer::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 getItemClass() { return Item::className(); }
public function getOrderClass() { return Order::className(); }
public function getOrderItemClass() { return OrderItem::className(); }
public function callCustomerFind($q = null)
{
return Customer::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 getItemClass()
{
return Item::className();
}
public function getOrderClass()
{
return Order::className();
}
public function getOrderItemClass()
{
return OrderItem::className();
}
public function testCustomColumns()
{
......
......@@ -239,5 +239,4 @@ class QueryBuilderTest extends DatabaseTestCase
list($actualQuerySql, $queryParams) = $this->getQueryBuilder()->build($query);
$this->assertEquals($expectedQuerySql, $actualQuerySql);
}*/
}
......@@ -79,5 +79,4 @@ class CubridQueryBuilderTest extends QueryBuilderTest
[Schema::TYPE_MONEY . ' NOT NULL', 'decimal(19,4) NOT NULL'],
];
}
}
......@@ -13,14 +13,13 @@ class MSSQLQueryBuilderTest extends QueryBuilderTest
{
public $driverName = 'sqlsrv';
public function testOffsetLimit() {
public function testOffsetLimit()
{
$expectedQuerySql = 'SELECT `id` FROM `exapmle` OFFSET 5 ROWS FETCH NEXT 10 ROWS ONLY';
$expectedQueryParams = null;
$query = new Query();
$query->select('id')
->from('example')
->limit(10)->offset(5);
$query->select('id')->from('example')->limit(10)->offset(5);
list($actualQuerySql, $actualQueryParams) = $this->getQueryBuilder()->build($query);
......@@ -28,14 +27,13 @@ class MSSQLQueryBuilderTest extends QueryBuilderTest
$this->assertEquals($expectedQueryParams, $actualQueryParams);
}
public function testLimit() {
public function testLimit()
{
$expectedQuerySql = 'SELECT `id` FROM `exapmle` OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY';
$expectedQueryParams = null;
$query = new Query();
$query->select('id')
->from('example')
->limit(10);
$query->select('id')->from('example')->limit(10);
list($actualQuerySql, $actualQueryParams) = $this->getQueryBuilder()->build($query);
......@@ -43,14 +41,13 @@ class MSSQLQueryBuilderTest extends QueryBuilderTest
$this->assertEquals($expectedQueryParams, $actualQueryParams);
}
public function testOffset() {
public function testOffset()
{
$expectedQuerySql = 'SELECT `id` FROM `exapmle` OFFSET 10 ROWS';
$expectedQueryParams = null;
$query = new Query();
$query->select('id')
->from('example')
->offset(10);
$query->select('id')->from('example')->offset(10);
list($actualQuerySql, $actualQueryParams) = $this->getQueryBuilder()->build($query);
......
......@@ -84,7 +84,7 @@ class SqliteQueryBuilderTest extends QueryBuilderTest
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);
}
}
......@@ -255,16 +255,20 @@ class FileHelperTest extends TestCase
{
$basePath = $this->testFilePath . DIRECTORY_SEPARATOR;
$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;
$root = $files;
$flat = [];
foreach ($dirs as $dir) {
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);
$last = array_pop($parts);
$parent = array_pop($parts);
......@@ -280,25 +284,31 @@ class FileHelperTest extends TestCase
// range
$foundFiles = FileHelper::findFiles($basePath, ['except' => ['a.[2-8]']]);
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);
// suffix
$foundFiles = FileHelper::findFiles($basePath, ['except' => ['*.1']]);
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);
// dir
$foundFiles = FileHelper::findFiles($basePath, ['except' => ['/one']]);
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);
// dir contents
$foundFiles = FileHelper::findFiles($basePath, ['except' => ['?*/a.1']]);
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.' || (
substr($p, -8)!==DIRECTORY_SEPARATOR.'one'.DIRECTORY_SEPARATOR.'a.1' &&
substr($p, -10)!==DIRECTORY_SEPARATOR.'three'.DIRECTORY_SEPARATOR.'a.1'
......
......@@ -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" 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, [
'class' => 'a',
......
......@@ -105,13 +105,13 @@ class I18NTest extends TestCase
$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'));
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('Missing translation message.', $this->i18n->translate('test', 'Missing translation message.', [], 'de-DE'));
$this->assertEquals('Hallo Welt!', $this->i18n->translate('test', 'Hello world!', [], 'de-DE'));
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.') {
$event->translatedMessage = 'TRANSLATION MISSING HERE!';
}
......@@ -124,4 +124,3 @@ class I18NTest extends TestCase
Event::off(PhpMessageSource::className(), PhpMessageSource::EVENT_MISSING_TRANSLATION);
}
}
......@@ -235,12 +235,11 @@ class BaseMailerTest extends TestCase
{
$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->expects($this->once())->method('afterSend')->with($message, true);
$mailerMock->send($message);
}
}
/**
......
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