language stringclasses 1
value | owner stringlengths 2 15 | repo stringlengths 2 21 | sha stringlengths 45 45 | message stringlengths 7 36.3k | path stringlengths 1 199 | patch stringlengths 15 102k | is_multipart bool 2
classes |
|---|---|---|---|---|---|---|---|
Other | laravel | framework | ef2dc2e7ccbcb3d074e81c552e35df36a6fc25e6.json | Fix MorphTo lazy eager loading (#25240) | tests/Database/DatabaseEloquentBuilderTest.php | @@ -460,7 +460,7 @@ public function testGetRelationProperlySetsNestedRelationships()
{
$builder = $this->getBuilder();
$builder->setModel($this->getMockModel());
- $builder->getModel()->shouldReceive('orders')->once()->andReturn($relation = m::mock('stdClass'));
+ $builder->getModel()->shouldReceive('newInstance->orders')->once()->andReturn($relation = m::mock('stdClass'));
$relationQuery = m::mock('stdClass');
$relation->shouldReceive('getQuery')->andReturn($relationQuery);
$relationQuery->shouldReceive('with')->once()->with(['lines' => null, 'lines.details' => null]);
@@ -473,8 +473,8 @@ public function testGetRelationProperlySetsNestedRelationshipsWithSimilarNames()
{
$builder = $this->getBuilder();
$builder->setModel($this->getMockModel());
- $builder->getModel()->shouldReceive('orders')->once()->andReturn($relation = m::mock('stdClass'));
- $builder->getModel()->shouldReceive('ordersGroups')->once()->andReturn($groupsRelation = m::mock('stdClass'));
+ $builder->getModel()->shouldReceive('newInstance->orders')->once()->andReturn($relation = m::mock('stdClass'));
+ $builder->getModel()->shouldReceive('newInstance->ordersGroups')->once()->andReturn($groupsRelation = m::mock('stdClass'));
$relationQuery = m::mock('stdClass');
$relation->shouldReceive('getQuery')->andReturn($relationQuery); | true |
Other | laravel | framework | ef2dc2e7ccbcb3d074e81c552e35df36a6fc25e6.json | Fix MorphTo lazy eager loading (#25240) | tests/Integration/Database/EloquentMorphToLazyEagerLoadingTest.php | @@ -0,0 +1,94 @@
+<?php
+
+namespace Illuminate\Tests\Integration\Database\EloquentMorphToLazyEagerLoadingTest;
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Tests\Integration\Database\DatabaseTestCase;
+
+/**
+ * @group integration
+ */
+class EloquentMorphToLazyEagerLoadingTest extends DatabaseTestCase
+{
+ public function setUp()
+ {
+ parent::setUp();
+
+ Schema::create('users', function (Blueprint $table) {
+ $table->increments('id');
+ });
+
+ Schema::create('posts', function (Blueprint $table) {
+ $table->increments('post_id');
+ $table->unsignedInteger('user_id');
+ });
+
+ Schema::create('videos', function (Blueprint $table) {
+ $table->increments('video_id');
+ });
+
+ Schema::create('comments', function (Blueprint $table) {
+ $table->increments('id');
+ $table->string('commentable_type');
+ $table->integer('commentable_id');
+ });
+
+ $user = User::create();
+
+ $post = tap((new Post)->user()->associate($user))->save();
+
+ $video = Video::create();
+
+ (new Comment)->commentable()->associate($post)->save();
+ (new Comment)->commentable()->associate($video)->save();
+ }
+
+ public function test_lazy_eager_loading()
+ {
+ $comments = Comment::all();
+
+ \DB::enableQueryLog();
+
+ $comments->load('commentable');
+
+ $this->assertCount(3, \DB::getQueryLog());
+ $this->assertTrue($comments[0]->relationLoaded('commentable'));
+ $this->assertTrue($comments[0]->commentable->relationLoaded('user'));
+ $this->assertTrue($comments[1]->relationLoaded('commentable'));
+ }
+}
+
+class Comment extends Model
+{
+ public $timestamps = false;
+
+ public function commentable()
+ {
+ return $this->morphTo();
+ }
+}
+
+class Post extends Model
+{
+ public $timestamps = false;
+ protected $primaryKey = 'post_id';
+ protected $with = ['user'];
+
+ public function user()
+ {
+ return $this->belongsTo(User::class);
+ }
+}
+
+class User extends Model
+{
+ public $timestamps = false;
+}
+
+class Video extends Model
+{
+ public $timestamps = false;
+ protected $primaryKey = 'video_id';
+} | true |
Other | laravel | framework | 7bfbac7d22926612cce18bd3aac1376f24704320.json | Fix URL validation pattern (#25197) | src/Illuminate/Validation/Concerns/ValidatesAttributes.php | @@ -1360,7 +1360,7 @@ public function validateUrl($attribute, $value)
((aaa|aaas|about|acap|acct|acr|adiumxtra|afp|afs|aim|apt|attachment|aw|barion|beshare|bitcoin|blob|bolo|callto|cap|chrome|chrome-extension|cid|coap|coaps|com-eventbrite-attendee|content|crid|cvs|data|dav|dict|dlna-playcontainer|dlna-playsingle|dns|dntp|dtn|dvb|ed2k|example|facetime|fax|feed|feedready|file|filesystem|finger|fish|ftp|geo|gg|git|gizmoproject|go|gopher|gtalk|h323|ham|hcp|http|https|iax|icap|icon|im|imap|info|iotdisco|ipn|ipp|ipps|irc|irc6|ircs|iris|iris.beep|iris.lwz|iris.xpc|iris.xpcs|itms|jabber|jar|jms|keyparc|lastfm|ldap|ldaps|magnet|mailserver|mailto|maps|market|message|mid|mms|modem|ms-help|ms-settings|ms-settings-airplanemode|ms-settings-bluetooth|ms-settings-camera|ms-settings-cellular|ms-settings-cloudstorage|ms-settings-emailandaccounts|ms-settings-language|ms-settings-location|ms-settings-lock|ms-settings-nfctransactions|ms-settings-notifications|ms-settings-power|ms-settings-privacy|ms-settings-proximity|ms-settings-screenrotation|ms-settings-wifi|ms-settings-workplace|msnim|msrp|msrps|mtqp|mumble|mupdate|mvn|news|nfs|ni|nih|nntp|notes|oid|opaquelocktoken|pack|palm|paparazzi|pkcs11|platform|pop|pres|prospero|proxy|psyc|query|redis|rediss|reload|res|resource|rmi|rsync|rtmfp|rtmp|rtsp|rtsps|rtspu|secondlife|s3|service|session|sftp|sgn|shttp|sieve|sip|sips|skype|smb|sms|smtp|snews|snmp|soap.beep|soap.beeps|soldat|spotify|ssh|steam|stun|stuns|submit|svn|tag|teamspeak|tel|teliaeid|telnet|tftp|things|thismessage|tip|tn3270|turn|turns|tv|udp|unreal|urn|ut2004|vemmi|ventrilo|videotex|view-source|wais|webcal|ws|wss|wtai|wyciwyg|xcon|xcon-userid|xfire|xmlrpc\.beep|xmlrpc.beeps|xmpp|xri|ymsgr|z39\.50|z39\.50r|z39\.50s)):// # protocol
(([\pL\pN-]+:)?([\pL\pN-]+)@)? # basic auth
(
- ([\pL\pN\pS-\.])+(\.?([\pL]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
+ ([\pL\pN\pS\-\.])+(\.?([\pL]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
| # or
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} # an IP address
| # or | false |
Other | laravel | framework | 2d551a849184ed55655f52559beed7ac26706bb7.json | Fix URL validation pattern (#25194) | src/Illuminate/Validation/Concerns/ValidatesAttributes.php | @@ -1528,7 +1528,7 @@ public function validateUrl($attribute, $value)
((aaa|aaas|about|acap|acct|acr|adiumxtra|afp|afs|aim|apt|attachment|aw|barion|beshare|bitcoin|blob|bolo|callto|cap|chrome|chrome-extension|cid|coap|coaps|com-eventbrite-attendee|content|crid|cvs|data|dav|dict|dlna-playcontainer|dlna-playsingle|dns|dntp|dtn|dvb|ed2k|example|facetime|fax|feed|feedready|file|filesystem|finger|fish|ftp|geo|gg|git|gizmoproject|go|gopher|gtalk|h323|ham|hcp|http|https|iax|icap|icon|im|imap|info|iotdisco|ipn|ipp|ipps|irc|irc6|ircs|iris|iris.beep|iris.lwz|iris.xpc|iris.xpcs|itms|jabber|jar|jms|keyparc|lastfm|ldap|ldaps|magnet|mailserver|mailto|maps|market|message|mid|mms|modem|ms-help|ms-settings|ms-settings-airplanemode|ms-settings-bluetooth|ms-settings-camera|ms-settings-cellular|ms-settings-cloudstorage|ms-settings-emailandaccounts|ms-settings-language|ms-settings-location|ms-settings-lock|ms-settings-nfctransactions|ms-settings-notifications|ms-settings-power|ms-settings-privacy|ms-settings-proximity|ms-settings-screenrotation|ms-settings-wifi|ms-settings-workplace|msnim|msrp|msrps|mtqp|mumble|mupdate|mvn|news|nfs|ni|nih|nntp|notes|oid|opaquelocktoken|pack|palm|paparazzi|pkcs11|platform|pop|pres|prospero|proxy|psyc|query|redis|rediss|reload|res|resource|rmi|rsync|rtmfp|rtmp|rtsp|rtsps|rtspu|secondlife|s3|service|session|sftp|sgn|shttp|sieve|sip|sips|skype|smb|sms|smtp|snews|snmp|soap.beep|soap.beeps|soldat|spotify|ssh|steam|stun|stuns|submit|svn|tag|teamspeak|tel|teliaeid|telnet|tftp|things|thismessage|tip|tn3270|turn|turns|tv|udp|unreal|urn|ut2004|vemmi|ventrilo|videotex|view-source|wais|webcal|ws|wss|wtai|wyciwyg|xcon|xcon-userid|xfire|xmlrpc\.beep|xmlrpc.beeps|xmpp|xri|ymsgr|z39\.50|z39\.50r|z39\.50s)):// # protocol
(([\pL\pN-]+:)?([\pL\pN-]+)@)? # basic auth
(
- ([\pL\pN\pS-\.])+(\.?([\pL]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
+ ([\pL\pN\pS\-\.])+(\.?([\pL]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
| # or
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} # an IP address
| # or | false |
Other | laravel | framework | 0a6bd84aed6faaff0a1716e26c62ff7aef7971cb.json | Remove undefined variable from compact (#25193) | src/Illuminate/Database/Query/Builder.php | @@ -1240,7 +1240,7 @@ public function addWhereExistsQuery(self $query, $boolean = 'and', $not = false)
{
$type = $not ? 'NotExists' : 'Exists';
- $this->wheres[] = compact('type', 'operator', 'query', 'boolean');
+ $this->wheres[] = compact('type', 'query', 'boolean');
$this->addBinding($query->getBindings(), 'where');
| false |
Other | laravel | framework | a86665aee4bed73272b0b0365b73060db6dee984.json | remove unused var (#25187) | src/Illuminate/Database/Concerns/ManagesTransactions.php | @@ -26,7 +26,7 @@ public function transaction(Closure $callback, $attempts = 1)
// catch any exception we can rollback this transaction so that none of this
// gets actually persisted to a database or stored in a permanent fashion.
try {
- return tap($callback($this), function ($result) {
+ return tap($callback($this), function () {
$this->commit();
});
} | false |
Other | laravel | framework | 525f780709026979e08ba5cfe0da91a6853075d8.json | Create ForwardsCalls trait | src/Illuminate/Support/Traits/ForwardsCalls.php | @@ -0,0 +1,35 @@
+<?php
+
+namespace Illuminate\Support\Traits;
+
+use Error;
+use BadMethodCallException;
+
+trait ForwardsCalls
+{
+ protected function forwardCallTo($object, $method, $parameters)
+ {
+ try {
+ return $object->{$method}(...$parameters);
+ } catch (Error | BadMethodCallException $e) {
+ $pattern = '~^Call to undefined method (?P<class>[^:]+)::(?P<method>[a-zA-Z]+)\(\)$~';
+
+ if (! preg_match($pattern, $e->getMessage(), $matches)) {
+ throw $e;
+ }
+
+ if ($matches['class'] != get_class($object) || $matches['method'] != $method) {
+ throw $e;
+ }
+
+ $this->throwBadMethodCallException($method);
+ }
+ }
+
+ protected function throwBadMethodCallException($method)
+ {
+ throw new BadMethodCallException(sprintf(
+ 'Call to undefined method %s::%s()', static::class, $method
+ ));
+ }
+} | true |
Other | laravel | framework | 525f780709026979e08ba5cfe0da91a6853075d8.json | Create ForwardsCalls trait | tests/Support/ForwardsCallsTest.php | @@ -0,0 +1,93 @@
+<?php
+
+namespace Illuminate\Tests\Support;
+
+use PHPUnit\Framework\TestCase;
+use Illuminate\Support\Traits\ForwardsCalls;
+
+class ForwardsCallsTest extends TestCase
+{
+ public function testForwardsCalls()
+ {
+ $results = (new ForwardsCallsOne)->forwardedTwo('foo', 'bar');
+
+ $this->assertEquals(['foo', 'bar'], $results);
+ }
+
+ public function testNestedForwardCalls()
+ {
+ $results = (new ForwardsCallsOne)->forwardedBase('foo', 'bar');
+
+ $this->assertEquals(['foo', 'bar'], $results);
+ }
+
+ /**
+ * @expectedException \BadMethodCallException
+ * @expectedExceptionMessage Call to undefined method Illuminate\Tests\Support\ForwardsCallsOne::missingMethod()
+ */
+ public function testMissingForwardedCallThrowsCorrectError()
+ {
+ (new ForwardsCallsOne)->missingMethod('foo', 'bar');
+ }
+
+ /**
+ * @expectedException \Error
+ * @expectedExceptionMessage Call to undefined method Illuminate\Tests\Support\ForwardsCallsBase::missingMethod()
+ */
+ public function testNonForwardedErrorIsNotTamperedWith()
+ {
+ (new ForwardsCallsOne)->baseError('foo', 'bar');
+ }
+
+ /**
+ * @expectedException \BadMethodCallException
+ * @expectedExceptionMessage Call to undefined method Illuminate\Tests\Support\ForwardsCallsOne::test()
+ */
+ public function testThrowBadMethodCallException()
+ {
+ (new ForwardsCallsOne)->throwTestException('test');
+ }
+}
+
+class ForwardsCallsOne
+{
+ use ForwardsCalls;
+
+ public function __call($method, $parameters)
+ {
+ return $this->forwardCallTo(new ForwardsCallsTwo, $method, $parameters);
+ }
+
+ public function throwTestException($method)
+ {
+ $this->throwBadMethodCallException($method);
+ }
+}
+
+class ForwardsCallsTwo
+{
+ use ForwardsCalls;
+
+ public function __call($method, $parameters)
+ {
+ return $this->forwardCallTo(new ForwardsCallsBase, $method, $parameters);
+ }
+
+ public function forwardedTwo(...$parameters)
+ {
+ return $parameters;
+ }
+}
+
+class ForwardsCallsBase
+{
+ public function forwardedBase(...$parameters)
+ {
+ return $parameters;
+ }
+
+ public function baseError()
+ {
+ return $this->missingMethod();
+ }
+} | true |
Other | laravel | framework | fe290321349916223a800bf2f300d818d94d537a.json | Modify MSSQL driver order (#25150) | src/Illuminate/Database/Connectors/SqlServerConnector.php | @@ -43,13 +43,15 @@ protected function getDsn(array $config)
// First we will create the basic DSN setup as well as the port if it is in
// in the configuration options. This will give us the basic DSN we will
// need to establish the PDO connections and return them back for use.
- if (in_array('dblib', $this->getAvailableDrivers())) {
- return $this->getDblibDsn($config);
- } elseif ($this->prefersOdbc($config)) {
+ if ($this->prefersOdbc($config)) {
return $this->getOdbcDsn($config);
}
- return $this->getSqlSrvDsn($config);
+ if (in_array('sqlsrv', $this->getAvailableDrivers())) {
+ return $this->getSqlSrvDsn($config);
+ } else {
+ return $this->getDblibDsn($config);
+ }
}
/** | true |
Other | laravel | framework | fe290321349916223a800bf2f300d818d94d537a.json | Modify MSSQL driver order (#25150) | tests/Database/DatabaseConnectorTest.php | @@ -161,23 +161,48 @@ public function testSqlServerConnectCallsCreateConnectionWithOptionalArguments()
$this->assertSame($result, $connection);
}
+ public function testSqlServerConnectCallsCreateConnectionWithPreferredODBC()
+ {
+ if (! in_array('odbc', PDO::getAvailableDrivers())) {
+ $this->markTestSkipped('PHP was compiled without PDO ODBC support.');
+ }
+
+ $config = ['odbc' => true, 'odbc_datasource_name' => 'server=localhost;database=test;'];
+ $dsn = $this->getDsn($config);
+ $connector = $this->getMockBuilder('Illuminate\Database\Connectors\SqlServerConnector')->setMethods(['createConnection', 'getOptions'])->getMock();
+ $connection = m::mock('stdClass');
+ $connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->will($this->returnValue(['options']));
+ $connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->will($this->returnValue($connection));
+ $result = $connector->connect($config);
+
+ $this->assertSame($result, $connection);
+ }
+
protected function getDsn(array $config)
{
extract($config, EXTR_SKIP);
- if (in_array('dblib', PDO::getAvailableDrivers())) {
- $port = isset($config['port']) ? ':'.$port : '';
- $appname = isset($config['appname']) ? ';appname='.$config['appname'] : '';
- $charset = isset($config['charset']) ? ';charset='.$config['charset'] : '';
+ $availableDrivers = PDO::getAvailableDrivers();
- return "dblib:host={$host}{$port};dbname={$database}{$charset}{$appname}";
- } else {
+ if (in_array('odbc', $availableDrivers) &&
+ ($config['odbc'] ?? null) === true) {
+ return isset($config['odbc_datasource_name'])
+ ? 'odbc:'.$config['odbc_datasource_name'] : '';
+ }
+
+ if (in_array('sqlsrv', $availableDrivers)) {
$port = isset($config['port']) ? ','.$port : '';
$appname = isset($config['appname']) ? ';APP='.$config['appname'] : '';
$readonly = isset($config['readonly']) ? ';ApplicationIntent=ReadOnly' : '';
$pooling = (isset($config['pooling']) && $config['pooling'] == false) ? ';ConnectionPooling=0' : '';
return "sqlsrv:Server={$host}{$port};Database={$database}{$readonly}{$pooling}{$appname}";
+ } else {
+ $port = isset($config['port']) ? ':'.$port : '';
+ $appname = isset($config['appname']) ? ';appname='.$config['appname'] : '';
+ $charset = isset($config['charset']) ? ';charset='.$config['charset'] : '';
+
+ return "dblib:host={$host}{$port};dbname={$database}{$charset}{$appname}";
}
}
} | true |
Other | laravel | framework | c5dc9c870a8a1af6c7e827dd81bd15f0a1561cc4.json | update serialization logic | src/Illuminate/Cookie/Middleware/EncryptCookies.php | @@ -30,7 +30,7 @@ class EncryptCookies
*
* @var bool
*/
- protected $serialize = false;
+ protected static $serialize = false;
/**
* Create a new CookieGuard instance.
@@ -100,7 +100,7 @@ protected function decryptCookie($name, $cookie)
{
return is_array($cookie)
? $this->decryptArray($cookie)
- : $this->encrypter->decrypt($cookie, $this->serialize);
+ : $this->encrypter->decrypt($cookie, static::serialized($name));
}
/**
@@ -115,7 +115,7 @@ protected function decryptArray(array $cookie)
foreach ($cookie as $key => $value) {
if (is_string($value)) {
- $decrypted[$key] = $this->encrypter->decrypt($value, $this->serialize);
+ $decrypted[$key] = $this->encrypter->decrypt($value, static::serialized($key));
}
}
@@ -136,7 +136,7 @@ protected function encrypt(Response $response)
}
$response->headers->setCookie($this->duplicate(
- $cookie, $this->encrypter->encrypt($cookie->getValue(), $this->serialize)
+ $cookie, $this->encrypter->encrypt($cookie->getValue(), static::serialized($cookie->getName()))
));
}
@@ -169,4 +169,15 @@ public function isDisabled($name)
{
return in_array($name, $this->except);
}
+
+ /**
+ * Determine if the cookie contents should be serialized.
+ *
+ * @param string $name
+ * @return bool
+ */
+ public static function serialized($name)
+ {
+ return static::$serialize;
+ }
} | true |
Other | laravel | framework | c5dc9c870a8a1af6c7e827dd81bd15f0a1561cc4.json | update serialization logic | src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php | @@ -8,6 +8,7 @@
use Symfony\Component\HttpFoundation\Cookie;
use Illuminate\Contracts\Encryption\Encrypter;
use Illuminate\Session\TokenMismatchException;
+use Illuminate\Cookie\Middleware\EncryptCookies;
class VerifyCsrfToken
{
@@ -138,7 +139,7 @@ protected function getTokenFromRequest($request)
$token = $request->input('_token') ?: $request->header('X-CSRF-TOKEN');
if (! $token && $header = $request->header('X-XSRF-TOKEN')) {
- $token = $this->encrypter->decrypt($header, false);
+ $token = $this->encrypter->decrypt($header, static::serialized());
}
return $token;
@@ -164,4 +165,14 @@ protected function addCookieToResponse($request, $response)
return $response;
}
+
+ /**
+ * Determine if the cookie contents should be serialized.
+ *
+ * @return bool
+ */
+ public static function serialized()
+ {
+ return EncryptCookies::serialized('XSRF-TOKEN');
+ }
} | true |
Other | laravel | framework | 240d904606a101f5104bff8a1d09678c44f11903.json | adjust cookie serialization | src/Illuminate/Cookie/Middleware/EncryptCookies.php | @@ -30,7 +30,7 @@ class EncryptCookies
*
* @var bool
*/
- protected $serialize = false;
+ protected static $serialize = false;
/**
* Create a new CookieGuard instance.
@@ -100,7 +100,7 @@ protected function decryptCookie($name, $cookie)
{
return is_array($cookie)
? $this->decryptArray($cookie)
- : $this->encrypter->decrypt($cookie, $this->serialize);
+ : $this->encrypter->decrypt($cookie, static::serialized($name));
}
/**
@@ -115,7 +115,7 @@ protected function decryptArray(array $cookie)
foreach ($cookie as $key => $value) {
if (is_string($value)) {
- $decrypted[$key] = $this->encrypter->decrypt($value, $this->serialize);
+ $decrypted[$key] = $this->encrypter->decrypt($value, static::serialized($key));
}
}
@@ -136,7 +136,7 @@ protected function encrypt(Response $response)
}
$response->headers->setCookie($this->duplicate(
- $cookie, $this->encrypter->encrypt($cookie->getValue(), $this->serialize)
+ $cookie, $this->encrypter->encrypt($cookie->getValue(), static::serialized($cookie->getName()))
));
}
@@ -169,4 +169,15 @@ public function isDisabled($name)
{
return in_array($name, $this->except);
}
+
+ /**
+ * Determine if the cookie contents should be serialized.
+ *
+ * @param string $name
+ * @return bool
+ */
+ public static function serialized($name)
+ {
+ return static::$serialize;
+ }
} | true |
Other | laravel | framework | 240d904606a101f5104bff8a1d09678c44f11903.json | adjust cookie serialization | src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php | @@ -8,6 +8,7 @@
use Symfony\Component\HttpFoundation\Cookie;
use Illuminate\Contracts\Encryption\Encrypter;
use Illuminate\Session\TokenMismatchException;
+use Illuminate\Cookie\Middleware\EncryptCookies;
class VerifyCsrfToken
{
@@ -138,7 +139,7 @@ protected function getTokenFromRequest($request)
$token = $request->input('_token') ?: $request->header('X-CSRF-TOKEN');
if (! $token && $header = $request->header('X-XSRF-TOKEN')) {
- $token = $this->encrypter->decrypt($header, false);
+ $token = $this->encrypter->decrypt($header, static::serialized());
}
return $token;
@@ -164,4 +165,14 @@ protected function addCookieToResponse($request, $response)
return $response;
}
+
+ /**
+ * Determine if the cookie contents should be serialized.
+ *
+ * @return bool
+ */
+ public static function serialized()
+ {
+ return EncryptCookies::serialized('XSRF-TOKEN');
+ }
} | true |
Other | laravel | framework | 2104d867fd5a14753a01bec2603da0044fefa17e.json | Flatten preset asset directories (#25112) | src/Illuminate/Foundation/Console/Presets/Bootstrap.php | @@ -38,7 +38,7 @@ protected static function updatePackageArray(array $packages)
*/
protected static function updateSass()
{
- copy(__DIR__.'/bootstrap-stubs/_variables.scss', resource_path('assets/sass/_variables.scss'));
- copy(__DIR__.'/bootstrap-stubs/app.scss', resource_path('assets/sass/app.scss'));
+ copy(__DIR__.'/bootstrap-stubs/_variables.scss', resource_path('sass/_variables.scss'));
+ copy(__DIR__.'/bootstrap-stubs/app.scss', resource_path('sass/app.scss'));
}
} | true |
Other | laravel | framework | 2104d867fd5a14753a01bec2603da0044fefa17e.json | Flatten preset asset directories (#25112) | src/Illuminate/Foundation/Console/Presets/None.php | @@ -17,8 +17,8 @@ public static function install()
static::updateBootstrapping();
tap(new Filesystem, function ($filesystem) {
- $filesystem->deleteDirectory(resource_path('assets/js/components'));
- $filesystem->delete(resource_path('assets/sass/_variables.scss'));
+ $filesystem->deleteDirectory(resource_path('js/components'));
+ $filesystem->delete(resource_path('sass/_variables.scss'));
$filesystem->deleteDirectory(base_path('node_modules'));
$filesystem->deleteDirectory(public_path('css'));
$filesystem->deleteDirectory(public_path('js'));
@@ -53,7 +53,7 @@ protected static function updatePackageArray(array $packages)
*/
protected static function updateBootstrapping()
{
- file_put_contents(resource_path('assets/sass/app.scss'), ''.PHP_EOL);
- copy(__DIR__.'/none-stubs/app.js', resource_path('assets/js/app.js'));
+ file_put_contents(resource_path('sass/app.scss'), ''.PHP_EOL);
+ copy(__DIR__.'/none-stubs/app.js', resource_path('js/app.js'));
}
} | true |
Other | laravel | framework | 2104d867fd5a14753a01bec2603da0044fefa17e.json | Flatten preset asset directories (#25112) | src/Illuminate/Foundation/Console/Presets/Preset.php | @@ -15,7 +15,7 @@ protected static function ensureComponentDirectoryExists()
{
$filesystem = new Filesystem;
- if (! $filesystem->isDirectory($directory = resource_path('assets/js/components'))) {
+ if (! $filesystem->isDirectory($directory = resource_path('js/components'))) {
$filesystem->makeDirectory($directory, 0755, true);
}
} | true |
Other | laravel | framework | 2104d867fd5a14753a01bec2603da0044fefa17e.json | Flatten preset asset directories (#25112) | src/Illuminate/Foundation/Console/Presets/React.php | @@ -55,12 +55,12 @@ protected static function updateWebpackConfiguration()
protected static function updateComponent()
{
(new Filesystem)->delete(
- resource_path('assets/js/components/ExampleComponent.vue')
+ resource_path('js/components/ExampleComponent.vue')
);
copy(
__DIR__.'/react-stubs/Example.js',
- resource_path('assets/js/components/Example.js')
+ resource_path('js/components/Example.js')
);
}
@@ -71,6 +71,6 @@ protected static function updateComponent()
*/
protected static function updateBootstrapping()
{
- copy(__DIR__.'/react-stubs/app.js', resource_path('assets/js/app.js'));
+ copy(__DIR__.'/react-stubs/app.js', resource_path('js/app.js'));
}
} | true |
Other | laravel | framework | 2104d867fd5a14753a01bec2603da0044fefa17e.json | Flatten preset asset directories (#25112) | src/Illuminate/Foundation/Console/Presets/Vue.php | @@ -55,12 +55,12 @@ protected static function updateWebpackConfiguration()
protected static function updateComponent()
{
(new Filesystem)->delete(
- resource_path('assets/js/components/Example.js')
+ resource_path('js/components/Example.js')
);
copy(
__DIR__.'/vue-stubs/ExampleComponent.vue',
- resource_path('assets/js/components/ExampleComponent.vue')
+ resource_path('js/components/ExampleComponent.vue')
);
}
@@ -71,6 +71,6 @@ protected static function updateComponent()
*/
protected static function updateBootstrapping()
{
- copy(__DIR__.'/vue-stubs/app.js', resource_path('assets/js/app.js'));
+ copy(__DIR__.'/vue-stubs/app.js', resource_path('js/app.js'));
}
} | true |
Other | laravel | framework | 2104d867fd5a14753a01bec2603da0044fefa17e.json | Flatten preset asset directories (#25112) | src/Illuminate/Foundation/Console/Presets/react-stubs/webpack.mix.js | @@ -11,5 +11,5 @@ let mix = require('laravel-mix');
|
*/
-mix.react('resources/assets/js/app.js', 'public/js')
- .sass('resources/assets/sass/app.scss', 'public/css');
+mix.react('resources/js/app.js', 'public/js')
+ .sass('resources/sass/app.scss', 'public/css'); | true |
Other | laravel | framework | 2104d867fd5a14753a01bec2603da0044fefa17e.json | Flatten preset asset directories (#25112) | src/Illuminate/Foundation/Console/Presets/vue-stubs/webpack.mix.js | @@ -11,5 +11,5 @@ let mix = require('laravel-mix');
|
*/
-mix.js('resources/assets/js/app.js', 'public/js')
- .sass('resources/assets/sass/app.scss', 'public/css');
+mix.js('resources/js/app.js', 'public/js')
+ .sass('resources/sass/app.scss', 'public/css'); | true |
Other | laravel | framework | a0b4d25c1b795cd81cacda1a1407ecc191151c4c.json | Add absolute parameter to signed routes (#25107) | src/Illuminate/Routing/UrlGenerator.php | @@ -301,9 +301,10 @@ public function formatScheme($secure = null)
* @param string $name
* @param array $parameters
* @param \DateTimeInterface|int $expiration
+ * @param bool $absolute
* @return string
*/
- public function signedRoute($name, $parameters = [], $expiration = null)
+ public function signedRoute($name, $parameters = [], $expiration = null, $absolute = true)
{
$parameters = $this->formatParameters($parameters);
@@ -317,7 +318,7 @@ public function signedRoute($name, $parameters = [], $expiration = null)
return $this->route($name, $parameters + [
'signature' => hash_hmac('sha256', $this->route($name, $parameters), $key),
- ]);
+ ], $absolute);
}
/**
@@ -326,11 +327,12 @@ public function signedRoute($name, $parameters = [], $expiration = null)
* @param string $name
* @param \DateTimeInterface|int $expiration
* @param array $parameters
+ * @param bool $absolute
* @return string
*/
- public function temporarySignedRoute($name, $expiration, $parameters = [])
+ public function temporarySignedRoute($name, $expiration, $parameters = [], $absolute = true)
{
- return $this->signedRoute($name, $parameters, $expiration);
+ return $this->signedRoute($name, $parameters, $expiration, $absolute);
}
/** | false |
Other | laravel | framework | 55afaaa248d2e7092f99963762150f397fbbaba3.json | Allow guests in authorize middleware (#25109) | src/Illuminate/Auth/Middleware/Authorize.php | @@ -5,17 +5,9 @@
use Closure;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Auth\Access\Gate;
-use Illuminate\Contracts\Auth\Factory as Auth;
class Authorize
{
- /**
- * The authentication factory instance.
- *
- * @var \Illuminate\Contracts\Auth\Factory
- */
- protected $auth;
-
/**
* The gate instance.
*
@@ -26,13 +18,11 @@ class Authorize
/**
* Create a new middleware instance.
*
- * @param \Illuminate\Contracts\Auth\Factory $auth
* @param \Illuminate\Contracts\Auth\Access\Gate $gate
* @return void
*/
- public function __construct(Auth $auth, Gate $gate)
+ public function __construct(Gate $gate)
{
- $this->auth = $auth;
$this->gate = $gate;
}
@@ -50,8 +40,6 @@ public function __construct(Auth $auth, Gate $gate)
*/
public function handle($request, Closure $next, $ability, ...$models)
{
- $this->auth->authenticate();
-
$this->gate->authorize($ability, $this->getGateArguments($request, $models));
return $next($request); | true |
Other | laravel | framework | 55afaaa248d2e7092f99963762150f397fbbaba3.json | Allow guests in authorize middleware (#25109) | tests/Auth/AuthorizeMiddlewareTest.php | @@ -12,7 +12,6 @@
use Illuminate\Container\Container;
use Illuminate\Auth\Middleware\Authorize;
use Illuminate\Contracts\Routing\Registrar;
-use Illuminate\Contracts\Auth\Factory as Auth;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Contracts\Auth\Access\Gate as GateContract;
@@ -34,13 +33,6 @@ public function setUp()
Container::setInstance($this->container = new Container);
- $this->container->singleton(Auth::class, function () {
- $auth = m::mock(Auth::class);
- $auth->shouldReceive('authenticate')->once()->andReturn(null);
-
- return $auth;
- });
-
$this->container->singleton(GateContract::class, function () {
return new Gate($this->container, function () {
return $this->user;
@@ -208,7 +200,7 @@ public function testModelInstanceAsParameter()
$nextParam = $param;
};
- (new Authorize($this->container->make(Auth::class), $this->gate()))
+ (new Authorize($this->gate()))
->handle($request, $next, 'success', $instance);
}
| true |
Other | laravel | framework | a09b0e377ff1cf2b68a0c9bb87e8dfba21f34c51.json | use 301 redirect | src/Illuminate/Routing/Router.php | @@ -236,7 +236,7 @@ public function fallback($action)
* @param int $status
* @return \Illuminate\Routing\Route
*/
- public function redirect($uri, $destination, $status = 302)
+ public function redirect($uri, $destination, $status = 301)
{
return $this->any($uri, '\Illuminate\Routing\RedirectController')
->defaults('destination', $destination) | false |
Other | laravel | framework | 7a5b58b8e688a60557be238f4648b196b750f233.json | Fix ConnectionInterface methods (#25092)
Declaration of Illuminate\Database\Connection class methods must be compatible with Illuminate\Database\ConnectionInterface | src/Illuminate/Database/ConnectionInterface.php | @@ -27,18 +27,20 @@ public function raw($value);
*
* @param string $query
* @param array $bindings
+ * @param bool $useReadPdo
* @return mixed
*/
- public function selectOne($query, $bindings = []);
+ public function selectOne($query, $bindings = [], $useReadPdo = true);
/**
* Run a select statement against the database.
*
* @param string $query
* @param array $bindings
+ * @param bool $useReadPdo
* @return array
*/
- public function select($query, $bindings = []);
+ public function select($query, $bindings = [], $useReadPdo = true);
/**
* Run an insert statement against the database. | false |
Other | laravel | framework | bb57655967f31b426b968a46ca738d6a245e873d.json | Add getFallbackChannelName method.
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com> | src/Illuminate/Log/LogManager.php | @@ -374,6 +374,16 @@ protected function formatter()
});
}
+ /**
+ * Get fallback log channel name.
+ *
+ * @return string
+ */
+ protected function getFallbackChannelName()
+ {
+ return $this->app->bound('env') ? $this->app->environment() : 'production';
+ }
+
/**
* Get the log connection configuration.
* | true |
Other | laravel | framework | bb57655967f31b426b968a46ca738d6a245e873d.json | Add getFallbackChannelName method.
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com> | src/Illuminate/Log/LoggerConfiguration.php | @@ -51,9 +51,16 @@ protected function level(array $config)
protected function parseChannel(array $config)
{
if (! isset($config['name'])) {
- return $this->app->bound('env') ? $this->app->environment() : 'production';
+ return $this->getFallbackChannelName();
}
return $config['name'];
}
+
+ /**
+ * Get fallback log channel name.
+ *
+ * @return string
+ */
+ abstract protected function getFallbackChannelName();
} | true |
Other | laravel | framework | a7fecc3e3d410a955021583ddfc6cccc07b0114b.json | remove check for keys | src/Illuminate/Foundation/Testing/TestResponse.php | @@ -552,7 +552,6 @@ protected function jsonSearchStrings($key, $value)
$needle = substr(json_encode([$key => $value]), 1, -1);
return [
- $needle.':',
$needle.']',
$needle.'}',
$needle.',', | true |
Other | laravel | framework | a7fecc3e3d410a955021583ddfc6cccc07b0114b.json | remove check for keys | tests/Foundation/FoundationTestResponseTest.php | @@ -167,8 +167,6 @@ public function testAssertJsonFragment()
$response = TestResponse::fromBaseResponse(new Response(new JsonSerializableMixedResourcesStub));
- $response->assertJsonFragment(['foobar']);
-
$response->assertJsonFragment(['foo' => 'bar']);
$response->assertJsonFragment(['foobar_foo' => 'foo']); | true |
Other | laravel | framework | 3c6febb810af2128c479b402c36859d7572665cc.json | Apply fixes from StyleCI (#25080) | src/Illuminate/Validation/Rules/RequiredIf.php | @@ -2,8 +2,6 @@
namespace Illuminate\Validation\Rules;
-use Closure;
-
class RequiredIf
{
/** | false |
Other | laravel | framework | 5faa5944d9a9f2d2cae0cd7a40f7ec3ef7b58632.json | Apply fixes from StyleCI (#25079) | tests/Support/SupportPluralizerTest.php | @@ -40,7 +40,8 @@ public function testIfEndOfWordPlural()
$this->assertEquals('VertexFields', Str::plural('VertexField'));
}
- public function testPluralWithNegativeCount() {
+ public function testPluralWithNegativeCount()
+ {
$this->assertEquals('test', Str::plural('test', 1));
$this->assertEquals('tests', Str::plural('test', 2));
$this->assertEquals('test', Str::plural('test', -1)); | false |
Other | laravel | framework | f294134e2404dca84db92efa193ba574174cef30.json | Update DocBlock for PHP Analyses (#25078) | src/Illuminate/Http/Resources/Json/JsonResource.php | @@ -60,7 +60,7 @@ public function __construct($resource)
/**
* Create a new resource instance.
*
- * @param dynamic $parameters
+ * @param mixed $parameters
* @return static
*/
public static function make(...$parameters) | false |
Other | laravel | framework | 5f9769bc17d7d6ade1583ad7f348b1c4ebe3eb8b.json | Remove unused rule | tests/Validation/ValidationRequiredIfTest.php | @@ -2,7 +2,6 @@
namespace Illuminate\Tests\Validation;
-use Illuminate\Validation\Rule;
use PHPUnit\Framework\TestCase;
use Illuminate\Validation\Rules\RequiredIf;
| false |
Other | laravel | framework | 932cccb5c511d9e36a5e27217232d2626949737a.json | Fix edge case in assertJsonFragment (#25023) | src/Illuminate/Foundation/Testing/TestResponse.php | @@ -552,6 +552,7 @@ protected function jsonSearchStrings($key, $value)
$needle = substr(json_encode([$key => $value]), 1, -1);
return [
+ $needle.':',
$needle.']',
$needle.'}',
$needle.',', | true |
Other | laravel | framework | 932cccb5c511d9e36a5e27217232d2626949737a.json | Fix edge case in assertJsonFragment (#25023) | tests/Foundation/FoundationTestResponseTest.php | @@ -167,6 +167,8 @@ public function testAssertJsonFragment()
$response = TestResponse::fromBaseResponse(new Response(new JsonSerializableMixedResourcesStub));
+ $response->assertJsonFragment(['foobar']);
+
$response->assertJsonFragment(['foo' => 'bar']);
$response->assertJsonFragment(['foobar_foo' => 'foo']); | true |
Other | laravel | framework | 64f6f170e9c8f61dd61ef6f75aae633f9547b8b9.json | support multiple addresses in array | src/Illuminate/Notifications/Messages/MailMessage.php | @@ -2,6 +2,9 @@
namespace Illuminate\Notifications\Messages;
+use Traversable;
+use Illuminate\Contracts\Support\Arrayable;
+
class MailMessage extends SimpleMessage
{
/**
@@ -144,35 +147,47 @@ public function from($address, $name = null)
*/
public function replyTo($address, $name = null)
{
- $this->replyTo[] = [$address, $name];
+ if (is_array($address) || $address instanceof Arrayable || $address instanceof Traversable) {
+ $this->replyTo += $this->prepareAddress($address);
+ } else {
+ $this->replyTo[] = [$address, $name];
+ }
return $this;
}
/**
* Set the cc address for the mail message.
*
- * @param string $address
+ * @param array|string $address
* @param string|null $name
* @return $this
*/
public function cc($address, $name = null)
{
- $this->cc[] = [$address, $name];
+ if (is_array($address) || $address instanceof Arrayable || $address instanceof Traversable) {
+ $this->cc += $this->prepareAddress($address);
+ } else {
+ $this->cc[] = [$address, $name];
+ }
return $this;
}
/**
* Set the bcc address for the mail message.
*
- * @param string $address
+ * @param array|string $address
* @param string|null $name
* @return $this
*/
public function bcc($address, $name = null)
{
- $this->bcc[] = [$address, $name];
+ if (is_array($address) || $address instanceof Arrayable || $address instanceof Traversable) {
+ $this->bcc += $this->prepareAddress($address);
+ } else {
+ $this->bcc[] = [$address, $name];
+ }
return $this;
}
@@ -230,4 +245,20 @@ public function data()
{
return array_merge($this->toArray(), $this->viewData);
}
+
+ /**
+ * Prepare address input for support multiple recipients.
+ *
+ * @param array $value
+ * @return array
+ */
+ protected function prepareAddress($value)
+ {
+ $recipients = [];
+ foreach ($value as $name => $address) {
+ $recipients[] = [$address, is_numeric($name) ? null : $name];
+ }
+
+ return $recipients;
+ }
} | true |
Other | laravel | framework | 64f6f170e9c8f61dd61ef6f75aae633f9547b8b9.json | support multiple addresses in array | tests/Notifications/NotificationMailMessageTest.php | @@ -30,6 +30,11 @@ public function testCcIsSetCorrectly()
->cc('test@example.com', 'Test');
$this->assertSame([['test@example.com', null], ['test@example.com', 'Test']], $message->cc);
+
+ $message = new MailMessage;
+ $message->cc(['test@example.com', 'Test' => 'test@example.com']);
+
+ $this->assertSame([['test@example.com', null], ['test@example.com', 'Test']], $message->cc);
}
public function testBccIsSetCorrectly()
@@ -44,6 +49,11 @@ public function testBccIsSetCorrectly()
->bcc('test@example.com', 'Test');
$this->assertSame([['test@example.com', null], ['test@example.com', 'Test']], $message->bcc);
+
+ $message = new MailMessage;
+ $message->bcc(['test@example.com', 'Test' => 'test@example.com']);
+
+ $this->assertSame([['test@example.com', null], ['test@example.com', 'Test']], $message->bcc);
}
public function testReplyToIsSetCorrectly()
@@ -58,5 +68,10 @@ public function testReplyToIsSetCorrectly()
->replyTo('test@example.com', 'Test');
$this->assertSame([['test@example.com', null], ['test@example.com', 'Test']], $message->replyTo);
+
+ $message = new MailMessage;
+ $message->replyTo(['test@example.com', 'Test' => 'test@example.com']);
+
+ $this->assertSame([['test@example.com', null], ['test@example.com', 'Test']], $message->replyTo);
}
} | true |
Other | laravel | framework | 2ee2bb537ee10f398e9c4f4ffbc12b057a93a3d2.json | Add tests for Arr::query(). (#25024) | tests/Support/SupportArrTest.php | @@ -419,6 +419,16 @@ public function testPull()
$this->assertEquals(['emails' => ['joe@example.com' => 'Joe', 'jane@localhost' => 'Jane']], $array);
}
+ public function testQuery()
+ {
+ $this->assertSame('', Arr::query([]));
+ $this->assertSame('foo=bar', Arr::query(['foo' => 'bar']));
+ $this->assertSame('foo=bar&bar=baz', Arr::query(['foo' => 'bar', 'bar' => 'baz']));
+ $this->assertSame('foo=bar&bar=1', Arr::query(['foo' => 'bar', 'bar' => true]));
+ $this->assertSame('foo=bar', Arr::query(['foo' => 'bar', 'bar' => null]));
+ $this->assertSame('foo=bar&bar=', Arr::query(['foo' => 'bar', 'bar' => '']));
+ }
+
public function testRandom()
{
$random = Arr::random(['foo', 'bar', 'baz']); | false |
Other | laravel | framework | dc767d2d7cecd621d4c12b9eac901c17560cecd0.json | Apply fixes from StyleCI (#25017) | src/Illuminate/Mail/Transport/MailgunTransport.php | @@ -2,7 +2,6 @@
namespace Illuminate\Mail\Transport;
-use Illuminate\Support\Str;
use Swift_Mime_SimpleMessage;
use GuzzleHttp\ClientInterface;
| false |
Other | laravel | framework | 819dbe33b899e174ff70192479f1beaa86ab6707.json | add API endpoint to MailgunTransport (#25010) | src/Illuminate/Mail/Transport/MailgunTransport.php | @@ -23,7 +23,7 @@ class MailgunTransport extends Transport
protected $key;
/**
- * The Mailgun domain.
+ * The Mailgun email domain.
*
* @var string
*/
@@ -34,7 +34,7 @@ class MailgunTransport extends Transport
*
* @var string
*/
- protected $url;
+ protected $endpoint;
/**
* Create a new Mailgun transport instance.
@@ -44,10 +44,12 @@ class MailgunTransport extends Transport
* @param string $domain
* @return void
*/
- public function __construct(ClientInterface $client, $key, $domain)
+ public function __construct(ClientInterface $client, $key, $domain, $endpoint = null)
{
$this->key = $key;
$this->client = $client;
+ $this->endpoint = $endpoint ?? 'api.mailgun.net';
+
$this->setDomain($domain);
}
@@ -62,7 +64,10 @@ public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = nul
$message->setBcc([]);
- $this->client->post($this->url, $this->payload($message, $to));
+ $this->client->post(
+ "https://{$this->endpoint}/v3/{$this->domain}/messages.mime",
+ $this->payload($message, $to)
+ );
$this->sendPerformed($message);
@@ -162,12 +167,6 @@ public function getDomain()
*/
public function setDomain($domain)
{
- $url = ! Str::startsWith($domain, ['http://', 'https://'])
- ? 'https://api.mailgun.net/v3/'.$domain
- : $domain;
-
- $this->url = $url.'/messages.mime';
-
return $this->domain = $domain;
}
} | true |
Other | laravel | framework | 819dbe33b899e174ff70192479f1beaa86ab6707.json | add API endpoint to MailgunTransport (#25010) | src/Illuminate/Mail/TransportManager.php | @@ -118,7 +118,9 @@ protected function createMailgunDriver()
return new MailgunTransport(
$this->guzzle($config),
- $config['secret'], $config['domain']
+ $config['secret'],
+ $config['domain'],
+ $config['endpoint'] ?? null
);
}
| true |
Other | laravel | framework | a9e332988f707a3e721dd24b7881fc2c8f07daa5.json | add missing docblock | src/Illuminate/Console/Parser.php | @@ -35,6 +35,8 @@ public static function parse($expression)
*
* @param string $expression
* @return string
+ *
+ * @throws \InvalidArgumentException
*/
protected static function name($expression)
{ | false |
Other | laravel | framework | e3438e1071a06a2570108ed2a6e011b8816abbc7.json | Make Router::addRoute() public (#25000)
I'm developing a package that provides a different mechanism for defining routes. It would be much easier for the package to call `addRoute()` directly instead of the individual human-friendly get/post/etc. methods. I don't want to extend the router in order to reduce conflicts with customized apps or other packages.
Currently I am creating a macro and calling `$this->addRoute()` within the closure.
I am unsure if this would be considered a BC-affecting change, specifically if it affects anyone who is already extending the router and this method in particular. If there is a reason for keeping it protected that I am unaware of, I'd love to hear it. | src/Illuminate/Routing/Router.php | @@ -425,7 +425,7 @@ public function getLastGroupPrefix()
* @param \Closure|array|string|null $action
* @return \Illuminate\Routing\Route
*/
- protected function addRoute($methods, $uri, $action)
+ public function addRoute($methods, $uri, $action)
{
return $this->routes->add($this->createRoute($methods, $uri, $action));
} | false |
Other | laravel | framework | 51c6c8604fb1c0f5a13585cf991a872bf2f242bb.json | Use proper assertions. (#25004) | tests/Filesystem/FilesystemAdapterTest.php | @@ -107,7 +107,7 @@ public function testDelete()
file_put_contents($this->tempDir.'/file.txt', 'Hello World');
$filesystemAdapter = new FilesystemAdapter($this->filesystem);
$this->assertTrue($filesystemAdapter->delete('file.txt'));
- $this->assertFalse(file_exists($this->tempDir.'/file.txt'));
+ $this->assertFileNotExists($this->tempDir.'/file.txt');
}
public function testDeleteReturnsFalseWhenFileNotFound() | true |
Other | laravel | framework | 51c6c8604fb1c0f5a13585cf991a872bf2f242bb.json | Use proper assertions. (#25004) | tests/Integration/Database/EloquentCollectionLoadMissingTest.php | @@ -57,7 +57,7 @@ public function testLoadMissing()
$this->assertCount(2, \DB::getQueryLog());
$this->assertTrue($posts[0]->comments[0]->relationLoaded('parent'));
$this->assertTrue($posts[0]->comments[1]->parent->relationLoaded('revisions'));
- $this->assertFalse(array_key_exists('id', $posts[0]->comments[1]->parent->revisions[0]->getAttributes()));
+ $this->assertArrayNotHasKey('id', $posts[0]->comments[1]->parent->revisions[0]->getAttributes());
}
public function testLoadMissingWithClosure()
@@ -72,7 +72,7 @@ public function testLoadMissingWithClosure()
$this->assertCount(1, \DB::getQueryLog());
$this->assertTrue($posts[0]->comments[0]->relationLoaded('parent'));
- $this->assertFalse(array_key_exists('post_id', $posts[0]->comments[1]->parent->getAttributes()));
+ $this->assertArrayNotHasKey('post_id', $posts[0]->comments[1]->parent->getAttributes());
}
}
| true |
Other | laravel | framework | 51c6c8604fb1c0f5a13585cf991a872bf2f242bb.json | Use proper assertions. (#25004) | tests/Integration/Routing/UrlSigningTest.php | @@ -21,7 +21,7 @@ public function test_signing_url()
return $request->hasValidSignature() ? 'valid' : 'invalid';
})->name('foo');
- $this->assertTrue(is_string($url = URL::signedRoute('foo', ['id' => 1])));
+ $this->assertInternalType('string', $url = URL::signedRoute('foo', ['id' => 1]));
$this->assertEquals('valid', $this->get($url)->original);
}
@@ -32,7 +32,7 @@ public function test_temporary_signed_urls()
})->name('foo');
Carbon::setTestNow(Carbon::create(2018, 1, 1));
- $this->assertTrue(is_string($url = URL::temporarySignedRoute('foo', now()->addMinutes(5), ['id' => 1])));
+ $this->assertInternalType('string', $url = URL::temporarySignedRoute('foo', now()->addMinutes(5), ['id' => 1]));
$this->assertEquals('valid', $this->get($url)->original);
Carbon::setTestNow(Carbon::create(2018, 1, 1)->addMinutes(10));
@@ -55,7 +55,7 @@ public function test_signed_middleware()
})->name('foo')->middleware(ValidateSignature::class);
Carbon::setTestNow(Carbon::create(2018, 1, 1));
- $this->assertTrue(is_string($url = URL::temporarySignedRoute('foo', now()->addMinutes(5), ['id' => 1])));
+ $this->assertInternalType('string', $url = URL::temporarySignedRoute('foo', now()->addMinutes(5), ['id' => 1]));
$this->assertEquals('valid', $this->get($url)->original);
}
@@ -66,7 +66,7 @@ public function test_signed_middleware_with_invalid_url()
})->name('foo')->middleware(ValidateSignature::class);
Carbon::setTestNow(Carbon::create(2018, 1, 1));
- $this->assertTrue(is_string($url = URL::temporarySignedRoute('foo', now()->addMinutes(5), ['id' => 1])));
+ $this->assertInternalType('string', $url = URL::temporarySignedRoute('foo', now()->addMinutes(5), ['id' => 1]));
Carbon::setTestNow(Carbon::create(2018, 1, 1)->addMinutes(10));
$response = $this->get($url);
@@ -82,7 +82,7 @@ public function test_signed_middleware_with_routable_parameter()
return $request->hasValidSignature() ? $routable : 'invalid';
})->name('foo');
- $this->assertTrue(is_string($url = URL::signedRoute('foo', $model)));
+ $this->assertInternalType('string', $url = URL::signedRoute('foo', $model));
$this->assertEquals('routable', $this->get($url)->original);
}
} | true |
Other | laravel | framework | 51c6c8604fb1c0f5a13585cf991a872bf2f242bb.json | Use proper assertions. (#25004) | tests/Mail/MailableQueuedTest.php | @@ -46,7 +46,7 @@ public function testQueuedMailableWithAttachmentSent()
$mailable = new MailableQueableStub();
$attachmentOption = ['mime' => 'image/jpeg', 'as' => 'bar.jpg'];
$mailable->attach('foo.jpg', $attachmentOption);
- $this->assertTrue(is_array($mailable->attachments));
+ $this->assertInternalType('array', $mailable->attachments);
$this->assertCount(1, $mailable->attachments);
$this->assertEquals($mailable->attachments[0]['options'], $attachmentOption);
$queueFake->assertNothingPushed();
@@ -77,7 +77,7 @@ public function testQueuedMailableWithAttachmentFromDiskSent()
$mailable->attachFromStorage('/', 'foo.jpg', $attachmentOption);
- $this->assertTrue(is_array($mailable->diskAttachments));
+ $this->assertInternalType('array', $mailable->diskAttachments);
$this->assertCount(1, $mailable->diskAttachments);
$this->assertEquals($mailable->diskAttachments[0]['options'], $attachmentOption);
| true |
Other | laravel | framework | fa9359c8fed0211ddff970ee99a61e75bcd4fca8.json | Add a setup method in BroadcasterTest | tests/Broadcasting/BroadcasterTest.php | @@ -11,33 +11,43 @@
class BroadcasterTest extends TestCase
{
+ /**
+ * @var \Illuminate\Tests\Broadcasting\FakeBroadcaster
+ */
+ public $broadcaster;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->broadcaster = new FakeBroadcaster;
+ }
+
public function tearDown()
{
m::close();
}
public function testExtractingParametersWhileCheckingForUserAccess()
{
- $broadcaster = new FakeBroadcaster;
-
$callback = function ($user, BroadcasterTestEloquentModelStub $model, $nonModel) {
};
- $parameters = $broadcaster->extractAuthParameters('asd.{model}.{nonModel}', 'asd.1.something', $callback);
+ $parameters = $this->broadcaster->extractAuthParameters('asd.{model}.{nonModel}', 'asd.1.something', $callback);
$this->assertEquals(['model.1.instance', 'something'], $parameters);
$callback = function ($user, BroadcasterTestEloquentModelStub $model, BroadcasterTestEloquentModelStub $model2, $something) {
};
- $parameters = $broadcaster->extractAuthParameters('asd.{model}.{model2}.{nonModel}', 'asd.1.uid.something', $callback);
+ $parameters = $this->broadcaster->extractAuthParameters('asd.{model}.{model2}.{nonModel}', 'asd.1.uid.something', $callback);
$this->assertEquals(['model.1.instance', 'model.uid.instance', 'something'], $parameters);
$callback = function ($user) {
};
- $parameters = $broadcaster->extractAuthParameters('asd', 'asd', $callback);
+ $parameters = $this->broadcaster->extractAuthParameters('asd', 'asd', $callback);
$this->assertEquals([], $parameters);
$callback = function ($user, $something) {
};
- $parameters = $broadcaster->extractAuthParameters('asd', 'asd', $callback);
+ $parameters = $this->broadcaster->extractAuthParameters('asd', 'asd', $callback);
$this->assertEquals([], $parameters);
/*
@@ -52,16 +62,14 @@ public function testExtractingParametersWhileCheckingForUserAccess()
$container->instance(BindingRegistrar::class, $binder);
$callback = function ($user, $model) {
};
- $parameters = $broadcaster->extractAuthParameters('something.{model}', 'something.1', $callback);
+ $parameters = $this->broadcaster->extractAuthParameters('something.{model}', 'something.1', $callback);
$this->assertEquals(['bound'], $parameters);
Container::setInstance(new Container);
}
public function testCanUseChannelClasses()
{
- $broadcaster = new FakeBroadcaster;
-
- $parameters = $broadcaster->extractAuthParameters('asd.{model}.{nonModel}', 'asd.1.something', DummyBroadcastingChannel::class);
+ $parameters = $this->broadcaster->extractAuthParameters('asd.{model}.{nonModel}', 'asd.1.something', DummyBroadcastingChannel::class);
$this->assertEquals(['model.1.instance', 'something'], $parameters);
}
@@ -70,104 +78,85 @@ public function testCanUseChannelClasses()
*/
public function testUnknownChannelAuthHandlerTypeThrowsException()
{
- $broadcaster = new FakeBroadcaster;
-
- $broadcaster->extractAuthParameters('asd.{model}.{nonModel}', 'asd.1.something', 123);
+ $this->broadcaster->extractAuthParameters('asd.{model}.{nonModel}', 'asd.1.something', 123);
}
public function testCanRegisterChannelsAsClasses()
{
- $broadcaster = new FakeBroadcaster;
-
- $broadcaster->channel('something', function () {
+ $this->broadcaster->channel('something', function () {
});
- $broadcaster->channel('somethingelse', DummyBroadcastingChannel::class);
+ $this->broadcaster->channel('somethingelse', DummyBroadcastingChannel::class);
}
/**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
*/
public function testNotFoundThrowsHttpException()
{
- $broadcaster = new FakeBroadcaster;
$callback = function ($user, BroadcasterTestEloquentModelNotFoundStub $model) {
};
- $broadcaster->extractAuthParameters('asd.{model}', 'asd.1', $callback);
+ $this->broadcaster->extractAuthParameters('asd.{model}', 'asd.1', $callback);
}
public function testCanRegisterChannelsWithoutOptions()
{
- $broadcaster = new FakeBroadcaster;
-
- $broadcaster->channel('somechannel', function () {});
+ $this->broadcaster->channel('somechannel', function () {});
}
public function testCanRegisterChannelsWithOptions()
{
- $broadcaster = new FakeBroadcaster;
-
$options = [ 'a' => [ 'b', 'c' ] ];
- $broadcaster->channel('somechannel', function () {}, $options);
+ $this->broadcaster->channel('somechannel', function () {}, $options);
}
public function testCanRetrieveChannelsOptions()
{
- $broadcaster = new FakeBroadcaster;
-
$options = [ 'a' => [ 'b', 'c' ] ];
- $broadcaster->channel('somechannel', function () {}, $options);
+ $this->broadcaster->channel('somechannel', function () {}, $options);
$this->assertEquals(
$options,
- $broadcaster->retrieveChannelOptions('somechannel')
+ $this->broadcaster->retrieveChannelOptions('somechannel')
);
}
public function testCanRetrieveChannelsOptionsUsingAChannelNameContainingArgs()
{
- $broadcaster = new FakeBroadcaster;
-
$options = [ 'a' => [ 'b', 'c' ] ];
- $broadcaster->channel('somechannel.{id}.test.{text}', function () {}, $options);
+ $this->broadcaster->channel('somechannel.{id}.test.{text}', function () {}, $options);
$this->assertEquals(
$options,
- $broadcaster->retrieveChannelOptions('somechannel.23.test.mytext')
+ $this->broadcaster->retrieveChannelOptions('somechannel.23.test.mytext')
);
}
public function testCanRetrieveChannelsOptionsWhenMultipleChannelsAreRegistered()
{
- $broadcaster = new FakeBroadcaster;
-
$options = [ 'a' => [ 'b', 'c' ] ];
- $broadcaster->channel('somechannel', function () {});
- $broadcaster->channel('someotherchannel', function () {}, $options);
+ $this->broadcaster->channel('somechannel', function () {});
+ $this->broadcaster->channel('someotherchannel', function () {}, $options);
$this->assertEquals(
$options,
- $broadcaster->retrieveChannelOptions('someotherchannel')
+ $this->broadcaster->retrieveChannelOptions('someotherchannel')
);
}
public function testDontRetrieveChannelsOptionsWhenChannelDoesntExists()
{
- $broadcaster = new FakeBroadcaster;
-
$options = [ 'a' => [ 'b', 'c' ] ];
- $broadcaster->channel('somechannel', function () {}, $options);
+ $this->broadcaster->channel('somechannel', function () {}, $options);
$this->assertEquals(
[],
- $broadcaster->retrieveChannelOptions('someotherchannel')
+ $this->broadcaster->retrieveChannelOptions('someotherchannel')
);
}
public function testRetrieveUserWithoutGuard()
{
- $broadcaster = new FakeBroadcaster;
-
- $broadcaster->channel('somechannel', function () {});
+ $this->broadcaster->channel('somechannel', function () {});
$request = m::mock(\Illuminate\Http\Request::class);
$request->shouldReceive('user')
@@ -177,15 +166,13 @@ public function testRetrieveUserWithoutGuard()
$this->assertInstanceOf(
DummyUser::class,
- $broadcaster->retrieveUser($request, 'somechannel')
+ $this->broadcaster->retrieveUser($request, 'somechannel')
);
}
public function testRetrieveUserWithOneGuardUsingAStringForSpecifyingGuard()
{
- $broadcaster = new FakeBroadcaster;
-
- $broadcaster->channel('somechannel', function () {}, ['guards' => 'myguard']);
+ $this->broadcaster->channel('somechannel', function () {}, ['guards' => 'myguard']);
$request = m::mock(\Illuminate\Http\Request::class);
$request->shouldReceive('user')
@@ -195,16 +182,14 @@ public function testRetrieveUserWithOneGuardUsingAStringForSpecifyingGuard()
$this->assertInstanceOf(
DummyUser::class,
- $broadcaster->retrieveUser($request, 'somechannel')
+ $this->broadcaster->retrieveUser($request, 'somechannel')
);
}
public function testRetrieveUserWithMultipleGuardsAndRespectGuardsOrder()
{
- $broadcaster = new FakeBroadcaster;
-
- $broadcaster->channel('somechannel', function () {}, ['guards' => ['myguard1', 'myguard2']]);
- $broadcaster->channel('someotherchannel', function () {}, ['guards' => ['myguard2', 'myguard1']]);
+ $this->broadcaster->channel('somechannel', function () {}, ['guards' => ['myguard1', 'myguard2']]);
+ $this->broadcaster->channel('someotherchannel', function () {}, ['guards' => ['myguard2', 'myguard1']]);
$request = m::mock(\Illuminate\Http\Request::class);
@@ -220,20 +205,18 @@ public function testRetrieveUserWithMultipleGuardsAndRespectGuardsOrder()
$this->assertInstanceOf(
DummyUser::class,
- $broadcaster->retrieveUser($request, 'somechannel')
+ $this->broadcaster->retrieveUser($request, 'somechannel')
);
$this->assertInstanceOf(
DummyUser::class,
- $broadcaster->retrieveUser($request, 'someotherchannel')
+ $this->broadcaster->retrieveUser($request, 'someotherchannel')
);
}
public function testRetrieveUserDontUseDefaultGuardWhenOneGuardSpecified()
{
- $broadcaster = new FakeBroadcaster;
-
- $broadcaster->channel('somechannel', function () {}, ['guards' => 'myguard']);
+ $this->broadcaster->channel('somechannel', function () {}, ['guards' => 'myguard']);
$request = m::mock(\Illuminate\Http\Request::class);
$request->shouldReceive('user')
@@ -243,15 +226,12 @@ public function testRetrieveUserDontUseDefaultGuardWhenOneGuardSpecified()
$request->shouldNotReceive('user')
->withNoArgs();
- $broadcaster->retrieveUser($request, 'somechannel');
+ $this->broadcaster->retrieveUser($request, 'somechannel');
}
public function testRetrieveUserDontUseDefaultGuardWhenMultipleGuardsSpecified()
{
- $broadcaster = new FakeBroadcaster;
-
- $broadcaster->channel('somechannel', function () {}, ['guards' => ['myguard1', 'myguard2']]);
-
+ $this->broadcaster->channel('somechannel', function () {}, ['guards' => ['myguard1', 'myguard2']]);
$request = m::mock(\Illuminate\Http\Request::class);
$request->shouldReceive('user')
@@ -265,17 +245,15 @@ public function testRetrieveUserDontUseDefaultGuardWhenMultipleGuardsSpecified()
$request->shouldNotReceive('user')
->withNoArgs();
- $broadcaster->retrieveUser($request, 'somechannel');
+ $this->broadcaster->retrieveUser($request, 'somechannel');
}
/**
* @dataProvider channelNameMatchPatternProvider
*/
public function testChannelNameMatchPattern($channel, $pattern, $shouldMatch)
{
- $broadcaster = new FakeBroadcaster;
-
- $this->assertEquals($shouldMatch, $broadcaster->channelNameMatchPattern($channel, $pattern));
+ $this->assertEquals($shouldMatch, $this->broadcaster->channelNameMatchPattern($channel, $pattern));
}
public function channelNameMatchPatternProvider() { | false |
Other | laravel | framework | 304de5fc046c16eb08ab1415cc7755981ac1f3cb.json | Add tests for method retrieveChannelsOptions | tests/Broadcasting/BroadcasterTest.php | @@ -108,13 +108,61 @@ public function testCanRegisterChannelsWithOptions()
$options = [ 'a' => [ 'b', 'c' ] ];
$broadcaster->channel('somechannel', function () {}, $options);
+ }
+
+ public function testCanRetrieveChannelsOptions()
+ {
+ $broadcaster = new FakeBroadcaster;
+
+ $options = [ 'a' => [ 'b', 'c' ] ];
+ $broadcaster->channel('somechannel', function () {}, $options);
$this->assertEquals(
$options,
$broadcaster->retrieveChannelOptions('somechannel')
);
}
+ public function testCanRetrieveChannelsOptionsUsingAChannelNameContainingArgs()
+ {
+ $broadcaster = new FakeBroadcaster;
+
+ $options = [ 'a' => [ 'b', 'c' ] ];
+ $broadcaster->channel('somechannel.{id}.test.{text}', function () {}, $options);
+
+ $this->assertEquals(
+ $options,
+ $broadcaster->retrieveChannelOptions('somechannel.23.test.mytext')
+ );
+ }
+
+ public function testCanRetrieveChannelsOptionsWhenMultipleChannelsAreRegistered()
+ {
+ $broadcaster = new FakeBroadcaster;
+
+ $options = [ 'a' => [ 'b', 'c' ] ];
+ $broadcaster->channel('somechannel', function () {});
+ $broadcaster->channel('someotherchannel', function () {}, $options);
+
+ $this->assertEquals(
+ $options,
+ $broadcaster->retrieveChannelOptions('someotherchannel')
+ );
+ }
+
+ public function testDontRetrieveChannelsOptionsWhenChannelDoesntExists()
+ {
+ $broadcaster = new FakeBroadcaster;
+
+ $options = [ 'a' => [ 'b', 'c' ] ];
+ $broadcaster->channel('somechannel', function () {}, $options);
+
+ $this->assertEquals(
+ [],
+ $broadcaster->retrieveChannelOptions('someotherchannel')
+ );
+ }
+
public function testRetrieveUserWithoutGuard()
{
$broadcaster = new FakeBroadcaster; | false |
Other | laravel | framework | cdcb9e28205e1bd9104a79335619652772533f18.json | Add a test class for trait UsePusherChannelsNames | tests/Broadcasting/PusherBroadcasterTest.php | @@ -23,28 +23,6 @@ public function setUp()
$this->broadcaster = m::mock(PusherBroadcaster::class, [$this->pusher])->makePartial();
}
- /**
- * @dataProvider channelsProvider
- */
- public function testChannelNameNormalization($requestChannelName, $normalizedName)
- {
- $this->assertEquals(
- $normalizedName,
- $this->broadcaster->normalizeChannelName($requestChannelName)
- );
- }
-
- /**
- * @dataProvider channelsProvider
- */
- public function testIsGuardedChannel($requestChannelName, $_, $guarded)
- {
- $this->assertEquals(
- $guarded,
- $this->broadcaster->isGuardedChannel($requestChannelName)
- );
- }
-
public function testAuthCallValidAuthenticationResponseWithPrivateChannelWhenCallbackReturnTrue()
{
$this->broadcaster->channel('test', function() {
@@ -170,48 +148,6 @@ public function testValidAuthenticationResponseCallPusherPresenceAuthMethodWithP
);
}
- public function channelsProvider()
- {
- $prefixesInfos = [
- ['prefix' => 'private-', 'guarded' => true],
- ['prefix' => 'presence-', 'guarded' => true],
- ['prefix' => '', 'guarded' => false],
- ];
-
- $channels = [
- 'test',
- 'test-channel',
- 'test-private-channel',
- 'test-presence-channel',
- 'abcd.efgh',
- 'abcd.efgh.ijkl',
- 'test.{param}',
- 'test-{param}',
- '{a}.{b}',
- '{a}-{b}',
- '{a}-{b}.{c}',
- ];
-
- $tests = [];
- foreach ($prefixesInfos as $prefixInfos) {
- foreach ($channels as $channel) {
- $tests[] = [
- $prefixInfos['prefix'] . $channel,
- $channel,
- $prefixInfos['guarded'],
- ];
- }
- }
-
- $tests[] = ['private-private-test' , 'private-test', true];
- $tests[] = ['private-presence-test' , 'presence-test', true];
- $tests[] = ['presence-private-test' , 'private-test', true];
- $tests[] = ['presence-presence-test' , 'presence-test', true];
- $tests[] = ['public-test' , 'public-test', false];
-
- return $tests;
- }
-
/**
* @param string $channel
* @return \Illuminate\Http\Request | true |
Other | laravel | framework | cdcb9e28205e1bd9104a79335619652772533f18.json | Add a test class for trait UsePusherChannelsNames | tests/Broadcasting/RedisBroadcasterTest.php | @@ -25,28 +25,6 @@ public function tearDown()
m::close();
}
- /**
- * @dataProvider channelsProvider
- */
- public function testChannelNameNormalization($requestChannelName, $normalizedName)
- {
- $this->assertEquals(
- $normalizedName,
- $this->broadcaster->normalizeChannelName($requestChannelName)
- );
- }
-
- /**
- * @dataProvider channelsProvider
- */
- public function testIsGuardedChannel($requestChannelName, $_, $guarded)
- {
- $this->assertEquals(
- $guarded,
- $this->broadcaster->isGuardedChannel($requestChannelName)
- );
- }
-
public function testAuthCallValidAuthenticationResponseWithPrivateChannelWhenCallbackReturnTrue()
{
$this->broadcaster->channel('test', function() {
@@ -163,48 +141,6 @@ public function testValidAuthenticationResponseWithPresenceChannel()
);
}
- public function channelsProvider()
- {
- $prefixesInfos = [
- ['prefix' => 'private-', 'guarded' => true],
- ['prefix' => 'presence-', 'guarded' => true],
- ['prefix' => '', 'guarded' => false],
- ];
-
- $channels = [
- 'test',
- 'test-channel',
- 'test-private-channel',
- 'test-presence-channel',
- 'abcd.efgh',
- 'abcd.efgh.ijkl',
- 'test.{param}',
- 'test-{param}',
- '{a}.{b}',
- '{a}-{b}',
- '{a}-{b}.{c}',
- ];
-
- $tests = [];
- foreach ($prefixesInfos as $prefixInfos) {
- foreach ($channels as $channel) {
- $tests[] = [
- $prefixInfos['prefix'] . $channel,
- $channel,
- $prefixInfos['guarded'],
- ];
- }
- }
-
- $tests[] = ['private-private-test' , 'private-test', true];
- $tests[] = ['private-presence-test' , 'presence-test', true];
- $tests[] = ['presence-private-test' , 'private-test', true];
- $tests[] = ['presence-presence-test' , 'presence-test', true];
- $tests[] = ['public-test' , 'public-test', false];
-
- return $tests;
- }
-
/**
* @param string $channel
* @return \Illuminate\Http\Request | true |
Other | laravel | framework | cdcb9e28205e1bd9104a79335619652772533f18.json | Add a test class for trait UsePusherChannelsNames | tests/Broadcasting/UsePusherChannelsNamesTest.php | @@ -0,0 +1,109 @@
+<?php
+
+namespace Illuminate\Tests\Broadcasting;
+
+use Illuminate\Broadcasting\Broadcasters\Broadcaster;
+use Illuminate\Broadcasting\Broadcasters\UsePusherChannelsNames;
+use Mockery as m;
+use PHPUnit\Framework\TestCase;
+
+class UsePusherChannelsNamesTest extends TestCase
+{
+ /**
+ * @var \Illuminate\Broadcasting\Broadcasters\RedisBroadcaster
+ */
+ public $broadcaster;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->broadcaster = new FakeBroadcasterUsingPusherChannelsNames();
+ }
+
+ public function tearDown()
+ {
+ m::close();
+ }
+
+ /**
+ * @dataProvider channelsProvider
+ */
+ public function testChannelNameNormalization($requestChannelName, $normalizedName)
+ {
+ $this->assertEquals(
+ $normalizedName,
+ $this->broadcaster->normalizeChannelName($requestChannelName)
+ );
+ }
+
+ /**
+ * @dataProvider channelsProvider
+ */
+ public function testIsGuardedChannel($requestChannelName, $_, $guarded)
+ {
+ $this->assertEquals(
+ $guarded,
+ $this->broadcaster->isGuardedChannel($requestChannelName)
+ );
+ }
+
+ public function channelsProvider()
+ {
+ $prefixesInfos = [
+ ['prefix' => 'private-', 'guarded' => true],
+ ['prefix' => 'presence-', 'guarded' => true],
+ ['prefix' => '', 'guarded' => false],
+ ];
+
+ $channels = [
+ 'test',
+ 'test-channel',
+ 'test-private-channel',
+ 'test-presence-channel',
+ 'abcd.efgh',
+ 'abcd.efgh.ijkl',
+ 'test.{param}',
+ 'test-{param}',
+ '{a}.{b}',
+ '{a}-{b}',
+ '{a}-{b}.{c}',
+ ];
+
+ $tests = [];
+ foreach ($prefixesInfos as $prefixInfos) {
+ foreach ($channels as $channel) {
+ $tests[] = [
+ $prefixInfos['prefix'] . $channel,
+ $channel,
+ $prefixInfos['guarded'],
+ ];
+ }
+ }
+
+ $tests[] = ['private-private-test' , 'private-test', true];
+ $tests[] = ['private-presence-test' , 'presence-test', true];
+ $tests[] = ['presence-private-test' , 'private-test', true];
+ $tests[] = ['presence-presence-test' , 'presence-test', true];
+ $tests[] = ['public-test' , 'public-test', false];
+
+ return $tests;
+ }
+}
+
+class FakeBroadcasterUsingPusherChannelsNames extends Broadcaster
+{
+ use UsePusherChannelsNames;
+
+ public function auth($request)
+ {
+ }
+
+ public function validAuthenticationResponse($request, $result)
+ {
+ }
+
+ public function broadcast(array $channels, $event, array $payload = [])
+ {
+ }
+} | true |
Other | laravel | framework | 30ebb1b80521efca6c65b3921bfd725d6c628b6f.json | Add trait UsePusherChannelsNames | src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php | @@ -10,6 +10,8 @@
class PusherBroadcaster extends Broadcaster
{
+ use UsePusherChannelsNames;
+
/**
* The Pusher SDK instance.
*
@@ -127,31 +129,4 @@ public function getPusher()
{
return $this->pusher;
}
-
- /**
- * Return true if channel is protected by authentication
- *
- * @param string $channel
- * @return bool
- */
- public function isGuardedChannel($channel)
- {
- return Str::startsWith($channel, ['private-', 'presence-']);
- }
-
- /**
- * Remove prefix from channel name
- *
- * @param string $channel
- * @return string
- */
- public function normalizeChannelName($channel)
- {
- if ($this->isGuardedChannel($channel)) {
- return Str::startsWith($channel, 'private-')
- ? Str::replaceFirst('private-', '', $channel)
- : Str::replaceFirst('presence-', '', $channel);
- }
- return $channel;
- }
} | true |
Other | laravel | framework | 30ebb1b80521efca6c65b3921bfd725d6c628b6f.json | Add trait UsePusherChannelsNames | src/Illuminate/Broadcasting/Broadcasters/RedisBroadcaster.php | @@ -3,12 +3,13 @@
namespace Illuminate\Broadcasting\Broadcasters;
use Illuminate\Support\Arr;
-use Illuminate\Support\Str;
use Illuminate\Contracts\Redis\Factory as Redis;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
class RedisBroadcaster extends Broadcaster
{
+ use UsePusherChannelsNames;
+
/**
* The Redis instance.
*
@@ -100,31 +101,4 @@ public function broadcast(array $channels, $event, array $payload = [])
$connection->publish($channel, $payload);
}
}
-
- /**
- * Return true if channel is protected by authentication
- *
- * @param string $channel
- * @return bool
- */
- public function isGuardedChannel($channel)
- {
- return Str::startsWith($channel, ['private-', 'presence-']);
- }
-
- /**
- * Remove prefix from channel name
- *
- * @param string $channel
- * @return string
- */
- public function normalizeChannelName($channel)
- {
- if ($this->isGuardedChannel($channel)) {
- return Str::startsWith($channel, 'private-')
- ? Str::replaceFirst('private-', '', $channel)
- : Str::replaceFirst('presence-', '', $channel);
- }
- return $channel;
- }
} | true |
Other | laravel | framework | 30ebb1b80521efca6c65b3921bfd725d6c628b6f.json | Add trait UsePusherChannelsNames | src/Illuminate/Broadcasting/Broadcasters/UsePusherChannelsNames.php | @@ -0,0 +1,35 @@
+<?php
+
+namespace Illuminate\Broadcasting\Broadcasters;
+
+use Illuminate\Support\Str;
+
+trait UsePusherChannelsNames
+{
+ /**
+ * Return true if channel is protected by authentication
+ *
+ * @param string $channel
+ * @return bool
+ */
+ public function isGuardedChannel($channel)
+ {
+ return Str::startsWith($channel, ['private-', 'presence-']);
+ }
+
+ /**
+ * Remove prefix from channel name
+ *
+ * @param string $channel
+ * @return string
+ */
+ public function normalizeChannelName($channel)
+ {
+ if ($this->isGuardedChannel($channel)) {
+ return Str::startsWith($channel, 'private-')
+ ? Str::replaceFirst('private-', '', $channel)
+ : Str::replaceFirst('presence-', '', $channel);
+ }
+ return $channel;
+ }
+} | true |
Other | laravel | framework | 7bc1103a127d26442e60e343abf34bb6f6857f99.json | Fix multiple notification recipients (#24957)
* Fix multiple notification recipients
PR #24606 unfortunately broke on-demand notifications addressed to multiple recipients.
This fixes Issue #24729 and #24956
* Added test for multiple mail recipients.
* Remove unnecessary spaces. | src/Illuminate/Notifications/Channels/MailChannel.php | @@ -186,7 +186,7 @@ protected function getRecipients($notifiable, $notification, $message)
return collect($recipients)->mapWithKeys(function ($recipient, $email) {
return is_numeric($email)
- ? [(is_string($recipient) ? $recipient : $recipient->email)]
+ ? [$email => (is_string($recipient) ? $recipient : $recipient->email)]
: [$email => $recipient];
})->all();
} | true |
Other | laravel | framework | 7bc1103a127d26442e60e343abf34bb6f6857f99.json | Fix multiple notification recipients (#24957)
* Fix multiple notification recipients
PR #24606 unfortunately broke on-demand notifications addressed to multiple recipients.
This fixes Issue #24729 and #24956
* Added test for multiple mail recipients.
* Remove unnecessary spaces. | tests/Integration/Notifications/SendingMailNotificationsTest.php | @@ -174,6 +174,36 @@ public function test_mail_is_sent_with_subject()
$user->notify($notification);
}
+ public function test_mail_is_sent_to_multiple_adresses()
+ {
+ $notification = new TestMailNotificationWithSubject;
+
+ $user = NotifiableUserWithMultipleAddreses::forceCreate([
+ 'email' => 'taylor@laravel.com',
+ ]);
+
+ $this->markdown->shouldReceive('render')->once()->andReturn('htmlContent');
+ $this->markdown->shouldReceive('renderText')->once()->andReturn('textContent');
+
+ $this->mailer->shouldReceive('send')->once()->with(
+ ['html' => 'htmlContent', 'text' => 'textContent'],
+ $notification->toMail($user)->toArray(),
+ Mockery::on(function ($closure) {
+ $message = Mockery::mock(\Illuminate\Mail\Message::class);
+
+ $message->shouldReceive('to')->once()->with(['foo_taylor@laravel.com', 'bar_taylor@laravel.com']);
+
+ $message->shouldReceive('subject')->once()->with('mail custom subject');
+
+ $closure($message);
+
+ return true;
+ })
+ );
+
+ $user->notify($notification);
+ }
+
public function test_mail_is_sent_using_mailable()
{
$notification = new TestMailNotificationWithMailable;
@@ -205,6 +235,17 @@ public function routeNotificationForMail($notification)
}
}
+class NotifiableUserWithMultipleAddreses extends NotifiableUser
+{
+ public function routeNotificationForMail($notification)
+ {
+ return [
+ 'foo_'.$this->email,
+ 'bar_'.$this->email,
+ ];
+ }
+}
+
class TestMailNotification extends Notification
{
public function via($notifiable) | true |
Other | laravel | framework | c8682e11b9f0e153654ff5c2a3ad9f8b2dca56d1.json | Add alias for calling with single state (#24937) | src/Illuminate/Database/Eloquent/FactoryBuilder.php | @@ -117,6 +117,17 @@ public function times($amount)
return $this;
}
+ /**
+ * Set the state to be applied to the model.
+ *
+ * @param string $state
+ * @return $this
+ */
+ public function state($state)
+ {
+ return $this->states([$state]);
+ }
+
/**
* Set the states to be applied to the model.
* | true |
Other | laravel | framework | c8682e11b9f0e153654ff5c2a3ad9f8b2dca56d1.json | Add alias for calling with single state (#24937) | tests/Integration/Database/EloquentFactoryBuilderTest.php | @@ -53,7 +53,7 @@ protected function getEnvironmentSetUp($app)
$factory->afterMakingState(FactoryBuildableUser::class, 'with_callable_server', function (FactoryBuildableUser $user, Generator $faker) {
$server = factory(FactoryBuildableServer::class)
- ->states('callable')
+ ->state('callable')
->make(['user_id' => $user->id]);
$user->servers->push($server);
@@ -91,7 +91,7 @@ protected function getEnvironmentSetUp($app)
$factory->afterCreatingState(FactoryBuildableUser::class, 'with_callable_server', function (FactoryBuildableUser $user, Generator $faker) {
$server = factory(FactoryBuildableServer::class)
- ->states('callable')
+ ->state('callable')
->create(['user_id' => $user->id]);
});
@@ -186,11 +186,11 @@ public function creating_collection_of_models()
/**
* @test
*/
- public function creating_models_with_callable_states()
+ public function creating_models_with_callable_state()
{
$server = factory(FactoryBuildableServer::class)->create();
- $callableServer = factory(FactoryBuildableServer::class)->states('callable')->create();
+ $callableServer = factory(FactoryBuildableServer::class)->state('callable')->create();
$this->assertEquals('active', $server->status);
$this->assertEquals(['Storage', 'Data'], $server->tags);
@@ -200,11 +200,11 @@ public function creating_models_with_callable_states()
/**
* @test
*/
- public function creating_models_with_inline_states()
+ public function creating_models_with_inline_state()
{
$server = factory(FactoryBuildableServer::class)->create();
- $inlineServer = factory(FactoryBuildableServer::class)->states('inline')->create();
+ $inlineServer = factory(FactoryBuildableServer::class)->state('inline')->create();
$this->assertEquals('active', $server->status);
$this->assertEquals('inline', $inlineServer->status);
@@ -249,9 +249,9 @@ public function creating_models_with_after_callback()
}
/** @test **/
- public function creating_models_with_after_callback_states()
+ public function creating_models_with_after_callback_state()
{
- $user = factory(FactoryBuildableUser::class)->states('with_callable_server')->create();
+ $user = factory(FactoryBuildableUser::class)->state('with_callable_server')->create();
$this->assertNotNull($user->profile);
$this->assertNotNull($user->servers->where('status', 'callable')->first());
@@ -276,9 +276,9 @@ public function making_models_with_after_callback()
}
/** @test **/
- public function making_models_with_after_callback_states()
+ public function making_models_with_after_callback_state()
{
- $user = factory(FactoryBuildableUser::class)->states('with_callable_server')->make();
+ $user = factory(FactoryBuildableUser::class)->state('with_callable_server')->make();
$this->assertNotNull($user->profile);
$this->assertNotNull($user->servers->where('status', 'callable')->first()); | true |
Other | laravel | framework | ffa5803a9dd72ca431cf4711cf636f3ba20f57db.json | Support special float values on PostgreSQL | src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php | @@ -478,7 +478,7 @@ protected function castAttribute($key, $value)
case 'real':
case 'float':
case 'double':
- return (float) $value;
+ return $this->fromFloat($value);
case 'string':
return (string) $value;
case 'bool':
@@ -692,6 +692,26 @@ public function fromJson($value, $asObject = false)
return json_decode($value, ! $asObject);
}
+ /**
+ * Cast the given float value.
+ *
+ * @param mixed $value
+ * @return mixed
+ */
+ public function fromFloat($value)
+ {
+ switch ($value) {
+ case 'Infinity':
+ return INF;
+ case '-Infinity':
+ return -INF;
+ case 'NaN':
+ return NAN;
+ default:
+ return (float) $value;
+ }
+ }
+
/**
* Return a timestamp as DateTime object with time set to 00:00:00.
* | true |
Other | laravel | framework | ffa5803a9dd72ca431cf4711cf636f3ba20f57db.json | Support special float values on PostgreSQL | tests/Database/DatabaseEloquentModelTest.php | @@ -1613,6 +1613,29 @@ public function testModelAttributeCastingFailsOnUnencodableData()
$model->getAttributes();
}
+ public function testModelAttributeCastingWithSpecialFloatValues()
+ {
+ $model = new EloquentModelCastingStub;
+
+ $model->floatAttribute = 'Infinity';
+ $this->assertEquals(INF, $model->floatAttribute);
+
+ $model->floatAttribute = INF;
+ $this->assertEquals(INF, $model->floatAttribute);
+
+ $model->floatAttribute = '-Infinity';
+ $this->assertEquals(-INF, $model->floatAttribute);
+
+ $model->floatAttribute = -INF;
+ $this->assertEquals(-INF, $model->floatAttribute);
+
+ $model->floatAttribute = 'NaN';
+ $this->assertNan($model->floatAttribute);
+
+ $model->floatAttribute = NAN;
+ $this->assertNan($model->floatAttribute);
+ }
+
public function testUpdatingNonExistentModelFails()
{
$model = new EloquentModelStub; | true |
Other | laravel | framework | 4d9e85fc4f320fce3c7c386368e00405efb46d3e.json | Add missing call to guard for Pusher | src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php | @@ -67,7 +67,7 @@ public function auth($request)
* @param mixed $result
* @return mixed
*/
- public function validAuthenticationResponse($request, $result)
+ public function validAuthenticationResponse($request, $result, $options = [])
{
if (Str::startsWith($request->channel_name, 'private')) {
return $this->decodePusherResponse(
@@ -79,7 +79,7 @@ public function validAuthenticationResponse($request, $result)
$request,
$this->pusher->presence_auth(
$request->channel_name, $request->socket_id,
- $request->user()->getAuthIdentifier(), $result
+ $request->user($options['guard'] ?? null)->getAuthIdentifier(), $result
)
);
} | false |
Other | laravel | framework | 796eb9315b2a1eaee830873ebdd4950b757fcdb1.json | Add options to RedisBroadcaster | src/Illuminate/Broadcasting/Broadcasters/RedisBroadcaster.php | @@ -45,17 +45,26 @@ public function __construct(Redis $redis, $connection = null)
*/
public function auth($request)
{
+ $channelName = Str::startsWith($request->channel_name, 'private-')
+ ? Str::replaceFirst('private-', '', $request->channel_name)
+ : Str::replaceFirst('presence-', '', $request->channel_name);
+
+ $options = [];
+ foreach ($this->channelsOptions as $pattern => $opts) {
+ if (! Str::is(preg_replace('/\{(.*?)\}/', '*', $pattern), $channelName)) {
+ continue;
+ }
+
+ $options = $opts;
+ }
+
if (Str::startsWith($request->channel_name, ['private-', 'presence-']) &&
- ! $request->user()) {
+ ! $request->user($options['guard'] ?? null)) {
throw new AccessDeniedHttpException;
}
- $channelName = Str::startsWith($request->channel_name, 'private-')
- ? Str::replaceFirst('private-', '', $request->channel_name)
- : Str::replaceFirst('presence-', '', $request->channel_name);
-
return parent::verifyUserCanAccessChannel(
- $request, $channelName
+ $request, $channelName, $options
);
}
@@ -66,14 +75,14 @@ public function auth($request)
* @param mixed $result
* @return mixed
*/
- public function validAuthenticationResponse($request, $result)
+ public function validAuthenticationResponse($request, $result, $options = [])
{
if (is_bool($result)) {
return json_encode($result);
}
return json_encode(['channel_data' => [
- 'user_id' => $request->user()->getAuthIdentifier(),
+ 'user_id' => $request->user($options['guard'] ?? null)->getAuthIdentifier(),
'user_info' => $result,
]]);
} | false |
Other | laravel | framework | 16ed752928a59e0b3003ab54675fcb3096b23d96.json | Remove options retrieving from Broadcaster | src/Illuminate/Broadcasting/Broadcasters/Broadcaster.php | @@ -59,19 +59,8 @@ public function channel($channel, $callback, array $options = [])
* @return mixed
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
*/
- protected function verifyUserCanAccessChannel($request, $channel)
+ protected function verifyUserCanAccessChannel($request, $channel, $options = [])
{
- $options = [];
-
- foreach ($this->channelsOptions as $pattern => $opts) {
- if (! Str::is(preg_replace('/\{(.*?)\}/', '*', $pattern), $channel)) {
- continue;
- }
-
- $options = $opts;
- }
-
-
foreach ($this->channels as $pattern => $callback) {
if (! Str::is(preg_replace('/\{(.*?)\}/', '*', $pattern), $channel)) {
continue;
@@ -82,7 +71,7 @@ protected function verifyUserCanAccessChannel($request, $channel)
$handler = $this->normalizeChannelHandlerToCallable($callback);
if ($result = $handler($request->user($options['guard'] ?? null), ...$parameters)) {
- return $this->validAuthenticationResponse($request, $result);
+ return $this->validAuthenticationResponse($request, $result, $options);
}
}
| false |
Other | laravel | framework | 6dd4e2bfb1cc545d2a26ecb790c78bf4c13be41c.json | add method to get contents of uploaded file
- `getContents()` checks if a file exists at the temporary upload location, and returns the contents of the file if found.
- added a test, and a file for the test | src/Illuminate/Http/UploadedFile.php | @@ -5,6 +5,7 @@
use Illuminate\Support\Arr;
use Illuminate\Container\Container;
use Illuminate\Support\Traits\Macroable;
+use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory;
use Symfony\Component\HttpFoundation\File\UploadedFile as SymfonyUploadedFile;
@@ -86,6 +87,21 @@ public function storeAs($path, $name, $options = [])
);
}
+ /**
+ * Get the contents of the uploaded file.
+ *
+ * @return bool|string
+ * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
+ */
+ public function getContents()
+ {
+ if (file_exists($this->getPathname())) {
+ return file_get_contents($this->getPathname());
+ }
+
+ throw new FileNotFoundException("File does not exist at path {$this->getPathname()}");
+ }
+
/**
* Create a new file instance from a base instance.
* | true |
Other | laravel | framework | 6dd4e2bfb1cc545d2a26ecb790c78bf4c13be41c.json | add method to get contents of uploaded file
- `getContents()` checks if a file exists at the temporary upload location, and returns the contents of the file if found.
- added a test, and a file for the test | tests/Http/HttpUploadedFileTest.php | @@ -0,0 +1,19 @@
+<?php
+
+namespace Illuminate\Tests\Http;
+
+use PHPUnit\Framework\TestCase;
+use Illuminate\Http\UploadedFile;
+
+class HttpUploadedFileTest extends TestCase
+{
+ public function testUploadedFileCanRetrieveContentsFromTextFile()
+ {
+ $file = new UploadedFile(
+ __DIR__.'/Fixtures/test.txt',
+ 'test.txt'
+ );
+
+ $this->assertEquals('This is a story about something that happened long ago when your grandfather was a child.', trim($file->getContents()));
+ }
+} | true |
Other | laravel | framework | 6dd4e2bfb1cc545d2a26ecb790c78bf4c13be41c.json | add method to get contents of uploaded file
- `getContents()` checks if a file exists at the temporary upload location, and returns the contents of the file if found.
- added a test, and a file for the test | tests/Http/fixtures/test.txt | @@ -0,0 +1 @@
+This is a story about something that happened long ago when your grandfather was a child. | true |
Other | laravel | framework | c19afaf30f67838b6b3d2da0afcbff98ff6029f3.json | Add hint to mail fake (#24911)
* Add hint to mail fake
* Style fixes | src/Illuminate/Support/Testing/Fakes/MailFake.php | @@ -36,9 +36,15 @@ public function assertSent($mailable, $callback = null)
return $this->assertSentTimes($mailable, $callback);
}
+ $message = "The expected [{$mailable}] mailable was not sent.";
+
+ if (count($this->queuedMailables) > 0) {
+ $message .= ' Did you mean to use assertQueued() instead?';
+ }
+
PHPUnit::assertTrue(
$this->sent($mailable, $callback)->count() > 0,
- "The expected [{$mailable}] mailable was not sent."
+ $message
);
}
| false |
Other | laravel | framework | 74252d15d8c22be664934b251c52ff3c98147740.json | Use func_num_args(). (#24901) | src/Illuminate/View/Concerns/ManagesComponents.php | @@ -88,7 +88,7 @@ protected function componentData($name)
*/
public function slot($name, $content = null)
{
- if (count(func_get_args()) === 2) {
+ if (func_num_args() === 2) {
$this->slots[$this->currentComponent()][$name] = $content;
} else {
if (ob_start()) { | false |
Other | laravel | framework | f912d7ba43af6f494603898ef15fca3d5b9d56e6.json | Fix typo in the observer stub | src/Illuminate/Foundation/Console/stubs/observer.stub | @@ -7,7 +7,7 @@ use NamespacedDummyModel;
class DummyClass
{
/**
- * Handle to the DocDummyModel "created" event.
+ * Handle the DocDummyModel "created" event.
*
* @param \NamespacedDummyModel $dummyModel
* @return void | false |
Other | laravel | framework | cab365a85a0fa3e4f7113390de4a5b31f64748e2.json | Fix $withCount binding problems | src/Illuminate/Database/Eloquent/Builder.php | @@ -219,9 +219,7 @@ public function whereKeyNot($id)
public function where($column, $operator = null, $value = null, $boolean = 'and')
{
if ($column instanceof Closure) {
- $query = $this->model->newQueryWithoutScopes();
-
- $column($query);
+ $column($query = $this->model->newModelQuery());
$this->query->addNestedWhereQuery($query->getQuery(), $boolean);
} else { | true |
Other | laravel | framework | cab365a85a0fa3e4f7113390de4a5b31f64748e2.json | Fix $withCount binding problems | src/Illuminate/Database/Eloquent/Model.php | @@ -526,7 +526,7 @@ public function push()
*/
public function save(array $options = [])
{
- $query = $this->newQueryWithoutScopes();
+ $query = $this->newModelQuery();
// If the "saving" event returns false we'll bail out of the save and return
// false, indicating that the save failed. This provides a chance for any
@@ -811,7 +811,7 @@ public function forceDelete()
*/
protected function performDeleteOnModel()
{
- $this->setKeysForSaveQuery($this->newQueryWithoutScopes())->delete();
+ $this->setKeysForSaveQuery($this->newModelQuery())->delete();
$this->exists = false;
}
@@ -836,6 +836,18 @@ public function newQuery()
return $this->registerGlobalScopes($this->newQueryWithoutScopes());
}
+ /**
+ * Get a new query builder that doesn't have any global scopes or eager loading.
+ *
+ * @return \Illuminate\Database\Eloquent\Builder|static
+ */
+ public function newModelQuery()
+ {
+ return $this->newEloquentBuilder(
+ $this->newBaseQueryBuilder()
+ )->setModel($this);
+ }
+
/**
* Get a new query builder with no relationships loaded.
*
@@ -870,12 +882,7 @@ public function registerGlobalScopes($builder)
*/
public function newQueryWithoutScopes()
{
- $builder = $this->newEloquentBuilder($this->newBaseQueryBuilder());
-
- // Once we have the query builders, we will set the model instances so the
- // builder can easily access any information it may need from the model
- // while it is constructing and executing various queries against it.
- return $builder->setModel($this)
+ return $this->newModelQuery()
->with($this->with)
->withCount($this->withCount);
} | true |
Other | laravel | framework | cab365a85a0fa3e4f7113390de4a5b31f64748e2.json | Fix $withCount binding problems | src/Illuminate/Database/Eloquent/SoftDeletes.php | @@ -47,7 +47,7 @@ protected function performDeleteOnModel()
if ($this->forceDeleting) {
$this->exists = false;
- return $this->newQueryWithoutScopes()->where($this->getKeyName(), $this->getKey())->forceDelete();
+ return $this->newModelQuery()->where($this->getKeyName(), $this->getKey())->forceDelete();
}
return $this->runSoftDelete();
@@ -60,7 +60,7 @@ protected function performDeleteOnModel()
*/
protected function runSoftDelete()
{
- $query = $this->newQueryWithoutScopes()->where($this->getKeyName(), $this->getKey());
+ $query = $this->newModelQuery()->where($this->getKeyName(), $this->getKey());
$time = $this->freshTimestamp();
| true |
Other | laravel | framework | cab365a85a0fa3e4f7113390de4a5b31f64748e2.json | Fix $withCount binding problems | tests/Database/DatabaseEloquentBuilderTest.php | @@ -575,7 +575,7 @@ public function testNestedWhere()
$nestedRawQuery = $this->getMockQueryBuilder();
$nestedQuery->shouldReceive('getQuery')->once()->andReturn($nestedRawQuery);
$model = $this->getMockModel()->makePartial();
- $model->shouldReceive('newQueryWithoutScopes')->once()->andReturn($nestedQuery);
+ $model->shouldReceive('newModelQuery')->once()->andReturn($nestedQuery);
$builder = $this->getBuilder();
$builder->getQuery()->shouldReceive('from');
$builder->setModel($model); | true |
Other | laravel | framework | cab365a85a0fa3e4f7113390de4a5b31f64748e2.json | Fix $withCount binding problems | tests/Database/DatabaseEloquentModelTest.php | @@ -227,11 +227,11 @@ public function testWithMethodCallsQueryBuilderCorrectlyWithArray()
public function testUpdateProcess()
{
- $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps'])->getMock();
+ $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newModelQuery', 'updateTimestamps'])->getMock();
$query = m::mock('Illuminate\Database\Eloquent\Builder');
$query->shouldReceive('where')->once()->with('id', '=', 1);
$query->shouldReceive('update')->once()->with(['name' => 'taylor'])->andReturn(1);
- $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
$model->expects($this->once())->method('updateTimestamps');
$model->setEventDispatcher($events = m::mock('Illuminate\Contracts\Events\Dispatcher'));
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(true);
@@ -250,11 +250,11 @@ public function testUpdateProcess()
public function testUpdateProcessDoesntOverrideTimestamps()
{
- $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes'])->getMock();
+ $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newModelQuery'])->getMock();
$query = m::mock('Illuminate\Database\Eloquent\Builder');
$query->shouldReceive('where')->once()->with('id', '=', 1);
$query->shouldReceive('update')->once()->with(['created_at' => 'foo', 'updated_at' => 'bar'])->andReturn(1);
- $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
$model->setEventDispatcher($events = m::mock('Illuminate\Contracts\Events\Dispatcher'));
$events->shouldReceive('until');
$events->shouldReceive('fire');
@@ -269,9 +269,9 @@ public function testUpdateProcessDoesntOverrideTimestamps()
public function testSaveIsCancelledIfSavingEventReturnsFalse()
{
- $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes'])->getMock();
+ $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newModelQuery'])->getMock();
$query = m::mock('Illuminate\Database\Eloquent\Builder');
- $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
$model->setEventDispatcher($events = m::mock('Illuminate\Contracts\Events\Dispatcher'));
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(false);
$model->exists = true;
@@ -281,9 +281,9 @@ public function testSaveIsCancelledIfSavingEventReturnsFalse()
public function testUpdateIsCancelledIfUpdatingEventReturnsFalse()
{
- $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes'])->getMock();
+ $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newModelQuery'])->getMock();
$query = m::mock('Illuminate\Database\Eloquent\Builder');
- $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
$model->setEventDispatcher($events = m::mock('Illuminate\Contracts\Events\Dispatcher'));
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(true);
$events->shouldReceive('until')->once()->with('eloquent.updating: '.get_class($model), $model)->andReturn(false);
@@ -295,9 +295,9 @@ public function testUpdateIsCancelledIfUpdatingEventReturnsFalse()
public function testEventsCanBeFiredWithCustomEventObjects()
{
- $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelEventObjectStub')->setMethods(['newQueryWithoutScopes'])->getMock();
+ $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelEventObjectStub')->setMethods(['newModelQuery'])->getMock();
$query = m::mock('Illuminate\Database\Eloquent\Builder');
- $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
$model->setEventDispatcher($events = m::mock('Illuminate\Contracts\Events\Dispatcher'));
$events->shouldReceive('until')->once()->with(m::type(EloquentModelSavingEventStub::class))->andReturn(false);
$model->exists = true;
@@ -307,12 +307,12 @@ public function testEventsCanBeFiredWithCustomEventObjects()
public function testUpdateProcessWithoutTimestamps()
{
- $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelEventObjectStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'fireModelEvent'])->getMock();
+ $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelEventObjectStub')->setMethods(['newModelQuery', 'updateTimestamps', 'fireModelEvent'])->getMock();
$model->timestamps = false;
$query = m::mock('Illuminate\Database\Eloquent\Builder');
$query->shouldReceive('where')->once()->with('id', '=', 1);
$query->shouldReceive('update')->once()->with(['name' => 'taylor'])->andReturn(1);
- $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
$model->expects($this->never())->method('updateTimestamps');
$model->expects($this->any())->method('fireModelEvent')->will($this->returnValue(true));
@@ -325,11 +325,11 @@ public function testUpdateProcessWithoutTimestamps()
public function testUpdateUsesOldPrimaryKey()
{
- $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps'])->getMock();
+ $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newModelQuery', 'updateTimestamps'])->getMock();
$query = m::mock('Illuminate\Database\Eloquent\Builder');
$query->shouldReceive('where')->once()->with('id', '=', 1);
$query->shouldReceive('update')->once()->with(['id' => 2, 'foo' => 'bar'])->andReturn(1);
- $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
$model->expects($this->once())->method('updateTimestamps');
$model->setEventDispatcher($events = m::mock('Illuminate\Contracts\Events\Dispatcher'));
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(true);
@@ -456,11 +456,11 @@ public function testFromDateTime()
public function testInsertProcess()
{
- $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock();
+ $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newModelQuery', 'updateTimestamps', 'refresh'])->getMock();
$query = m::mock('Illuminate\Database\Eloquent\Builder');
$query->shouldReceive('insertGetId')->once()->with(['name' => 'taylor'], 'id')->andReturn(1);
$query->shouldReceive('getConnection')->once();
- $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
$model->expects($this->once())->method('updateTimestamps');
$model->setEventDispatcher($events = m::mock('Illuminate\Contracts\Events\Dispatcher'));
@@ -475,11 +475,11 @@ public function testInsertProcess()
$this->assertEquals(1, $model->id);
$this->assertTrue($model->exists);
- $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock();
+ $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newModelQuery', 'updateTimestamps', 'refresh'])->getMock();
$query = m::mock('Illuminate\Database\Eloquent\Builder');
$query->shouldReceive('insert')->once()->with(['name' => 'taylor']);
$query->shouldReceive('getConnection')->once();
- $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
$model->expects($this->once())->method('updateTimestamps');
$model->setIncrementing(false);
@@ -498,10 +498,10 @@ public function testInsertProcess()
public function testInsertIsCancelledIfCreatingEventReturnsFalse()
{
- $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes'])->getMock();
+ $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newModelQuery'])->getMock();
$query = m::mock('Illuminate\Database\Eloquent\Builder');
$query->shouldReceive('getConnection')->once();
- $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
$model->setEventDispatcher($events = m::mock('Illuminate\Contracts\Events\Dispatcher'));
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(true);
$events->shouldReceive('until')->once()->with('eloquent.creating: '.get_class($model), $model)->andReturn(false);
@@ -512,11 +512,11 @@ public function testInsertIsCancelledIfCreatingEventReturnsFalse()
public function testDeleteProperlyDeletesModel()
{
- $model = $this->getMockBuilder('Illuminate\Database\Eloquent\Model')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'touchOwners'])->getMock();
+ $model = $this->getMockBuilder('Illuminate\Database\Eloquent\Model')->setMethods(['newModelQuery', 'updateTimestamps', 'touchOwners'])->getMock();
$query = m::mock('Illuminate\Database\Eloquent\Builder');
$query->shouldReceive('where')->once()->with('id', '=', 1)->andReturn($query);
$query->shouldReceive('delete')->once();
- $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
$model->expects($this->once())->method('touchOwners');
$model->exists = true;
$model->id = 1;
@@ -525,11 +525,11 @@ public function testDeleteProperlyDeletesModel()
public function testPushNoRelations()
{
- $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock();
+ $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newModelQuery', 'updateTimestamps', 'refresh'])->getMock();
$query = m::mock('Illuminate\Database\Eloquent\Builder');
$query->shouldReceive('insertGetId')->once()->with(['name' => 'taylor'], 'id')->andReturn(1);
$query->shouldReceive('getConnection')->once();
- $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
$model->expects($this->once())->method('updateTimestamps');
$model->name = 'taylor';
@@ -542,11 +542,11 @@ public function testPushNoRelations()
public function testPushEmptyOneRelation()
{
- $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock();
+ $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newModelQuery', 'updateTimestamps', 'refresh'])->getMock();
$query = m::mock('Illuminate\Database\Eloquent\Builder');
$query->shouldReceive('insertGetId')->once()->with(['name' => 'taylor'], 'id')->andReturn(1);
$query->shouldReceive('getConnection')->once();
- $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
$model->expects($this->once())->method('updateTimestamps');
$model->name = 'taylor';
@@ -561,20 +561,20 @@ public function testPushEmptyOneRelation()
public function testPushOneRelation()
{
- $related1 = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock();
+ $related1 = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newModelQuery', 'updateTimestamps', 'refresh'])->getMock();
$query = m::mock('Illuminate\Database\Eloquent\Builder');
$query->shouldReceive('insertGetId')->once()->with(['name' => 'related1'], 'id')->andReturn(2);
$query->shouldReceive('getConnection')->once();
- $related1->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query));
+ $related1->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
$related1->expects($this->once())->method('updateTimestamps');
$related1->name = 'related1';
$related1->exists = false;
- $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock();
+ $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newModelQuery', 'updateTimestamps', 'refresh'])->getMock();
$query = m::mock('Illuminate\Database\Eloquent\Builder');
$query->shouldReceive('insertGetId')->once()->with(['name' => 'taylor'], 'id')->andReturn(1);
$query->shouldReceive('getConnection')->once();
- $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
$model->expects($this->once())->method('updateTimestamps');
$model->name = 'taylor';
@@ -592,11 +592,11 @@ public function testPushOneRelation()
public function testPushEmptyManyRelation()
{
- $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock();
+ $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newModelQuery', 'updateTimestamps', 'refresh'])->getMock();
$query = m::mock('Illuminate\Database\Eloquent\Builder');
$query->shouldReceive('insertGetId')->once()->with(['name' => 'taylor'], 'id')->andReturn(1);
$query->shouldReceive('getConnection')->once();
- $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
$model->expects($this->once())->method('updateTimestamps');
$model->name = 'taylor';
@@ -611,29 +611,29 @@ public function testPushEmptyManyRelation()
public function testPushManyRelation()
{
- $related1 = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock();
+ $related1 = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newModelQuery', 'updateTimestamps', 'refresh'])->getMock();
$query = m::mock('Illuminate\Database\Eloquent\Builder');
$query->shouldReceive('insertGetId')->once()->with(['name' => 'related1'], 'id')->andReturn(2);
$query->shouldReceive('getConnection')->once();
- $related1->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query));
+ $related1->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
$related1->expects($this->once())->method('updateTimestamps');
$related1->name = 'related1';
$related1->exists = false;
- $related2 = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock();
+ $related2 = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newModelQuery', 'updateTimestamps', 'refresh'])->getMock();
$query = m::mock('Illuminate\Database\Eloquent\Builder');
$query->shouldReceive('insertGetId')->once()->with(['name' => 'related2'], 'id')->andReturn(3);
$query->shouldReceive('getConnection')->once();
- $related2->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query));
+ $related2->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
$related2->expects($this->once())->method('updateTimestamps');
$related2->name = 'related2';
$related2->exists = false;
- $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock();
+ $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newModelQuery', 'updateTimestamps', 'refresh'])->getMock();
$query = m::mock('Illuminate\Database\Eloquent\Builder');
$query->shouldReceive('insertGetId')->once()->with(['name' => 'taylor'], 'id')->andReturn(1);
$query->shouldReceive('getConnection')->once();
- $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
$model->expects($this->once())->method('updateTimestamps');
$model->name = 'taylor';
@@ -1619,23 +1619,23 @@ public function testNonExistingAttributeWithInternalMethodNameDoesntCallMethod()
public function testIntKeyTypePreserved()
{
- $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock();
+ $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newModelQuery', 'updateTimestamps', 'refresh'])->getMock();
$query = m::mock('Illuminate\Database\Eloquent\Builder');
$query->shouldReceive('insertGetId')->once()->with([], 'id')->andReturn(1);
$query->shouldReceive('getConnection')->once();
- $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
$this->assertTrue($model->save());
$this->assertEquals(1, $model->id);
}
public function testStringKeyTypePreserved()
{
- $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentKeyTypeModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock();
+ $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentKeyTypeModelStub')->setMethods(['newModelQuery', 'updateTimestamps', 'refresh'])->getMock();
$query = m::mock('Illuminate\Database\Eloquent\Builder');
$query->shouldReceive('insertGetId')->once()->with([], 'id')->andReturn('string id');
$query->shouldReceive('getConnection')->once();
- $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
$this->assertTrue($model->save());
$this->assertEquals('string id', $model->id); | true |
Other | laravel | framework | cab365a85a0fa3e4f7113390de4a5b31f64748e2.json | Fix $withCount binding problems | tests/Database/DatabaseSoftDeletingTraitTest.php | @@ -17,7 +17,7 @@ public function testDeleteSetsSoftDeletedColumn()
$model = m::mock('Illuminate\Tests\Database\DatabaseSoftDeletingTraitStub');
$model->shouldDeferMissing();
// $model->shouldReceive('newQuery')->andReturn($query = m::mock('stdClass'));
- $model->shouldReceive('newQueryWithoutScopes')->andReturn($query = m::mock('stdClass'));
+ $model->shouldReceive('newModelQuery')->andReturn($query = m::mock('stdClass'));
$query->shouldReceive('where')->once()->with('id', 1)->andReturn($query);
$query->shouldReceive('update')->once()->with([
'deleted_at' => 'date-time', | true |
Other | laravel | framework | a451a2bacc2518fa0d54b780e4324bb3be560aad.json | Add JPEG support to FileFactory::image() | src/Illuminate/Http/Testing/FileFactory.php | @@ -2,6 +2,8 @@
namespace Illuminate\Http\Testing;
+use Illuminate\Support\Str;
+
class FileFactory
{
/**
@@ -28,7 +30,9 @@ public function create($name, $kilobytes = 0)
*/
public function image($name, $width = 10, $height = 10)
{
- return new File($name, $this->generateImage($width, $height));
+ $type = Str::endsWith($name, ['.jpg', '.jpeg']) ? 'jpeg' : 'png';
+
+ return new File($name, $this->generateImage($width, $height, $type));
}
/**
@@ -38,12 +42,21 @@ public function image($name, $width = 10, $height = 10)
* @param int $height
* @return resource
*/
- protected function generateImage($width, $height)
+ protected function generateImage($width, $height, $type)
{
- return tap(tmpfile(), function ($temp) use ($width, $height) {
+ return tap(tmpfile(), function ($temp) use ($width, $height, $type) {
ob_start();
- imagepng(imagecreatetruecolor($width, $height));
+ $image = imagecreatetruecolor($width, $height);
+
+ switch ($type) {
+ case 'jpeg':
+ imagejpeg($image);
+ break;
+ case 'png':
+ imagepng($image);
+ break;
+ }
fwrite($temp, ob_get_clean());
}); | true |
Other | laravel | framework | a451a2bacc2518fa0d54b780e4324bb3be560aad.json | Add JPEG support to FileFactory::image() | tests/Http/HttpTestingFileFactoryTest.php | @@ -0,0 +1,31 @@
+<?php
+
+namespace Illuminate\Tests\Http;
+
+use PHPUnit\Framework\TestCase;
+use Illuminate\Http\Testing\FileFactory;
+
+class HttpTestingFileFactoryTest extends TestCase
+{
+ public function testImagePng()
+ {
+ $image = (new FileFactory)->image('test.png', 15, 20);
+
+ $info = getimagesize($image->getRealPath());
+
+ $this->assertSame('image/png', $info['mime']);
+ $this->assertSame(15, $info[0]);
+ $this->assertSame(20, $info[1]);
+ }
+
+ public function testImageJpeg()
+ {
+ $image = (new FileFactory)->image('test.jpeg', 15, 20);
+
+ $info = getimagesize($image->getRealPath());
+
+ $this->assertSame('image/jpeg', $info['mime']);
+ $this->assertSame(15, $info[0]);
+ $this->assertSame(20, $info[1]);
+ }
+} | true |
Other | laravel | framework | 4a9ccc9943e016e324b1df5e74dd244cd8cd5420.json | add unit tests to illustrate JSON assertion issues | tests/Foundation/FoundationTestResponseTest.php | @@ -174,6 +174,16 @@ public function testAssertJsonFragment()
$response->assertJsonFragment(['foobar' => ['foobar_foo' => 'foo', 'foobar_bar' => 'bar']]);
$response->assertJsonFragment(['foo' => 'bar 0', 'bar' => ['foo' => 'bar 0', 'bar' => 'foo 0']]);
+
+ $response = TestResponse::fromBaseResponse(new Response(new JsonSerializableSingleResourceWithIntegersStub()));
+
+ $response->assertJsonFragment(['id' => 10]);
+
+ try {
+ $response->assertJsonFragment(['id' => 1]);
+ $this->fail('Asserting id => 1, existsing in JsonSerializableSingleResourceWithIntegersStub should fail');
+ } catch (\PHPUnit\Framework\ExpectationFailedException $e) {
+ }
}
public function testAssertJsonStructure()
@@ -217,6 +227,13 @@ public function testAssertJsonCount()
$response->assertJsonCount(4);
}
+ public function testAssertJsonMissing()
+ {
+ $response = TestResponse::fromBaseResponse(new Response(new JsonSerializableSingleResourceWithIntegersStub));
+
+ $response->assertJsonMissing(['id' => 2]);
+ }
+
public function testAssertJsonMissingValidationErrors()
{
$baseResponse = tap(new Response, function ($response) {
@@ -330,3 +347,15 @@ public function jsonSerialize()
];
}
}
+
+class JsonSerializableSingleResourceWithIntegersStub implements JsonSerializable
+{
+ public function jsonSerialize()
+ {
+ return [
+ ['id' => 10, 'foo' => 'bar'],
+ ['id' => 20, 'foo' => 'bar'],
+ ['id' => 30, 'foo' => 'bar'],
+ ];
+ }
+} | false |
Other | laravel | framework | 89fc8607d0b58dabdcb198452393b898af77bbe8.json | add methods to policy stub | src/Illuminate/Foundation/Console/stubs/policy.stub | @@ -56,4 +56,28 @@ class DummyClass
{
//
}
+
+ /**
+ * Determine whether the user can restore the DocDummyModel.
+ *
+ * @param \NamespacedDummyUserModel $user
+ * @param \NamespacedDummyModel $dummyModel
+ * @return mixed
+ */
+ public function restore(DummyUser $user, DummyModel $dummyModel)
+ {
+ //
+ }
+
+ /**
+ * Determine whether the user can permanently delete the DocDummyModel.
+ *
+ * @param \NamespacedDummyUserModel $user
+ * @param \NamespacedDummyModel $dummyModel
+ * @return mixed
+ */
+ public function forceDelete(DummyUser $user, DummyModel $dummyModel)
+ {
+ //
+ }
} | false |
Other | laravel | framework | a43562b6a139887b421d1d3f3fdfc110c9a8df2b.json | add joiningTableSegment to Model | src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php | @@ -425,7 +425,7 @@ public function belongsToMany($related, $table = null, $foreignPivotKey = null,
// models using underscores in alphabetical order. The two model names
// are transformed to snake case from their default CamelCase also.
if (is_null($table)) {
- $table = $this->joiningTable($related);
+ $table = $this->joiningTable($related, $instance);
}
return $this->newBelongsToMany(
@@ -563,24 +563,36 @@ protected function guessBelongsToManyRelation()
* Get the joining table name for a many-to-many relation.
*
* @param string $related
+ * @param \Illuminate\Database\Eloquent\Model|null $instance
* @return string
*/
- public function joiningTable($related)
+ public function joiningTable($related, $instance = null)
{
// The joining table name, by convention, is simply the snake cased models
// sorted alphabetically and concatenated with an underscore, so we can
// just sort the models and join them together to get the table name.
- $models = [
- Str::snake(class_basename($related)),
- Str::snake(class_basename($this)),
+ $segments = [
+ $instance ? $instance->joiningTableSegment()
+ : Str::snake(class_basename($related)),
+ $this->joiningTableSegment(),
];
// Now that we have the model names in an array we can just sort them and
// use the implode function to join them together with an underscores,
// which is typically used by convention within the database system.
- sort($models);
+ sort($segments);
- return strtolower(implode('_', $models));
+ return strtolower(implode('_', $segments));
+ }
+
+ /**
+ * Get this model's half of the intermediate table name for belongsToMany relationships.
+ *
+ * @return string
+ */
+ public function joiningTableSegment()
+ {
+ return Str::snake(class_basename($this));
}
/** | false |
Other | laravel | framework | 2ae5872a24a71094521c06b4f682e053f9ec8fe6.json | use local configuration options | src/Illuminate/Broadcasting/BroadcastManager.php | @@ -212,13 +212,13 @@ protected function callCustomCreator(array $config)
*/
protected function createPusherDriver(array $config)
{
- $pusher = new Pusher($config['key'], $config['secret'],
- $config['app_id'], $config['options'] ?? []);
+ $pusher = new Pusher(
+ $config['key'], $config['secret'],
+ $config['app_id'], $config['options'] ?? []
+ );
- if ($this->app->make('config')->get('app.debug')) {
- $pusher->setLogger(
- $this->app->make(LoggerInterface::class)
- );
+ if ($config['log'] ?? false) {
+ $pusher->setLogger($this->app->make(LoggerInterface::class));
}
return new PusherBroadcaster($pusher); | false |
Other | laravel | framework | 8e2d32c2b6b6aff7b966abc714a391e136abb41b.json | add docblock for \BadMethodCallException (#24847) | src/Illuminate/Routing/RouteRegistrar.php | @@ -175,6 +175,8 @@ protected function compileAction($action)
* @param string $method
* @param array $parameters
* @return \Illuminate\Routing\Route|$this
+ *
+ * @throws \BadMethodCallException
*/
public function __call($method, $parameters)
{ | false |
Other | laravel | framework | b1a80f0c32e16753b5f50ec1172fdf8a8d41256e.json | add tests. extract class | src/Illuminate/Database/Console/Migrations/MigrateMakeCommand.php | @@ -84,22 +84,7 @@ public function handle()
// "create" in the name. This will allow us to provide a convenient way
// of creating migrations that create new tables for the application.
if (! $table) {
- if (preg_match('/^create_(\w+)_table$/', $name, $matches)) {
- $table = $matches[1];
-
- $create = true;
- }
- }
-
- // Next, we will attempt to guess the table name if this the migration has
- // "to", "from", "in" in the name. This will allow us to provide a convenient
- // way of creating migrations that modify tables in the application.
- if (! $table) {
- if (preg_match('/_(to|from|in)_(\w+)_table$/', $name, $matches)) {
- $table = $matches[2];
-
- $create = false;
- }
+ [$table, $create] = TableGuesser::guess($name);
}
// Now we are ready to write the migration out to disk. Once we've written | true |
Other | laravel | framework | b1a80f0c32e16753b5f50ec1172fdf8a8d41256e.json | add tests. extract class | src/Illuminate/Database/Console/Migrations/TableGuesser.php | @@ -0,0 +1,23 @@
+<?php
+
+namespace Illuminate\Database\Console\Migrations;
+
+class TableGuesser
+{
+ /**
+ * Attempt to guess the table name and "creation" status of the given migration.
+ *
+ * @param string $migration
+ * @return array
+ */
+ public static function guess($migration)
+ {
+ if (preg_match('/^create_(\w+)_table$/', $migration, $matches)) {
+ return [$matches[1], $create = true];
+ }
+
+ if (preg_match('/_(to|from|in)_(\w+)_table$/', $migration, $matches)) {
+ return [$matches[2], $create = false];
+ }
+ }
+} | true |
Other | laravel | framework | b1a80f0c32e16753b5f50ec1172fdf8a8d41256e.json | add tests. extract class | tests/Database/TableGuesserTest.php | @@ -0,0 +1,24 @@
+<?php
+
+namespace Illuminate\Tests\Database;
+
+use PHPUnit\Framework\TestCase;
+use Illuminate\Database\Console\Migrations\TableGuesser;
+
+class TableGuesserTest extends TestCase
+{
+ public function test_migration_is_properly_parsed()
+ {
+ [$table, $create] = TableGuesser::guess('create_users_table');
+ $this->assertEquals('users', $table);
+ $this->assertTrue($create);
+
+ [$table, $create] = TableGuesser::guess('add_status_column_to_users_table');
+ $this->assertEquals('users', $table);
+ $this->assertFalse($create);
+
+ [$table, $create] = TableGuesser::guess('drop_status_column_from_users_table');
+ $this->assertEquals('users', $table);
+ $this->assertFalse($create);
+ }
+} | true |
Other | laravel | framework | b343c4fd40e4c8466e205ee3347a893a0dcdb1c2.json | Remove aria-label on form tags (#24839) | src/Illuminate/Auth/Console/stubs/make/views/auth/login.stub | @@ -8,7 +8,7 @@
<div class="card-header">{{ __('Login') }}</div>
<div class="card-body">
- <form method="POST" action="{{ route('login') }}" aria-label="{{ __('Login') }}">
+ <form method="POST" action="{{ route('login') }}">
@csrf
<div class="form-group row"> | true |
Other | laravel | framework | b343c4fd40e4c8466e205ee3347a893a0dcdb1c2.json | Remove aria-label on form tags (#24839) | src/Illuminate/Auth/Console/stubs/make/views/auth/passwords/email.stub | @@ -14,7 +14,7 @@
</div>
@endif
- <form method="POST" action="{{ route('password.email') }}" aria-label="{{ __('Reset Password') }}">
+ <form method="POST" action="{{ route('password.email') }}">
@csrf
<div class="form-group row"> | true |
Other | laravel | framework | b343c4fd40e4c8466e205ee3347a893a0dcdb1c2.json | Remove aria-label on form tags (#24839) | src/Illuminate/Auth/Console/stubs/make/views/auth/passwords/reset.stub | @@ -8,7 +8,7 @@
<div class="card-header">{{ __('Reset Password') }}</div>
<div class="card-body">
- <form method="POST" action="{{ route('password.update') }}" aria-label="{{ __('Reset Password') }}">
+ <form method="POST" action="{{ route('password.update') }}">
@csrf
<input type="hidden" name="token" value="{{ $token }}"> | true |
Other | laravel | framework | b343c4fd40e4c8466e205ee3347a893a0dcdb1c2.json | Remove aria-label on form tags (#24839) | src/Illuminate/Auth/Console/stubs/make/views/auth/register.stub | @@ -8,7 +8,7 @@
<div class="card-header">{{ __('Register') }}</div>
<div class="card-body">
- <form method="POST" action="{{ route('register') }}" aria-label="{{ __('Register') }}">
+ <form method="POST" action="{{ route('register') }}">
@csrf
<div class="form-group row"> | true |
Other | laravel | framework | 18dc89b3434367946d7e62e5d684dbbae49d0431.json | Display messages during running migrator | src/Illuminate/Database/Console/Migrations/MigrateCommand.php | @@ -65,18 +65,11 @@ public function handle()
// Next, we will check to see if a path option has been defined. If it has
// we will use the path relative to the root of this installation folder
// so that migrations may be run for any path within the applications.
- $this->migrator->run($this->getMigrationPaths(), [
+ $this->migrator->setOutput($this->output)->run($this->getMigrationPaths(), [
'pretend' => $this->option('pretend'),
'step' => $this->option('step'),
]);
- // Once the migrator has run we will grab the note output and send it out to
- // the console screen, since the migrator itself functions without having
- // any instances of the OutputInterface contract passed into the class.
- foreach ($this->migrator->getNotes() as $note) {
- $this->output->writeln($note);
- }
-
// Finally, if the "seed" option has been given, we will re-run the database
// seed task to re-populate the database, which is convenient when adding
// a migration and a seed at the same time, as it is only this command. | true |
Other | laravel | framework | 18dc89b3434367946d7e62e5d684dbbae49d0431.json | Display messages during running migrator | src/Illuminate/Database/Console/Migrations/ResetCommand.php | @@ -64,16 +64,9 @@ public function handle()
return $this->comment('Migration table not found.');
}
- $this->migrator->reset(
+ $this->migrator->setOutput($this->output)->reset(
$this->getMigrationPaths(), $this->option('pretend')
);
-
- // Once the migrator has run we will grab the note output and send it out to
- // the console screen, since the migrator itself functions without having
- // any instances of the OutputInterface contract passed into the class.
- foreach ($this->migrator->getNotes() as $note) {
- $this->output->writeln($note);
- }
}
/** | true |
Other | laravel | framework | 18dc89b3434367946d7e62e5d684dbbae49d0431.json | Display messages during running migrator | src/Illuminate/Database/Console/Migrations/RollbackCommand.php | @@ -57,19 +57,12 @@ public function handle()
$this->migrator->setConnection($this->option('database'));
- $this->migrator->rollback(
+ $this->migrator->setOutput($this->output)->rollback(
$this->getMigrationPaths(), [
'pretend' => $this->option('pretend'),
'step' => (int) $this->option('step'),
]
);
-
- // Once the migrator has run we will grab the note output and send it out to
- // the console screen, since the migrator itself functions without having
- // any instances of the OutputInterface contract passed into the class.
- foreach ($this->migrator->getNotes() as $note) {
- $this->output->writeln($note);
- }
}
/** | true |
Other | laravel | framework | 18dc89b3434367946d7e62e5d684dbbae49d0431.json | Display messages during running migrator | src/Illuminate/Database/Migrations/Migrator.php | @@ -2,6 +2,7 @@
namespace Illuminate\Database\Migrations;
+use Illuminate\Console\OutputStyle;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Support\Collection;
@@ -39,18 +40,18 @@ class Migrator
protected $connection;
/**
- * The notes for the current operation.
+ * The paths to all of the migration files.
*
* @var array
*/
- protected $notes = [];
+ protected $paths = [];
/**
- * The paths to all of the migration files.
+ * The output interface implementation.
*
- * @var array
+ * @var \Illuminate\Console\OutputStyle
*/
- protected $paths = [];
+ protected $output;
/**
* Create a new migrator instance.
@@ -69,6 +70,20 @@ public function __construct(MigrationRepositoryInterface $repository,
$this->repository = $repository;
}
+ /**
+ * Set output.
+ *
+ * @param \Illuminate\Console\OutputStyle $output
+ *
+ * @return $this
+ */
+ public function setOutput(OutputStyle $output)
+ {
+ $this->output = $output;
+
+ return $this;
+ }
+
/**
* Run the pending migrations at a given path.
*
@@ -573,16 +588,6 @@ public function getFilesystem()
*/
protected function note($message)
{
- $this->notes[] = $message;
- }
-
- /**
- * Get the notes for the last operation.
- *
- * @return array
- */
- public function getNotes()
- {
- return $this->notes;
+ $this->output->writeln($message);
}
} | true |
Other | laravel | framework | 18dc89b3434367946d7e62e5d684dbbae49d0431.json | Display messages during running migrator | tests/Database/DatabaseMigrationMigrateCommandTest.php | @@ -22,6 +22,7 @@ public function testBasicMigrationsCallMigratorWithProperArguments()
$command->setLaravel($app);
$migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with(null);
+ $migrator->shouldReceive('setOutput')->once()->andReturn($migrator);
$migrator->shouldReceive('run')->once()->with([__DIR__.DIRECTORY_SEPARATOR.'migrations'], ['pretend' => false, 'step' => false]);
$migrator->shouldReceive('getNotes')->andReturn([]);
$migrator->shouldReceive('repositoryExists')->once()->andReturn(true);
@@ -38,8 +39,8 @@ public function testMigrationRepositoryCreatedWhenNecessary()
$command->setLaravel($app);
$migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with(null);
+ $migrator->shouldReceive('setOutput')->once()->andReturn($migrator);
$migrator->shouldReceive('run')->once()->with([__DIR__.DIRECTORY_SEPARATOR.'migrations'], ['pretend' => false, 'step' => false]);
- $migrator->shouldReceive('getNotes')->andReturn([]);
$migrator->shouldReceive('repositoryExists')->once()->andReturn(false);
$command->expects($this->once())->method('call')->with($this->equalTo('migrate:install'), $this->equalTo(['--database' => null]));
@@ -54,8 +55,8 @@ public function testTheCommandMayBePretended()
$command->setLaravel($app);
$migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with(null);
+ $migrator->shouldReceive('setOutput')->once()->andReturn($migrator);
$migrator->shouldReceive('run')->once()->with([__DIR__.DIRECTORY_SEPARATOR.'migrations'], ['pretend' => true, 'step' => false]);
- $migrator->shouldReceive('getNotes')->andReturn([]);
$migrator->shouldReceive('repositoryExists')->once()->andReturn(true);
$this->runCommand($command, ['--pretend' => true]);
@@ -69,8 +70,8 @@ public function testTheDatabaseMayBeSet()
$command->setLaravel($app);
$migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with('foo');
+ $migrator->shouldReceive('setOutput')->once()->andReturn($migrator);
$migrator->shouldReceive('run')->once()->with([__DIR__.DIRECTORY_SEPARATOR.'migrations'], ['pretend' => false, 'step' => false]);
- $migrator->shouldReceive('getNotes')->andReturn([]);
$migrator->shouldReceive('repositoryExists')->once()->andReturn(true);
$this->runCommand($command, ['--database' => 'foo']);
@@ -84,8 +85,8 @@ public function testStepMayBeSet()
$command->setLaravel($app);
$migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with(null);
+ $migrator->shouldReceive('setOutput')->once()->andReturn($migrator);
$migrator->shouldReceive('run')->once()->with([__DIR__.DIRECTORY_SEPARATOR.'migrations'], ['pretend' => false, 'step' => true]);
- $migrator->shouldReceive('getNotes')->andReturn([]);
$migrator->shouldReceive('repositoryExists')->once()->andReturn(true);
$this->runCommand($command, ['--step' => true]); | true |
Other | laravel | framework | 18dc89b3434367946d7e62e5d684dbbae49d0431.json | Display messages during running migrator | tests/Database/DatabaseMigrationResetCommandTest.php | @@ -23,8 +23,8 @@ public function testResetCommandCallsMigratorWithProperArguments()
$migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with(null);
$migrator->shouldReceive('repositoryExists')->once()->andReturn(true);
+ $migrator->shouldReceive('setOutput')->once()->andReturn($migrator);
$migrator->shouldReceive('reset')->once()->with([__DIR__.'/migrations'], false);
- $migrator->shouldReceive('getNotes')->andReturn([]);
$this->runCommand($command);
}
@@ -38,8 +38,8 @@ public function testResetCommandCanBePretended()
$migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with('foo');
$migrator->shouldReceive('repositoryExists')->once()->andReturn(true);
+ $migrator->shouldReceive('setOutput')->once()->andReturn($migrator);
$migrator->shouldReceive('reset')->once()->with([__DIR__.'/migrations'], true);
- $migrator->shouldReceive('getNotes')->andReturn([]);
$this->runCommand($command, ['--pretend' => true, '--database' => 'foo']);
} | true |
Other | laravel | framework | 18dc89b3434367946d7e62e5d684dbbae49d0431.json | Display messages during running migrator | tests/Database/DatabaseMigrationRollbackCommandTest.php | @@ -22,8 +22,8 @@ public function testRollbackCommandCallsMigratorWithProperArguments()
$command->setLaravel($app);
$migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with(null);
+ $migrator->shouldReceive('setOutput')->once()->andReturn($migrator);
$migrator->shouldReceive('rollback')->once()->with([__DIR__.'/migrations'], ['pretend' => false, 'step' => 0]);
- $migrator->shouldReceive('getNotes')->andReturn([]);
$this->runCommand($command);
}
@@ -36,8 +36,8 @@ public function testRollbackCommandCallsMigratorWithStepOption()
$command->setLaravel($app);
$migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with(null);
+ $migrator->shouldReceive('setOutput')->once()->andReturn($migrator);
$migrator->shouldReceive('rollback')->once()->with([__DIR__.'/migrations'], ['pretend' => false, 'step' => 2]);
- $migrator->shouldReceive('getNotes')->andReturn([]);
$this->runCommand($command, ['--step' => 2]);
}
@@ -50,8 +50,8 @@ public function testRollbackCommandCanBePretended()
$command->setLaravel($app);
$migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with('foo');
+ $migrator->shouldReceive('setOutput')->once()->andReturn($migrator);
$migrator->shouldReceive('rollback')->once()->with([__DIR__.'/migrations'], true);
- $migrator->shouldReceive('getNotes')->andReturn([]);
$this->runCommand($command, ['--pretend' => true, '--database' => 'foo']);
}
@@ -64,8 +64,8 @@ public function testRollbackCommandCanBePretendedWithStepOption()
$command->setLaravel($app);
$migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with('foo');
+ $migrator->shouldReceive('setOutput')->once()->andReturn($migrator);
$migrator->shouldReceive('rollback')->once()->with([__DIR__.'/migrations'], ['pretend' => true, 'step' => 2]);
- $migrator->shouldReceive('getNotes')->andReturn([]);
$this->runCommand($command, ['--pretend' => true, '--database' => 'foo', '--step' => 2]);
} | true |
Other | laravel | framework | 18dc89b3434367946d7e62e5d684dbbae49d0431.json | Display messages during running migrator | tests/Database/DatabaseMigratorIntegrationTest.php | @@ -3,6 +3,7 @@
namespace Illuminate\Tests\Database;
use Illuminate\Support\Str;
+use Mockery;
use PHPUnit\Framework\TestCase;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Database\Migrations\Migrator;
@@ -39,6 +40,11 @@ public function setUp()
new Filesystem
);
+ $output = Mockery::mock('\Illuminate\Console\OutputStyle');
+ $output->shouldReceive('writeln');
+
+ $this->migrator->setOutput($output);
+
if (! $repository->repositoryExists()) {
$repository->createRepository();
} | true |
Other | laravel | framework | 9a912d6f7da4d15144d73afc9213a5ef0f8db3e2.json | add merge method | src/Illuminate/Http/Resources/ConditionallyLoadsAttributes.php | @@ -28,7 +28,7 @@ protected function filter($data)
}
if (is_numeric($key) && $value instanceof MergeValue) {
- return $this->merge($data, $index, $this->filter($value->data), $numericKeys);
+ return $this->mergeData($data, $index, $this->filter($value->data), $numericKeys);
}
if ($value instanceof self && is_null($value->resource)) {
@@ -48,7 +48,7 @@ protected function filter($data)
* @param bool $numericKeys
* @return array
*/
- protected function merge($data, $index, $merge, $numericKeys)
+ protected function mergeData($data, $index, $merge, $numericKeys)
{
if ($numericKeys) {
return $this->removeMissingValues(array_merge(
@@ -101,12 +101,23 @@ protected function when($condition, $value, $default = null)
return func_num_args() === 3 ? value($default) : new MissingValue;
}
+ /**
+ * Merge a value into the array.
+ *
+ * @param mixed $value
+ * @return \Illuminate\Http\Resources\MergeValue|mixed
+ */
+ protected function merge($value)
+ {
+ return $this->mergeWhen(true, $value);
+ }
+
/**
* Merge a value based on a given condition.
*
* @param bool $condition
* @param mixed $value
- * @return \Illuminate\Http\Resources\MissingValue|mixed
+ * @return \Illuminate\Http\Resources\MergeValue|mixed
*/
protected function mergeWhen($condition, $value)
{ | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.