Skip to content

Commit

Permalink
Allow Storage::put to accept a Psr StreamInterface
Browse files Browse the repository at this point in the history
Remove brackets arround URL php artisan serve (laravel#30168)

To allow opening the development URL in Visual Studio Code with ctrl + click the bracket after the URL needs to be removed.
This patch wil remove the brackets around the url.

add test for sorted middlewares (laravel#30166)

[6.x] Apply limit to database rather than collection (laravel#30148)

* Apply limit to database rather than collection

For HasInDatabase.php

* Fix tests

* Add to SoftDeleted trait as well

* Update HasInDatabase.php

* Update SoftDeletedInDatabase.php

[6.x] Allow to use scoped macro in nested queries (laravel#30127)

* Allow to use scoped macro in nested queries.

* Use newQueryWithoutRelationships
  • Loading branch information
Gman98ish committed Oct 4, 2019
1 parent e20374b commit afd7587
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 14 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"opis/closure": "^3.1",
"psr/container": "^1.0",
"psr/simple-cache": "^1.0",
"psr/http-message": "^1.0",
"ramsey/uuid": "^3.7",
"swiftmailer/swiftmailer": "^6.0",
"symfony/console": "^4.3.4",
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public function whereKeyNot($id)
public function where($column, $operator = null, $value = null, $boolean = 'and')
{
if ($column instanceof Closure) {
$column($query = $this->model->newModelQuery());
$column($query = $this->model->newQueryWithoutRelationships());

$this->query->addNestedWhereQuery($query->getQuery(), $boolean);
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/Illuminate/Filesystem/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use League\Flysystem\FileNotFoundException;
use League\Flysystem\FilesystemInterface;
use PHPUnit\Framework\Assert as PHPUnit;
use Psr\Http\Message\StreamInterface;
use RuntimeException;
use Symfony\Component\HttpFoundation\StreamedResponse;

Expand Down Expand Up @@ -203,6 +204,10 @@ public function put($path, $contents, $options = [])
return $this->putFile($path, $contents, $options);
}

if ($contents instanceof StreamInterface) {
return $this->driver->putStream($path, $contents->detach(), $options);
}

return is_resource($contents)
? $this->driver->putStream($path, $contents, $options)
: $this->driver->put($path, $contents, $options);
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Console/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function handle()
{
chdir(public_path());

$this->line("<info>Laravel development server started:</info> <http://{$this->host()}:{$this->port()}>");
$this->line("<info>Laravel development server started:</info> http://{$this->host()}:{$this->port()}");

passthru($this->serverCommand(), $status);

Expand Down
10 changes: 6 additions & 4 deletions src/Illuminate/Foundation/Testing/Constraints/HasInDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,18 @@ public function failureDescription($table): string
*/
protected function getAdditionalInfo($table)
{
$results = $this->database->table($table)->get();
$query = $this->database->table($table);

$results = $query->limit($this->show)->get();

if ($results->isEmpty()) {
return 'The table is empty';
}

$description = 'Found: '.json_encode($results->take($this->show), JSON_PRETTY_PRINT);
$description = 'Found: '.json_encode($results, JSON_PRETTY_PRINT);

if ($results->count() > $this->show) {
$description .= sprintf(' and %s others', $results->count() - $this->show);
if ($query->count() > $this->show) {
$description .= sprintf(' and %s others', $query->count() - $this->show);
}

return $description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,18 @@ public function failureDescription($table): string
*/
protected function getAdditionalInfo($table)
{
$results = $this->database->table($table)->get();
$query = $this->database->table($table);

$results = $query->limit($this->show)->get();

if ($results->isEmpty()) {
return 'The table is empty';
}

$description = 'Found: '.json_encode($results->take($this->show), JSON_PRETTY_PRINT);
$description = 'Found: '.json_encode($results, JSON_PRETTY_PRINT);

if ($results->count() > $this->show) {
$description .= sprintf(' and %s others', $results->count() - $this->show);
if ($query->count() > $this->show) {
$description .= sprintf(' and %s others', $query->count() - $this->show);
}

return $description;
Expand Down
13 changes: 12 additions & 1 deletion tests/Database/DatabaseEloquentBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ public function testNestedWhere()
$nestedRawQuery = $this->getMockQueryBuilder();
$nestedQuery->shouldReceive('getQuery')->once()->andReturn($nestedRawQuery);
$model = $this->getMockModel()->makePartial();
$model->shouldReceive('newModelQuery')->once()->andReturn($nestedQuery);
$model->shouldReceive('newQueryWithoutRelationships')->once()->andReturn($nestedQuery);
$builder = $this->getBuilder();
$builder->getQuery()->shouldReceive('from');
$builder->setModel($model);
Expand All @@ -667,6 +667,17 @@ public function testRealNestedWhereWithScopes()
$this->assertEquals(['bar', 9000], $query->getBindings());
}

public function testRealNestedWhereWithScopesMacro()
{
$model = new EloquentBuilderTestNestedStub;
$this->mockConnectionForModel($model, 'SQLite');
$query = $model->newQuery()->where('foo', '=', 'bar')->where(function ($query) {
$query->where('baz', '>', 9000)->onlyTrashed();
})->withTrashed();
$this->assertSame('select * from "table" where "foo" = ? and ("baz" > ? and "table"."deleted_at" is not null)', $query->toSql());
$this->assertEquals(['bar', 9000], $query->getBindings());
}

public function testRealNestedWhereWithMultipleScopesAndOneDeadScope()
{
$model = new EloquentBuilderTestNestedStub;
Expand Down
17 changes: 17 additions & 0 deletions tests/Filesystem/FilesystemAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

namespace Illuminate\Tests\Filesystem;

use GuzzleHttp\Psr7\Stream;
use Illuminate\Contracts\Filesystem\FileExistsException;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Filesystem\FilesystemAdapter;
use InvalidArgumentException;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\StreamInterface;
use Symfony\Component\HttpFoundation\StreamedResponse;

class FilesystemAdapterTest extends TestCase
Expand All @@ -26,6 +29,7 @@ protected function tearDown(): void
{
$filesystem = new Filesystem(new Local(dirname($this->tempDir)));
$filesystem->deleteDir(basename($this->tempDir));
m::close();
}

public function testResponse()
Expand Down Expand Up @@ -218,4 +222,17 @@ public function testStreamInvalidResourceThrows()
$filesystemAdapter = new FilesystemAdapter($this->filesystem);
$filesystemAdapter->writeStream('file.txt', 'foo bar');
}

public function testPutWithStreamInterface()
{
file_put_contents($this->tempDir.'/foo.txt', 'some-data');
$spy = m::spy($this->filesystem);

$filesystemAdapter = new FilesystemAdapter($spy);
$stream = new Stream(fopen($this->tempDir.'/foo.txt', 'r'));
$filesystemAdapter->put('bar.txt', $stream);

$spy->shouldHaveReceived('putStream');
$this->assertEquals('some-data', $filesystemAdapter->get('bar.txt'));
}
}
7 changes: 5 additions & 2 deletions tests/Foundation/FoundationInteractsWithDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ public function testSeeInDatabaseFindsManyNotMatchingResults()
$this->expectExceptionMessage('Found: '.json_encode(['data', 'data', 'data'], JSON_PRETTY_PRINT).' and 2 others.');

$builder = $this->mockCountBuilder(0);
$builder->shouldReceive('count')->andReturn(0, 5);

$builder->shouldReceive('take')->andReturnSelf();
$builder->shouldReceive('get')->andReturn(
collect(array_fill(0, 5, 'data'))
collect(array_fill(0, 3, 'data'))
);

$this->assertDatabaseHas($this->table, $this->data);
Expand Down Expand Up @@ -150,11 +151,13 @@ protected function mockCountBuilder($countResult, $deletedAtColumn = 'deleted_at
{
$builder = m::mock(Builder::class);

$builder->shouldReceive('limit')->andReturnSelf();

$builder->shouldReceive('where')->with($this->data)->andReturnSelf();

$builder->shouldReceive('whereNotNull')->with($deletedAtColumn)->andReturnSelf();

$builder->shouldReceive('count')->andReturn($countResult);
$builder->shouldReceive('count')->andReturn($countResult)->byDefault();

$this->connection->shouldReceive('table')
->with($this->table)
Expand Down
16 changes: 15 additions & 1 deletion tests/Routing/RoutingSortedMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,24 @@ public function testMiddlewareCanBeSortedByPriority()
$this->assertEquals([], (new SortedMiddleware(['First'], []))->all());
$this->assertEquals(['First'], (new SortedMiddleware(['First'], ['First']))->all());
$this->assertEquals(['First', 'Second'], (new SortedMiddleware(['First', 'Second'], ['Second', 'First']))->all());
}

public function testItDoesNotMoveNonStringValues()
{
$closure = function () {
//
return 'foo';
};

$closure2 = function () {
return 'bar';
};

$this->assertEquals([2, 1], (new SortedMiddleware([1, 2], [2, 1]))->all());
$this->assertEquals(['Second', $closure], (new SortedMiddleware(['First', 'Second'], ['Second', $closure]))->all());
$this->assertEquals(['a', 'b', $closure], (new SortedMiddleware(['a', 'b'], ['b', $closure, 'a']))->all());
$this->assertEquals([$closure2, 'a', 'b', $closure, 'foo'], (new SortedMiddleware(['a', 'b'], [$closure2, 'b', $closure, 'a', 'foo']))->all());
$this->assertEquals([$closure, 'a', 'b', $closure2, 'foo'], (new SortedMiddleware(['a', 'b'], [$closure, 'b', $closure2, 'foo', 'a']))->all());
$this->assertEquals(['a', $closure, 'b', $closure2, 'foo'], (new SortedMiddleware(['a', 'b'], ['a', $closure, 'b', $closure2, 'foo']))->all());
$this->assertEquals([$closure, $closure2, 'foo', 'a'], (new SortedMiddleware(['a', 'b'], [$closure, $closure2, 'foo', 'a']))->all());
}
}

0 comments on commit afd7587

Please sign in to comment.