From 95b85b7207c92d9ce757a6745a7912fb535562d9 Mon Sep 17 00:00:00 2001 From: agis Date: Thu, 17 Sep 2026 15:28:05 +0700 Subject: [PATCH 1/3] feat(database): add Builder::value() alongside pluck() (task 2.5a, additive) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First, non-breaking step of the pluck/lists pipeline. value($column) is a copy of today's scalar pluck() body on both Query\Builder and Eloquent\Builder — value() === pluck() for scalars right now. Purely additive: no call-site changes behavior, pluck() untouched. Unblocks app 2.5b (->pluck()->->value()) WITHOUT flipping pluck semantics, so the repos never flip in the same instant. Tests: value() returns the scalar and equals pluck() (Query + Eloquent). Database suite 516 green. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/Illuminate/Database/Eloquent/Builder.php | 13 ++++++++++++ src/Illuminate/Database/Query/Builder.php | 13 ++++++++++++ .../Database/DatabaseEloquentBuilderTest.php | 20 +++++++++++++++++++ tests/Database/DatabaseQueryBuilderTest.php | 13 ++++++++++++ 4 files changed, 59 insertions(+) diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index 8f99e8e3..b63f8d6e 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -175,6 +175,19 @@ public function pluck($column) if ($result) return $result->{$column}; } + /** + * Get a single column's value from the first result of a query. + * + * @param string $column + * @return mixed + */ + public function value($column) + { + $result = $this->first(array($column)); + + if ($result) return $result->{$column}; + } + /** * Chunk the results of the query. * diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index d9deeda9..f4b84a72 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -1360,6 +1360,19 @@ public function pluck($column) return count($result) > 0 ? reset($result) : null; } + /** + * Get a single column's value from the first result of a query. + * + * @param string $column + * @return mixed + */ + public function value($column) + { + $result = (array) $this->first(array($column)); + + return count($result) > 0 ? reset($result) : null; + } + /** * Execute the query and get the first result. * diff --git a/tests/Database/DatabaseEloquentBuilderTest.php b/tests/Database/DatabaseEloquentBuilderTest.php index e409c93b..505947d6 100755 --- a/tests/Database/DatabaseEloquentBuilderTest.php +++ b/tests/Database/DatabaseEloquentBuilderTest.php @@ -157,6 +157,26 @@ public function testPluckMethodWithModelNotFound() } + public function testValueMethodWithModelFound() + { + $builder = m::mock('Illuminate\Database\Eloquent\Builder[first]', [$this->getMockQueryBuilder()]); + $mockModel = new StdClass; + $mockModel->name = 'foo'; + $builder->shouldReceive('first')->with(['name'])->andReturn($mockModel); + + $this->assertEquals('foo', $builder->value('name')); + } + + + public function testValueMethodWithModelNotFound() + { + $builder = m::mock('Illuminate\Database\Eloquent\Builder[first]', [$this->getMockQueryBuilder()]); + $builder->shouldReceive('first')->with(['name'])->andReturn(null); + + $this->assertNull($builder->value('name')); + } + + public function testChunkExecuteCallbackOverPaginatedRequest() { $builder = m::mock('Illuminate\Database\Eloquent\Builder[forPage,get]', [$this->getMockQueryBuilder()]); diff --git a/tests/Database/DatabaseQueryBuilderTest.php b/tests/Database/DatabaseQueryBuilderTest.php index bf0db305..e6e4c0f8 100755 --- a/tests/Database/DatabaseQueryBuilderTest.php +++ b/tests/Database/DatabaseQueryBuilderTest.php @@ -884,6 +884,19 @@ public function testPluckMethodReturnsSingleColumn(): void } + public function testValueMethodReturnsSingleColumn(): void + { + $builder = $this->getBuilder(); + $builder->getConnection()->shouldReceive('select')->once()->with('select "foo" from "users" where "id" = ? limit 1', [1] + )->andReturn([['foo' => 'bar']]); + $builder->getProcessor()->shouldReceive('processSelect')->once()->with($builder, [['foo' => 'bar']])->andReturn( + [['foo' => 'bar']] + ); + $results = $builder->from('users')->where('id', '=', 1)->value('foo'); + $this->assertEquals('bar', $results); + } + + public function testAggregateFunctions(): void { $builder = $this->getBuilder(); From 8a6250e3a2b06814f5d7e94a8cecfd446a415768 Mon Sep 17 00:00:00 2001 From: agis Date: Thu, 17 Sep 2026 15:14:52 +0700 Subject: [PATCH 2/3] =?UTF-8?q?refactor(eloquent):=20rename=20SoftDeleting?= =?UTF-8?q?Trait=E2=86=92SoftDeletes,=20ScopeInterface=E2=86=92Scope,=20Mo?= =?UTF-8?q?del=20to=20L13=20contracts=20(task=202.5e)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Safe, type-caught slice of task 2.5 (Database). No alias — old FQCNs fatal so the app is forced to conform (task 2.5f, lockstep). - SoftDeletingTrait → SoftDeletes; boot hook bootSoftDeletingTrait() → bootSoftDeletes() (MUST match the new trait basename or Eloquent silently stops registering SoftDeletingScope → soft-deleted rows leak). Proven by DatabaseEloquentBuilderTest:486 (fails when the hook name is wrong). - ScopeInterface → Scope; SoftDeletingScope + Model typehints updated. - Model implements Illuminate\Contracts\Support\{Arrayable,Jsonable} (were Illuminate\Support\Contracts\{ArrayableInterface,JsonableInterface}); the 2 Model instanceof checks migrated to Arrayable. BC-safe: old contracts extend the new ones, so instanceof Arrayable is strictly wider. Does NOT touch lists()/pluck() — that dangerous semantic swap is the separate 2.5a–d pipeline. Fork suites green (Database 513, Support/Http/View 199). Co-Authored-By: Claude Opus 4.8 (1M context) --- src/Illuminate/Database/Eloquent/Model.php | 26 +++++++++---------- .../{ScopeInterface.php => Scope.php} | 2 +- ...{SoftDeletingTrait.php => SoftDeletes.php} | 4 +-- .../Database/Eloquent/SoftDeletingScope.php | 2 +- .../Database/DatabaseEloquentBuilderTest.php | 4 +-- .../DatabaseSoftDeletingTraitTest.php | 2 +- 6 files changed, 20 insertions(+), 20 deletions(-) rename src/Illuminate/Database/Eloquent/{ScopeInterface.php => Scope.php} (94%) rename src/Illuminate/Database/Eloquent/{SoftDeletingTrait.php => SoftDeletes.php} (97%) diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index 9f0cd701..f0cf2698 100755 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -15,8 +15,8 @@ use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\MorphTo; -use Illuminate\Support\Contracts\JsonableInterface; -use Illuminate\Support\Contracts\ArrayableInterface; +use Illuminate\Contracts\Support\Jsonable; +use Illuminate\Contracts\Support\Arrayable; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\Relations\MorphMany; @@ -27,7 +27,7 @@ use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Database\ConnectionResolverInterface as Resolver; -abstract class Model implements ArrayAccess, ArrayableInterface, JsonableInterface, JsonSerializable { +abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializable { /** * The connection name for the model. @@ -265,11 +265,11 @@ protected static function bootTraits(): void /** * Register a new global scope on the model. * - * @param ScopeInterface $scope + * @param Scope $scope * * @return void */ - public static function addGlobalScope(ScopeInterface $scope): void + public static function addGlobalScope(Scope $scope): void { static::$globalScopes[get_called_class()][get_class($scope)] = $scope; } @@ -277,7 +277,7 @@ public static function addGlobalScope(ScopeInterface $scope): void /** * Determine if a model has a global scope. * - * @param ScopeInterface $scope + * @param Scope $scope * * @return bool */ @@ -289,11 +289,11 @@ public static function hasGlobalScope($scope): bool /** * Get a global scope registered with the model. * - * @param ScopeInterface $scope + * @param Scope $scope * - * @return ScopeInterface|null + * @return Scope|null */ - public static function getGlobalScope($scope): ?ScopeInterface + public static function getGlobalScope($scope): ?Scope { return Arr::first(static::$globalScopes[get_called_class()], function($value, $key) use ($scope) { @@ -304,7 +304,7 @@ public static function getGlobalScope($scope): ?ScopeInterface /** * Get the global scopes for this class instance. * - * @return ScopeInterface[] + * @return Scope[] */ public function getGlobalScopes(): array { @@ -1740,7 +1740,7 @@ public function newQuery() /** * Get a new query instance without a given scope. * - * @param ScopeInterface $scope + * @param Scope $scope * * @return Builder */ @@ -2317,7 +2317,7 @@ public function relationsToArray():array // If the values implements the Arrayable interface we can just call this // toArray method on the instances which will convert both models and // collections to their proper array form and we'll set the values. - if ($value instanceof ArrayableInterface) + if ($value instanceof Arrayable) { $relation = $value->toArray(); } @@ -2515,7 +2515,7 @@ protected function mutateAttributeForArray($key, $value) { $value = $this->mutateAttribute($key, $value); - return $value instanceof ArrayableInterface ? $value->toArray() : $value; + return $value instanceof Arrayable ? $value->toArray() : $value; } /** diff --git a/src/Illuminate/Database/Eloquent/ScopeInterface.php b/src/Illuminate/Database/Eloquent/Scope.php similarity index 94% rename from src/Illuminate/Database/Eloquent/ScopeInterface.php rename to src/Illuminate/Database/Eloquent/Scope.php index b0a93a90..da1173af 100644 --- a/src/Illuminate/Database/Eloquent/ScopeInterface.php +++ b/src/Illuminate/Database/Eloquent/Scope.php @@ -1,6 +1,6 @@ Date: Thu, 17 Sep 2026 16:36:30 +0700 Subject: [PATCH 3/3] refactor(database): flip Builder::pluck() to list-returning, remove Builder::lists() (task 2.5d) Completes the fork side of the pluck/lists pipeline. Query\Builder and Eloquent\Builder pluck($column, $key = null) now return the list (old lists() body, an array); the scalar path lives in value() (added in 2.5a). lists() is removed from both builders. Internal callers rewired: Query\Builder::implode(), DatabaseMigrationRepository::getRan(), BelongsToMany (getRelatedIds/getCurrentIds) now use pluck(). Support\Collection::lists() kept (Collection callers convert in app 2.5c). Fork suite green: 1647 tests / 3659 assertions. Stacked on migration/2.5-fork-stack (= 4.2.95 + 2.5a value() + 2.5e SoftDeletes); this branch is what the app pins for task 2.5c. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/Illuminate/Database/Eloquent/Builder.php | 51 ++++++--------- .../Eloquent/Relations/BelongsToMany.php | 4 +- .../DatabaseMigrationRepository.php | 2 +- src/Illuminate/Database/Query/Builder.php | 63 ++++++++----------- .../DatabaseEloquentBelongsToManyTest.php | 12 ++-- .../Database/DatabaseEloquentBuilderTest.php | 30 ++------- .../DatabaseMigrationRepositoryTest.php | 2 +- tests/Database/DatabaseQueryBuilderTest.php | 19 +----- 8 files changed, 62 insertions(+), 121 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index b63f8d6e..a3c75ade 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -163,16 +163,30 @@ public function get($columns = array('*')) } /** - * Pluck a single column from the database. + * Get an array with the values of a given column. * * @param string $column - * @return mixed + * @param string $key + * @return array */ - public function pluck($column) + public function pluck($column, $key = null) { - $result = $this->first(array($column)); + $results = $this->query->pluck($column, $key); - if ($result) return $result->{$column}; + // If the model has a mutator for the requested column, we will spin through + // the results and mutate the values so that the mutated version of these + // columns are returned as you would expect from these Eloquent models. + if ($this->model->hasGetMutator($column)) + { + foreach ($results as $key => &$value) + { + $fill = array($column => $value); + + $value = $this->model->newFromBuilder($fill)->$column; + } + } + + return $results; } /** @@ -212,33 +226,6 @@ public function chunk($count, callable $callback) } } - /** - * Get an array with the values of a given column. - * - * @param string $column - * @param string $key - * @return array - */ - public function lists($column, $key = null) - { - $results = $this->query->lists($column, $key); - - // If the model has a mutator for the requested column, we will spin through - // the results and mutate the values so that the mutated version of these - // columns are returned as you would expect from these Eloquent models. - if ($this->model->hasGetMutator($column)) - { - foreach ($results as $key => &$value) - { - $fill = array($column => $value); - - $value = $this->model->newFromBuilder($fill)->$column; - } - } - - return $results; - } - /** * Get a paginator for the "select" statement. * diff --git a/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php b/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php index 1b66d6ba..df1a2d2c 100755 --- a/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php +++ b/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php @@ -496,7 +496,7 @@ public function getRelatedIds() $fullKey = $related->getQualifiedKeyName(); - return $this->getQuery()->select($fullKey)->lists($related->getKeyName()); + return $this->getQuery()->select($fullKey)->pluck($related->getKeyName()); } /** @@ -596,7 +596,7 @@ public function sync($ids, $detaching = true) // First we need to attach any of the associated models that are not currently // in this joining table. We'll spin through the given IDs, checking to see // if they exist in the array of current ones, and if not we will insert. - $current = $this->newPivotQuery()->lists($this->otherKey); + $current = $this->newPivotQuery()->pluck($this->otherKey); $records = $this->formatSyncList($ids); diff --git a/src/Illuminate/Database/Migrations/DatabaseMigrationRepository.php b/src/Illuminate/Database/Migrations/DatabaseMigrationRepository.php index 88947100..39e8261f 100755 --- a/src/Illuminate/Database/Migrations/DatabaseMigrationRepository.php +++ b/src/Illuminate/Database/Migrations/DatabaseMigrationRepository.php @@ -45,7 +45,7 @@ public function __construct(Resolver $resolver, $table) */ public function getRan() { - return $this->table()->lists('migration'); + return $this->table()->pluck('migration'); } /** diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index f4b84a72..2bb7b8b3 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -1348,16 +1348,34 @@ public function find($id, $columns = array('*')) } /** - * Pluck a single column's value from the first result of a query. + * Get an array with the values of a given column. * * @param string $column - * @return mixed + * @param string $key + * @return array */ - public function pluck($column) + public function pluck($column, $key = null) { - $result = (array) $this->first(array($column)); + $columns = $this->getListSelect($column, $key); - return count($result) > 0 ? reset($result) : null; + // First we will just get all of the column values for the record result set + // then we can associate those values with the column if it was specified + // otherwise we can just give these values back without a specific key. + $results = new Collection($this->get($columns)); + + $values = $results->fetch($columns[0])->all(); + + // If a key was specified and we have results, we will go ahead and combine + // the values with the keys of all of the records so that the values can + // be accessed by the key of the rows instead of simply being numeric. + if ( ! is_null($key) && count($results) > 0) + { + $keys = $results->fetch($key)->all(); + + return array_combine($keys, $values); + } + + return $values; } /** @@ -1629,37 +1647,6 @@ private function defaultKeyName(): string return 'id'; } - /** - * Get an array with the values of a given column. - * - * @param string $column - * @param string $key - * @return array - */ - public function lists($column, $key = null) - { - $columns = $this->getListSelect($column, $key); - - // First we will just get all of the column values for the record result set - // then we can associate those values with the column if it was specified - // otherwise we can just give these values back without a specific key. - $results = new Collection($this->get($columns)); - - $values = $results->fetch($columns[0])->all(); - - // If a key was specified and we have results, we will go ahead and combine - // the values with the keys of all of the records so that the values can - // be accessed by the key of the rows instead of simply being numeric. - if ( ! is_null($key) && count($results) > 0) - { - $keys = $results->fetch($key)->all(); - - return array_combine($keys, $values); - } - - return $values; - } - /** * Get the columns that should be used in a list array. * @@ -1691,9 +1678,9 @@ protected function getListSelect($column, $key) */ public function implode($column, $glue = null) { - if (is_null($glue)) return implode($this->lists($column)); + if (is_null($glue)) return implode($this->pluck($column)); - return implode($glue, $this->lists($column)); + return implode($glue, $this->pluck($column)); } /** diff --git a/tests/Database/DatabaseEloquentBelongsToManyTest.php b/tests/Database/DatabaseEloquentBelongsToManyTest.php index 62220d51..cd0183a9 100755 --- a/tests/Database/DatabaseEloquentBelongsToManyTest.php +++ b/tests/Database/DatabaseEloquentBelongsToManyTest.php @@ -303,7 +303,7 @@ public function testSyncMethodSyncsIntermediateTableWithGivenArray($list) $query->shouldReceive('where')->once()->with('user_id', 1)->andReturn($query); $relation->getQuery()->shouldReceive('getQuery')->andReturn($mockQueryBuilder = m::mock('StdClass')); $mockQueryBuilder->shouldReceive('newQuery')->once()->andReturn($query); - $query->shouldReceive('lists')->once()->with('role_id')->andReturn([1, 2, 3]); + $query->shouldReceive('pluck')->once()->with('role_id')->andReturn([1, 2, 3]); $relation->expects($this->once())->method('attach')->with($this->equalTo(4), $this->equalTo([]), $this->equalTo(false)); $relation->expects($this->once())->method('detach')->with($this->equalTo([1])); $relation->getRelated()->shouldReceive('touches')->andReturn(false); @@ -330,7 +330,7 @@ public function testSyncMethodSyncsIntermediateTableWithGivenArrayAndAttributes( $query->shouldReceive('where')->once()->with('user_id', 1)->andReturn($query); $relation->getQuery()->shouldReceive('getQuery')->andReturn($mockQueryBuilder = m::mock('StdClass')); $mockQueryBuilder->shouldReceive('newQuery')->once()->andReturn($query); - $query->shouldReceive('lists')->once()->with('role_id')->andReturn([1, 2, 3]); + $query->shouldReceive('pluck')->once()->with('role_id')->andReturn([1, 2, 3]); $relation->expects($this->once())->method('attach')->with($this->equalTo(4), $this->equalTo(['foo' => 'bar']), $this->equalTo(false)); $relation->expects($this->once())->method('updateExistingPivot')->with($this->equalTo(3), $this->equalTo( ['baz' => 'qux'] @@ -355,7 +355,7 @@ public function testSyncMethodDoesntReturnValuesThatWereNotUpdated() $query->shouldReceive('where')->once()->with('user_id', 1)->andReturn($query); $relation->getQuery()->shouldReceive('getQuery')->andReturn($mockQueryBuilder = m::mock('StdClass')); $mockQueryBuilder->shouldReceive('newQuery')->once()->andReturn($query); - $query->shouldReceive('lists')->once()->with('role_id')->andReturn([1, 2, 3]); + $query->shouldReceive('pluck')->once()->with('role_id')->andReturn([1, 2, 3]); $relation->expects($this->once())->method('attach')->with($this->equalTo(4), $this->equalTo(['foo' => 'bar']), $this->equalTo(false)); $relation->expects($this->once())->method('updateExistingPivot')->with($this->equalTo(3), $this->equalTo( ['baz' => 'qux'] @@ -380,7 +380,7 @@ public function testTouchMethodSyncsTimestamps() $relation->getRelated()->shouldReceive('freshTimestamp')->andReturn($carbon); $relation->getRelated()->shouldReceive('getQualifiedKeyName')->andReturn('table.id'); $relation->getQuery()->shouldReceive('select')->once()->with('table.id')->andReturn($relation->getQuery()); - $relation->getQuery()->shouldReceive('lists')->once()->with('id')->andReturn([1, 2, 3]); + $relation->getQuery()->shouldReceive('pluck')->once()->with('id')->andReturn([1, 2, 3]); $relation->getRelated()->shouldReceive('newQuery')->once()->andReturn($query = m::mock(Builder::class)); $query->shouldReceive('whereIn')->once()->with('id', [1, 2, 3])->andReturn($query); $query->shouldReceive('update')->once()->with(['updated_at' => $carbon]); @@ -409,7 +409,7 @@ public function testSyncMethodConvertsCollectionToArrayOfKeys() $query->shouldReceive('where')->once()->with('user_id', 1)->andReturn($query); $relation->getQuery()->shouldReceive('getQuery')->andReturn($mockQueryBuilder = m::mock('StdClass')); $mockQueryBuilder->shouldReceive('newQuery')->once()->andReturn($query); - $query->shouldReceive('lists')->once()->with('role_id')->andReturn([1, 2, 3]); + $query->shouldReceive('pluck')->once()->with('role_id')->andReturn([1, 2, 3]); $collection = m::mock(Collection::class); $collection->shouldReceive('modelKeys')->once()->andReturn([1, 2, 3]); @@ -443,7 +443,7 @@ public function testWherePivotParamsUsedForNewQueries() $query->shouldReceive('where')->once()->with('foo', '=', 'bar')->andReturn($query); // This is so $relation->sync() works - $query->shouldReceive('lists')->once()->with('role_id')->andReturn([1, 2, 3]); + $query->shouldReceive('pluck')->once()->with('role_id')->andReturn([1, 2, 3]); $relation->expects($this->once())->method('formatSyncList')->with([1, 2, 3])->willReturn( [1 => [], 2 => [], 3 => []] ); diff --git a/tests/Database/DatabaseEloquentBuilderTest.php b/tests/Database/DatabaseEloquentBuilderTest.php index ab0223e2..1dfec3f2 100755 --- a/tests/Database/DatabaseEloquentBuilderTest.php +++ b/tests/Database/DatabaseEloquentBuilderTest.php @@ -137,27 +137,7 @@ public function testGetMethodDoesntHydrateEagerRelationsWhenNoResultsAreReturned } - public function testPluckMethodWithModelFound() - { - $builder = m::mock('Illuminate\Database\Eloquent\Builder[first]', [$this->getMockQueryBuilder()]); - $mockModel = new StdClass; - $mockModel->name = 'foo'; - $builder->shouldReceive('first')->with(['name'])->andReturn($mockModel); - - $this->assertEquals('foo', $builder->pluck('name')); - } - - - public function testPluckMethodWithModelNotFound() - { - $builder = m::mock('Illuminate\Database\Eloquent\Builder[first]', [$this->getMockQueryBuilder()]); - $builder->shouldReceive('first')->with(['name'])->andReturn(null); - - $this->assertNull($builder->pluck('name')); - } - - - public function testValueMethodWithModelFound() +public function testValueMethodWithModelFound() { $builder = m::mock('Illuminate\Database\Eloquent\Builder[first]', [$this->getMockQueryBuilder()]); $mockModel = new StdClass; @@ -201,7 +181,7 @@ public function testChunkExecuteCallbackOverPaginatedRequest() public function testListsReturnsTheMutatedAttributesOfAModel() { $builder = $this->getBuilder(); - $builder->getQuery()->shouldReceive('lists')->with('name', '')->andReturn(['bar', 'baz']); + $builder->getQuery()->shouldReceive('pluck')->with('name', '')->andReturn(['bar', 'baz']); $builder->setModel($this->getMockModel()); $builder->getModel()->shouldReceive('hasGetMutator')->with('name')->andReturn(true); $builder->getModel()->shouldReceive('newFromBuilder')->with(['name' => 'bar'])->andReturn(new EloquentBuilderTestListsStub( @@ -211,18 +191,18 @@ public function testListsReturnsTheMutatedAttributesOfAModel() ['name' => 'baz'] )); - $this->assertEquals(['foo_bar', 'foo_baz'], $builder->lists('name')); + $this->assertEquals(['foo_bar', 'foo_baz'], $builder->pluck('name')); } public function testListsWithoutModelGetterJustReturnTheAttributesFoundInDatabase() { $builder = $this->getBuilder(); - $builder->getQuery()->shouldReceive('lists')->with('name', '')->andReturn(['bar', 'baz']); + $builder->getQuery()->shouldReceive('pluck')->with('name', '')->andReturn(['bar', 'baz']); $builder->setModel($this->getMockModel()); $builder->getModel()->shouldReceive('hasGetMutator')->with('name')->andReturn(false); - $this->assertEquals(['bar', 'baz'], $builder->lists('name')); + $this->assertEquals(['bar', 'baz'], $builder->pluck('name')); } diff --git a/tests/Database/DatabaseMigrationRepositoryTest.php b/tests/Database/DatabaseMigrationRepositoryTest.php index eaed40d4..7f289c7e 100755 --- a/tests/Database/DatabaseMigrationRepositoryTest.php +++ b/tests/Database/DatabaseMigrationRepositoryTest.php @@ -22,7 +22,7 @@ public function testGetRanMigrationsListMigrationsByPackage() $connectionMock = m::mock(Connection::class); $repo->getConnectionResolver()->shouldReceive('connection')->with(null)->andReturn($connectionMock); $repo->getConnection()->shouldReceive('table')->once()->with('migrations')->andReturn($query); - $query->shouldReceive('lists')->once()->with('migration')->andReturn('bar'); + $query->shouldReceive('pluck')->once()->with('migration')->andReturn('bar'); $this->assertEquals('bar', $repo->getRan()); } diff --git a/tests/Database/DatabaseQueryBuilderTest.php b/tests/Database/DatabaseQueryBuilderTest.php index e6e4c0f8..ffc73c47 100755 --- a/tests/Database/DatabaseQueryBuilderTest.php +++ b/tests/Database/DatabaseQueryBuilderTest.php @@ -750,7 +750,7 @@ public function testListMethodsGetsArrayOfColumnValues(): void { return $results; }); - $results = $builder->from('users')->where('id', '=', 1)->lists('foo'); + $results = $builder->from('users')->where('id', '=', 1)->pluck('foo'); $this->assertEquals(['bar', 'baz'], $results); $builder = $this->getBuilder(); @@ -762,7 +762,7 @@ public function testListMethodsGetsArrayOfColumnValues(): void { return $results; }); - $results = $builder->from('users')->where('id', '=', 1)->lists('foo', 'id'); + $results = $builder->from('users')->where('id', '=', 1)->pluck('foo', 'id'); $this->assertEquals([1 => 'bar', 10 => 'baz'], $results); } @@ -871,20 +871,7 @@ public function testQuickPaginateCorrectlyCreatesPaginatorInstance(): void } - public function testPluckMethodReturnsSingleColumn(): void - { - $builder = $this->getBuilder(); - $builder->getConnection()->shouldReceive('select')->once()->with('select "foo" from "users" where "id" = ? limit 1', [1] - )->andReturn([['foo' => 'bar']]); - $builder->getProcessor()->shouldReceive('processSelect')->once()->with($builder, [['foo' => 'bar']])->andReturn( - [['foo' => 'bar']] - ); - $results = $builder->from('users')->where('id', '=', 1)->pluck('foo'); - $this->assertEquals('bar', $results); - } - - - public function testValueMethodReturnsSingleColumn(): void +public function testValueMethodReturnsSingleColumn(): void { $builder = $this->getBuilder(); $builder->getConnection()->shouldReceive('select')->once()->with('select "foo" from "users" where "id" = ? limit 1', [1]