Skip to content

Commit

Permalink
[5.4] All tests have been namespaced (#17148)
Browse files Browse the repository at this point in the history
* Basic Composer File

* View Tests

* Validation Tests

* Translation Tests

* Support Tests

* Session Tests

* Routing Tests

* Redis Tests

* Queue Tests

* Pipeline Tests

* Pagination Tests

* Notification Tests

* Mail Tests

* Log Tests

* Http Tests

* Hashing Tests

* Foundation Tests

* Filesystem Tests

* Events Tests

* Encryption Tests

* Database Tests

* Cookie Tests

* Container Tests

* Console Tests

* Config Tests

* Cache Tests

* Bus Tests

* Broadcasting Tests

* Blade Tests

* Auth Tests

* Http Tests

* Fixed tests
  • Loading branch information
alexbowers authored and taylorotwell committed Jan 17, 2017
1 parent 40b4977 commit 75a6ef8
Show file tree
Hide file tree
Showing 213 changed files with 1,239 additions and 733 deletions.
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@
},
"autoload-dev": {
"files": [
"tests/Redis/InteractsWithRedis.php"
]
"tests/Database/stubs/MigrationCreatorFakeMigration.php"
],
"psr-4": {
"Illuminate\\Tests\\": "tests/"
}
},
"extra": {
"branch-alias": {
Expand Down
8 changes: 6 additions & 2 deletions tests/Auth/AuthAccessGateTest.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
<?php

namespace Illuminate\Tests\Auth;

use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use Illuminate\Auth\Access\Gate;
use Illuminate\Container\Container;
use Illuminate\Auth\Access\Response;
use Illuminate\Auth\Access\HandlesAuthorization;
use StdClass;

class GateTest extends TestCase
{
/**
* @expectedException \InvalidArgumentException
* @expectedException InvalidArgumentException
*/
public function test_gate_throws_exception_on_invalid_callback_type()
{
Expand Down Expand Up @@ -133,7 +137,7 @@ public function test_classes_can_be_defined_as_callbacks_using_at_notation()
{
$gate = $this->getBasicGate();

$gate->define('foo', 'AccessGateTestClass@foo');
$gate->define('foo', '\Illuminate\Tests\Auth\AccessGateTestClass@foo');

$this->assertTrue($gate->check('foo'));
}
Expand Down
5 changes: 4 additions & 1 deletion tests/Auth/AuthDatabaseTokenRepositoryTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

namespace Illuminate\Tests\Auth;

use Illuminate\Auth\Passwords\DatabaseTokenRepository;
use Mockery as m;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -103,7 +106,7 @@ public function testDeleteExpiredMethodDeletesExpiredTokens()

protected function getRepo()
{
return new Illuminate\Auth\Passwords\DatabaseTokenRepository(
return new DatabaseTokenRepository(
m::mock('Illuminate\Database\Connection'),
m::mock('Illuminate\Contracts\Hashing\Hasher'),
'table', 'key');
Expand Down
13 changes: 8 additions & 5 deletions tests/Auth/AuthDatabaseUserProviderTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

namespace Illuminate\Tests\Auth;

use Illuminate\Auth\DatabaseUserProvider;
use Mockery as m;
use PHPUnit\Framework\TestCase;

Expand All @@ -16,7 +19,7 @@ public function testRetrieveByIDReturnsUserWhenUserIsFound()
$conn->shouldReceive('table')->once()->with('foo')->andReturn($conn);
$conn->shouldReceive('find')->once()->with(1)->andReturn(['id' => 1, 'name' => 'Dayle']);
$hasher = m::mock('Illuminate\Contracts\Hashing\Hasher');
$provider = new Illuminate\Auth\DatabaseUserProvider($conn, $hasher, 'foo');
$provider = new DatabaseUserProvider($conn, $hasher, 'foo');
$user = $provider->retrieveById(1);

$this->assertInstanceOf('Illuminate\Auth\GenericUser', $user);
Expand All @@ -30,7 +33,7 @@ public function testRetrieveByIDReturnsNullWhenUserIsNotFound()
$conn->shouldReceive('table')->once()->with('foo')->andReturn($conn);
$conn->shouldReceive('find')->once()->with(1)->andReturn(null);
$hasher = m::mock('Illuminate\Contracts\Hashing\Hasher');
$provider = new Illuminate\Auth\DatabaseUserProvider($conn, $hasher, 'foo');
$provider = new DatabaseUserProvider($conn, $hasher, 'foo');
$user = $provider->retrieveById(1);

$this->assertNull($user);
Expand All @@ -43,7 +46,7 @@ public function testRetrieveByCredentialsReturnsUserWhenUserIsFound()
$conn->shouldReceive('where')->once()->with('username', 'dayle');
$conn->shouldReceive('first')->once()->andReturn(['id' => 1, 'name' => 'taylor']);
$hasher = m::mock('Illuminate\Contracts\Hashing\Hasher');
$provider = new Illuminate\Auth\DatabaseUserProvider($conn, $hasher, 'foo');
$provider = new DatabaseUserProvider($conn, $hasher, 'foo');
$user = $provider->retrieveByCredentials(['username' => 'dayle', 'password' => 'foo']);

$this->assertInstanceOf('Illuminate\Auth\GenericUser', $user);
Expand All @@ -58,7 +61,7 @@ public function testRetrieveByCredentialsReturnsNullWhenUserIsFound()
$conn->shouldReceive('where')->once()->with('username', 'dayle');
$conn->shouldReceive('first')->once()->andReturn(null);
$hasher = m::mock('Illuminate\Contracts\Hashing\Hasher');
$provider = new Illuminate\Auth\DatabaseUserProvider($conn, $hasher, 'foo');
$provider = new DatabaseUserProvider($conn, $hasher, 'foo');
$user = $provider->retrieveByCredentials(['username' => 'dayle']);

$this->assertNull($user);
Expand All @@ -69,7 +72,7 @@ public function testCredentialValidation()
$conn = m::mock('Illuminate\Database\Connection');
$hasher = m::mock('Illuminate\Contracts\Hashing\Hasher');
$hasher->shouldReceive('check')->once()->with('plain', 'hash')->andReturn(true);
$provider = new Illuminate\Auth\DatabaseUserProvider($conn, $hasher, 'foo');
$provider = new DatabaseUserProvider($conn, $hasher, 'foo');
$user = m::mock('Illuminate\Contracts\Auth\Authenticatable');
$user->shouldReceive('getAuthPassword')->once()->andReturn('hash');
$result = $provider->validateCredentials($user, ['password' => 'plain']);
Expand Down
9 changes: 6 additions & 3 deletions tests/Auth/AuthEloquentUserProviderTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

namespace Illuminate\Tests\Auth;

use Mockery as m;
use PHPUnit\Framework\TestCase;
use Illuminate\Auth\EloquentUserProvider;

class AuthEloquentUserProviderTest extends TestCase
{
Expand Down Expand Up @@ -40,7 +43,7 @@ public function testCredentialValidation()
$conn = m::mock('Illuminate\Database\Connection');
$hasher = m::mock('Illuminate\Contracts\Hashing\Hasher');
$hasher->shouldReceive('check')->once()->with('plain', 'hash')->andReturn(true);
$provider = new Illuminate\Auth\EloquentUserProvider($hasher, 'foo');
$provider = new EloquentUserProvider($hasher, 'foo');
$user = m::mock('Illuminate\Contracts\Auth\Authenticatable');
$user->shouldReceive('getAuthPassword')->once()->andReturn('hash');
$result = $provider->validateCredentials($user, ['password' => 'plain']);
Expand All @@ -51,10 +54,10 @@ public function testCredentialValidation()
public function testModelsCanBeCreated()
{
$hasher = m::mock('Illuminate\Contracts\Hashing\Hasher');
$provider = new Illuminate\Auth\EloquentUserProvider($hasher, 'EloquentProviderUserStub');
$provider = new EloquentUserProvider($hasher, 'Illuminate\Tests\Auth\EloquentProviderUserStub');
$model = $provider->createModel();

$this->assertInstanceOf('EloquentProviderUserStub', $model);
$this->assertInstanceOf('Illuminate\Tests\Auth\EloquentProviderUserStub', $model);
}

protected function getProviderMock()
Expand Down
28 changes: 15 additions & 13 deletions tests/Auth/AuthGuardTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Illuminate\Tests\Auth;

use Mockery as m;
use PHPUnit\Framework\TestCase;
use Illuminate\Auth\Events\Failed;
Expand All @@ -20,7 +22,7 @@ public function testBasicReturnsNullOnValidAttempt()
$guard = m::mock('Illuminate\Auth\SessionGuard[check,attempt]', ['default', $provider, $session]);
$guard->shouldReceive('check')->once()->andReturn(false);
$guard->shouldReceive('attempt')->once()->with(['email' => 'foo@bar.com', 'password' => 'secret'])->andReturn(true);
$request = Symfony\Component\HttpFoundation\Request::create('/', 'GET', [], [], [], ['PHP_AUTH_USER' => 'foo@bar.com', 'PHP_AUTH_PW' => 'secret']);
$request = Request::create('/', 'GET', [], [], [], ['PHP_AUTH_USER' => 'foo@bar.com', 'PHP_AUTH_PW' => 'secret']);
$guard->setRequest($request);

$guard->basic('email');
Expand All @@ -32,7 +34,7 @@ public function testBasicReturnsNullWhenAlreadyLoggedIn()
$guard = m::mock('Illuminate\Auth\SessionGuard[check]', ['default', $provider, $session]);
$guard->shouldReceive('check')->once()->andReturn(true);
$guard->shouldReceive('attempt')->never();
$request = Symfony\Component\HttpFoundation\Request::create('/', 'GET', [], [], [], ['PHP_AUTH_USER' => 'foo@bar.com', 'PHP_AUTH_PW' => 'secret']);
$request = Request::create('/', 'GET', [], [], [], ['PHP_AUTH_USER' => 'foo@bar.com', 'PHP_AUTH_PW' => 'secret']);
$guard->setRequest($request);

$guard->basic('email');
Expand All @@ -44,7 +46,7 @@ public function testBasicReturnsResponseOnFailure()
$guard = m::mock('Illuminate\Auth\SessionGuard[check,attempt]', ['default', $provider, $session]);
$guard->shouldReceive('check')->once()->andReturn(false);
$guard->shouldReceive('attempt')->once()->with(['email' => 'foo@bar.com', 'password' => 'secret'])->andReturn(false);
$request = Symfony\Component\HttpFoundation\Request::create('/', 'GET', [], [], [], ['PHP_AUTH_USER' => 'foo@bar.com', 'PHP_AUTH_PW' => 'secret']);
$request = \Symfony\Component\HttpFoundation\Request::create('/', 'GET', [], [], [], ['PHP_AUTH_USER' => 'foo@bar.com', 'PHP_AUTH_PW' => 'secret']);
$guard->setRequest($request);
$response = $guard->basic('email');

Expand All @@ -58,7 +60,7 @@ public function testBasicWithExtraConditions()
$guard = m::mock('Illuminate\Auth\SessionGuard[check,attempt]', ['default', $provider, $session]);
$guard->shouldReceive('check')->once()->andReturn(false);
$guard->shouldReceive('attempt')->once()->with(['email' => 'foo@bar.com', 'password' => 'secret', 'active' => 1])->andReturn(true);
$request = Symfony\Component\HttpFoundation\Request::create('/', 'GET', [], [], [], ['PHP_AUTH_USER' => 'foo@bar.com', 'PHP_AUTH_PW' => 'secret']);
$request = \Symfony\Component\HttpFoundation\Request::create('/', 'GET', [], [], [], ['PHP_AUTH_USER' => 'foo@bar.com', 'PHP_AUTH_PW' => 'secret']);
$guard->setRequest($request);

$guard->basic('email', ['active' => 1]);
Expand Down Expand Up @@ -261,9 +263,9 @@ public function testLogoutFiresLogoutEvent()
public function testLoginMethodQueuesCookieWhenRemembering()
{
list($session, $provider, $request, $cookie) = $this->getMocks();
$guard = new Illuminate\Auth\SessionGuard('default', $provider, $session, $request);
$guard = new \Illuminate\Auth\SessionGuard('default', $provider, $session, $request);
$guard->setCookieJar($cookie);
$foreverCookie = new Symfony\Component\HttpFoundation\Cookie($guard->getRecallerName(), 'foo');
$foreverCookie = new \Symfony\Component\HttpFoundation\Cookie($guard->getRecallerName(), 'foo');
$cookie->shouldReceive('forever')->once()->with($guard->getRecallerName(), 'foo|recaller')->andReturn($foreverCookie);
$cookie->shouldReceive('queue')->once()->with($foreverCookie);
$guard->getSession()->shouldReceive('put')->once()->with($guard->getName(), 'foo');
Expand All @@ -279,9 +281,9 @@ public function testLoginMethodQueuesCookieWhenRemembering()
public function testLoginMethodCreatesRememberTokenIfOneDoesntExist()
{
list($session, $provider, $request, $cookie) = $this->getMocks();
$guard = new Illuminate\Auth\SessionGuard('default', $provider, $session, $request);
$guard = new \Illuminate\Auth\SessionGuard('default', $provider, $session, $request);
$guard->setCookieJar($cookie);
$foreverCookie = new Symfony\Component\HttpFoundation\Cookie($guard->getRecallerName(), 'foo');
$foreverCookie = new \Symfony\Component\HttpFoundation\Cookie($guard->getRecallerName(), 'foo');
$cookie->shouldReceive('forever')->once()->andReturn($foreverCookie);
$cookie->shouldReceive('queue')->once()->with($foreverCookie);
$guard->getSession()->shouldReceive('put')->once()->with($guard->getName(), 'foo');
Expand Down Expand Up @@ -345,8 +347,8 @@ public function testUserUsesRememberCookieIfItExists()
{
$guard = $this->getGuard();
list($session, $provider, $request, $cookie) = $this->getMocks();
$request = Symfony\Component\HttpFoundation\Request::create('/', 'GET', [], [$guard->getRecallerName() => 'id|recaller']);
$guard = new Illuminate\Auth\SessionGuard('default', $provider, $session, $request);
$request = \Symfony\Component\HttpFoundation\Request::create('/', 'GET', [], [$guard->getRecallerName() => 'id|recaller']);
$guard = new \Illuminate\Auth\SessionGuard('default', $provider, $session, $request);
$guard->getSession()->shouldReceive('get')->once()->with($guard->getName())->andReturn(null);
$user = m::mock('Illuminate\Contracts\Auth\Authenticatable');
$guard->getProvider()->shouldReceive('retrieveByToken')->once()->with('id', 'recaller')->andReturn($user);
Expand All @@ -361,21 +363,21 @@ protected function getGuard()
{
list($session, $provider, $request, $cookie) = $this->getMocks();

return new Illuminate\Auth\SessionGuard('default', $provider, $session, $request);
return new \Illuminate\Auth\SessionGuard('default', $provider, $session, $request);
}

protected function getMocks()
{
return [
m::mock('Illuminate\Contracts\Session\Session'),
m::mock('Illuminate\Contracts\Auth\UserProvider'),
Symfony\Component\HttpFoundation\Request::create('/', 'GET'),
\Symfony\Component\HttpFoundation\Request::create('/', 'GET'),
m::mock('Illuminate\Cookie\CookieJar'),
];
}

protected function getCookieJar()
{
return new Illuminate\Cookie\CookieJar(Request::create('/foo', 'GET'), m::mock('Illuminate\Contracts\Encryption\Encrypter'), ['domain' => 'foo.com', 'path' => '/', 'secure' => false, 'httpOnly' => false]);
return new \Illuminate\Cookie\CookieJar(Request::create('/foo', 'GET'), m::mock('Illuminate\Contracts\Encryption\Encrypter'), ['domain' => 'foo.com', 'path' => '/', 'secure' => false, 'httpOnly' => false]);
}
}
4 changes: 3 additions & 1 deletion tests/Auth/AuthPasswordBrokerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Illuminate\Tests\Auth;

use Mockery as m;
use PHPUnit\Framework\TestCase;
use Illuminate\Contracts\Auth\PasswordBroker;
Expand Down Expand Up @@ -134,7 +136,7 @@ public function testResetRemovesRecordOnReminderTableAndCallsCallback()

protected function getBroker($mocks)
{
return new Illuminate\Auth\Passwords\PasswordBroker($mocks['tokens'], $mocks['users'], $mocks['mailer'], $mocks['view']);
return new \Illuminate\Auth\Passwords\PasswordBroker($mocks['tokens'], $mocks['users'], $mocks['mailer'], $mocks['view']);
}

protected function getMocks()
Expand Down
3 changes: 3 additions & 0 deletions tests/Auth/AuthTokenGuardTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

namespace Illuminate\Tests\Auth;

use Illuminate\Http\Request;
use Illuminate\Auth\TokenGuard;
use Mockery;
use PHPUnit\Framework\TestCase;
use Illuminate\Contracts\Auth\UserProvider;

Expand Down
9 changes: 6 additions & 3 deletions tests/Auth/AuthenticateMiddlewareTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

namespace Illuminate\Tests\Auth;

use stdClass;
use Mockery as m;
use Illuminate\Http\Request;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -31,7 +34,7 @@ public function setUp()
}

/**
* @expectedException Illuminate\Auth\AuthenticationException
* @expectedException \Illuminate\Auth\AuthenticationException
*/
public function testDefaultUnauthenticatedThrows()
{
Expand Down Expand Up @@ -76,7 +79,7 @@ public function testSecondaryAuthenticatedUpdatesDefaultDriver()
}

/**
* @expectedException Illuminate\Auth\AuthenticationException
* @expectedException \Illuminate\Auth\AuthenticationException
*/
public function testMultipleDriversUnauthenticatedThrows()
{
Expand Down Expand Up @@ -172,7 +175,7 @@ protected function createAuthDriver($authenticated)
* @param string ...$guards
* @return void
*
* @throws \Illuminate\Auth\AuthenticationException
* @throws AuthenticationException
*/
protected function authenticate(...$guards)
{
Expand Down
9 changes: 6 additions & 3 deletions tests/Auth/AuthorizeMiddlewareTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Illuminate\Tests\Auth;

use Mockery as m;
use Illuminate\Http\Request;
use Illuminate\Routing\Router;
Expand All @@ -12,6 +14,7 @@
use Illuminate\Contracts\Auth\Factory as Auth;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Contracts\Auth\Access\Gate as GateContract;
use stdClass;

class AuthorizeMiddlewareTest extends TestCase
{
Expand Down Expand Up @@ -52,7 +55,7 @@ public function setUp()
}

/**
* @expectedException Illuminate\Auth\Access\AuthorizationException
* @expectedException \Illuminate\Auth\Access\AuthorizationException
*/
public function testSimpleAbilityUnauthorized()
{
Expand Down Expand Up @@ -91,7 +94,7 @@ public function testSimpleAbilityAuthorized()
}

/**
* @expectedException Illuminate\Auth\Access\AuthorizationException
* @expectedException \Illuminate\Auth\Access\AuthorizationException
*/
public function testModelTypeUnauthorized()
{
Expand Down Expand Up @@ -132,7 +135,7 @@ public function testModelTypeAuthorized()
}

/**
* @expectedException Illuminate\Auth\Access\AuthorizationException
* @expectedException \Illuminate\Auth\Access\AuthorizationException
*/
public function testModelUnauthorized()
{
Expand Down
9 changes: 6 additions & 3 deletions tests/Auth/AuthorizesResourcesTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

namespace Illuminate\Tests\Auth;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Routing\Router;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -60,10 +63,10 @@ public function testDestroyMethod()
*/
protected function assertHasMiddleware($controller, $method, $middleware)
{
$router = new Router(new Illuminate\Events\Dispatcher);
$router = new Router(new \Illuminate\Events\Dispatcher);

$router->aliasMiddleware('can', 'AuthorizesResourcesMiddleware');
$router->get($method)->uses('AuthorizesResourcesController@'.$method);
$router->aliasMiddleware('can', '\Illuminate\Tests\Auth\AuthorizesResourcesMiddleware');
$router->get($method)->uses('\Illuminate\Tests\Auth\AuthorizesResourcesController@'.$method);

$this->assertEquals(
'caught '.$middleware,
Expand Down
Loading

0 comments on commit 75a6ef8

Please sign in to comment.