Merge branch 'master' into pr/1177

This commit is contained in:
李铭昕 2019-12-26 14:36:50 +08:00
commit c4c1276db0
10 changed files with 89 additions and 7 deletions

View File

@ -5,13 +5,13 @@ sudo: required
matrix:
include:
- php: 7.2
env: SW_VERSION="4.4.12"
env: SW_VERSION="4.4.14"
- php: 7.3
env: SW_VERSION="4.4.12"
env: SW_VERSION="4.4.14"
- php: 7.4
env: SW_VERSION="4.4.12"
env: SW_VERSION="4.4.14"
- php: master
env: SW_VERSION="4.4.12"
env: SW_VERSION="4.4.14"
allow_failures:
- php: master

View File

@ -5,6 +5,6 @@ tar -xf swoole.tar.gz -C swoole --strip-components=1
rm swoole.tar.gz
cd swoole
phpize
./configure --enable-openssl --enable-mysqlnd
./configure --enable-openssl --enable-mysqlnd --enable-http2
make -j$(nproc)
make install

View File

@ -1,5 +1,14 @@
# v1.1.12 - TBD
## Fixed
- [#1189](https://github.com/hyperf/hyperf/pull/1189) Fixed default operator does not works for `Hyperf\Utils\Collection::operatorForWhere`.
- [#1178](https://github.com/hyperf/hyperf/pull/1178) Fixed `Hyperf\Database\Query\Builder::chunkById` does not works when the collection item is array.
## Optimized
- [#1186](https://github.com/hyperf/hyperf/pull/1186) Automatically added default constructor's configuration, when you forgetton to set it.
# v1.1.11 - 2019-12-19
## Added

View File

@ -1175,6 +1175,7 @@ class Connection implements ConnectionInterface
/**
* Fire the given event if possible.
* @param mixed $event
*/
protected function event($event)
{

View File

@ -1934,7 +1934,8 @@ class Builder
return false;
}
$lastId = $results->last()->{$alias};
$lastResult = $results->last();
$lastId = is_array($lastResult) ? $lastResult[$alias] : $lastResult->{$alias};
unset($results);
} while ($countResults == $count);

View File

@ -2502,6 +2502,29 @@ class QueryBuilderTest extends TestCase
$this->assertTrue(true);
}
public function testChunkPaginatesUsingIdWithArray()
{
$builder = $this->getMockQueryBuilder();
$builder->orders[] = ['column' => 'foobar', 'direction' => 'asc'];
$chunk1 = collect([['someIdField' => 1], ['someIdField' => 2]]);
$chunk2 = collect([['someIdField' => 10]]);
$builder->shouldReceive('forPageAfterId')->once()->with(2, 0, 'someIdField')->andReturnSelf();
$builder->shouldReceive('forPageAfterId')->once()->with(2, 2, 'someIdField')->andReturnSelf();
$builder->shouldReceive('get')->times(2)->andReturn($chunk1, $chunk2);
$callbackAssertor = Mockery::mock(stdClass::class);
$callbackAssertor->shouldReceive('doSomething')->once()->with($chunk1);
$callbackAssertor->shouldReceive('doSomething')->once()->with($chunk2);
$builder->chunkById(2, function ($results) use ($callbackAssertor) {
$callbackAssertor->doSomething($results);
}, 'someIdField');
// Avoid 'This test did not perform any assertions' notice
$this->assertTrue(true);
}
public function testChunkPaginatesUsingIdWithLastChunkPartial()
{
$builder = $this->getMockQueryBuilder();

View File

@ -104,6 +104,11 @@ class LoggerFactory
foreach ($handlerConfigs as $value) {
$class = $value['class'] ?? $defaultHandlerConfig['class'];
$constructor = $value['constructor'] ?? $defaultHandlerConfig['constructor'];
if (isset($value['formatter'])) {
if (! isset($value['formatter']['constructor'])) {
$value['formatter']['constructor'] = $defaultFormatterConfig['constructor'];
}
}
$formatterConfig = $value['formatter'] ?? $defaultFormatterConfig;
$handlers[] = $this->handler($class, $constructor, $formatterConfig);

View File

@ -130,12 +130,18 @@ class LoggerFactoryTest extends TestCase
'stream' => BASE_PATH . '/runtime/logs/hyperf.log',
'level' => \Monolog\Logger::DEBUG,
],
'formatter' => [
'class' => \Monolog\Formatter\LineFormatter::class,
],
],
[
'class' => \Monolog\Handler\TestHandler::class,
'constructor' => [
'level' => \Monolog\Logger::DEBUG,
],
'formatter' => [
'class' => \Monolog\Formatter\LineFormatter::class,
],
],
],
'formatter' => [

View File

@ -1449,9 +1449,10 @@ class Collection implements ArrayAccess, Arrayable, Countable, IteratorAggregate
/**
* Get an operator checker callback.
* @param mixed|string $operator
* @param null|mixed $value
*/
protected function operatorForWhere(string $key, string $operator = null, $value = null): \Closure
protected function operatorForWhere(string $key, $operator = null, $value = null): \Closure
{
if (func_num_args() === 1) {
$value = true;

View File

@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://doc.hyperf.io
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace HyperfTest\Utils;
use Hyperf\Utils\Collection;
use PHPUnit\Framework\TestCase;
/**
* @internal
* @coversNothing
*/
class CollectionTest extends TestCase
{
public function testOperatorForWhere()
{
$col = new Collection([['id' => 1, 'name' => 'Hyperf'], ['id' => 2, 'name' => 'HyperfCloud']]);
$res = $col->where('id', 1);
$this->assertSame(1, $res->count());
$this->assertSame(['id' => 1, 'name' => 'Hyperf'], $res->shift());
$res = $col->where('id', '=', 2);
$this->assertSame(1, $res->count());
$this->assertSame(['id' => 2, 'name' => 'HyperfCloud'], $res->shift());
}
}