diff --git a/.travis.yml b/.travis.yml index 7fa09bd89..dd19dcc37 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/.travis/swoole.install.sh b/.travis/swoole.install.sh index 04bedf4aa..6a7e0a31e 100755 --- a/.travis/swoole.install.sh +++ b/.travis/swoole.install.sh @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 38bc6d0cb..629b6de85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/database/src/Connection.php b/src/database/src/Connection.php index 015de3810..74c99f547 100755 --- a/src/database/src/Connection.php +++ b/src/database/src/Connection.php @@ -1175,6 +1175,7 @@ class Connection implements ConnectionInterface /** * Fire the given event if possible. + * @param mixed $event */ protected function event($event) { diff --git a/src/database/src/Query/Builder.php b/src/database/src/Query/Builder.php index 3c99d1643..892bdebc8 100755 --- a/src/database/src/Query/Builder.php +++ b/src/database/src/Query/Builder.php @@ -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); diff --git a/src/database/tests/QueryBuilderTest.php b/src/database/tests/QueryBuilderTest.php index bc4f5d5bd..7b223c301 100644 --- a/src/database/tests/QueryBuilderTest.php +++ b/src/database/tests/QueryBuilderTest.php @@ -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(); diff --git a/src/logger/src/LoggerFactory.php b/src/logger/src/LoggerFactory.php index c51e97517..eb6978904 100644 --- a/src/logger/src/LoggerFactory.php +++ b/src/logger/src/LoggerFactory.php @@ -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); diff --git a/src/logger/tests/LoggerFactoryTest.php b/src/logger/tests/LoggerFactoryTest.php index 88ad572ff..d77db09e8 100644 --- a/src/logger/tests/LoggerFactoryTest.php +++ b/src/logger/tests/LoggerFactoryTest.php @@ -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' => [ diff --git a/src/utils/src/Collection.php b/src/utils/src/Collection.php index f0a3db1f3..c0e285112 100644 --- a/src/utils/src/Collection.php +++ b/src/utils/src/Collection.php @@ -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; diff --git a/src/utils/tests/CollectionTest.php b/src/utils/tests/CollectionTest.php new file mode 100644 index 000000000..52d327d74 --- /dev/null +++ b/src/utils/tests/CollectionTest.php @@ -0,0 +1,36 @@ + 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()); + } +}